This commit is contained in:
yasha 2025-04-18 06:23:41 +00:00
parent 424cac9adc
commit e00e4d13ee
163 changed files with 5650 additions and 4143 deletions

View File

@ -1,143 +1,311 @@
# GRU + Simplified SAC Trading Agent # GRU + SAC Crypto Trading System (v3)
This project implements a cryptocurrency trading system using a GRU model for price prediction and a **Simplified SAC (Soft Actor-Critic)** agent for position sizing. This project implements a cryptocurrency trading system using a GRU model for market prediction and a Soft Actor-Critic (SAC) agent for position sizing, focusing on the v3 architecture and features.
The system predicts future *price* using a GRU model adapted from the V6 architecture. It calculates the *predicted percentage return* from this price prediction and estimates prediction *uncertainty* based on the standard deviation of Monte Carlo dropout predictions. It also extracts recent *momentum* and *volatility* features. These values, along with a risk proxy (`z_proxy`), form the **5-dimensional state** input (`[predicted_return, mc_unscaled_std_dev, z_proxy, momentum_5, volatility_20]`) to the SAC reinforcement learning agent, which determines optimal position sizing (-1 to +1) using a **squashed Gaussian policy** and **automatic entropy tuning**. The core idea is to decouple prediction and action:
1. A **GRU model** (primarily v3 architecture) forecasts future log-returns (μ̂) and ternary class probabilities (p_down, p_flat, p_up).
2. The **probability forecast** is calibrated using Vector Scaling (or Temperature Scaling for binary cases).
3. A **SAC agent** observes the GRU outputs (derived features like 'edge'), its own current position, and potentially other state variables (normalized using `MeanStdFilter`) to determine the optimal **position size** (-1 to +1).
The system incorporates efficiency improvements by pre-computing GRU predictions and uncertainties before generating SAC experiences or running the backtest. It includes detailed backtesting, performance reporting, and visualization capabilities, including **SAC training loss plots**. This approach aims for a robust system where the RL agent focuses solely on risk management (sizing) based on the predictor's signals.
## System Design ## V3 Features
The system integrates a GRU predictor and a Simplified SAC agent within a backtesting framework. This version incorporates significant revisions, including:
### 1. Data Flow & Processing * **Data/Labeling:** Soft binary labels, optional ternary (up/flat/down) labels.
* **Features:** Potential use of volatility-normalized returns, cyclical time features, and technical indicators.
* **GRU v3 Model:** GRU -> Attention -> LayerNorm architecture predicting continuous log-return (`mu`) and ternary direction classification logits (`dir3`).
* **Calibration:** Vector Scaling for ternary outputs; Temperature Scaling as an option for binary classification.
* **SAC Stabilization:** Reward scaling, state normalization (`MeanStdFilter`), adjusted target entropy calculation, action magnitude penalty, optional oracle buffer seeding.
* **Metrics & Validation:** Edge-filtered accuracy metric, baseline model checks, backtest performance validation gates (Sharpe, Max Drawdown), re-centered Sharpe ratio.
* **Configuration:** Centralized `config.yaml` controls pipeline stages, model versions, hyperparameters.
* **Output Contract:** Standardized output structure via `IOManager` and `LoggerSetup` for reproducibility.
* **Testing:** Unit tests and an output contract smoke test (`tests/test_output_contract.py`).
* **Documentation:** This README and `docs/v3_changelog.md`.
1. **Loading:** Raw 1-minute OHLCV data is loaded from the SQLite database directory specified in `main.py` (e.g., `downloaded_data/`) using `src.data_pipeline.load_data_from_db` which utilizes `src.crypto_db_fetcher.CryptoDBFetcher`. ## System Design (v3)
2. **Splitting:** Data is chronologically split into training (60%), validation (20%), and test (20%) sets using `src.data_pipeline.create_data_pipeline`.
3. **GRU Training / Loading (on Train/Validation Sets):**
* If `TRAIN_GRU_MODEL` is `True`:
* *Preprocessing*: `TradingSystem._preprocess_data_for_gru_training` calculates V6 features plus basic return features (`calculate_v6_features`) on the raw train/val data. It determines the future *price* target (`prediction_horizon` steps ahead) and aligns features, targets (prices), and the *unscaled* starting close prices needed for return calculation.
* *Scaling*: Within `TradingSystem.train_gru`, a `StandardScaler` is fitted *only* on the training features. A `MinMaxScaler` is fitted *only* on the training future *price* targets. Train and validation features/targets are scaled using these fitted scalers.
* *Sequence Creation*: `src.data_pipeline.create_sequences_v2` creates input sequences `(batch, sequence_length, num_features)` and corresponding scaled target prices using the scaled features/targets and the unscaled start prices.
* *Model Training*: `CryptoGRUModel.train` builds the V6-style GRU model (if not already built) and trains it using Mean Squared Error (MSE) loss on the scaled sequences. Callbacks monitor `val_rmse` for early stopping and model checkpointing. The best model (`best_model_reg.keras`) and the fitted scalers (`feature_scaler.joblib`, `y_scaler.joblib`) are saved.
* If `LOAD_EXISTING_SYSTEM` is `True` and `TRAIN_GRU_MODEL` is `False`:
* Attempts to load a pre-trained GRU model and scalers. If `GRU_MODEL_LOAD_RUN_ID` is set in `main.py`, it loads the GRU from that specific run ID's directory (`gru_sac_predictor/models/run_<run_id>`); otherwise, it attempts to load from the default `MODEL_SAVE_PATH` (expecting the model and scalers to be directly in that path).
* **Note:** SAC model loading is handled *separately* based on the `LOAD_SAC_AGENT` flag and the `GRU_MODEL_LOAD_RUN_ID` setting (see Model Loading/Training section in `main.py` for details).
4. **SAC Training (on Validation Set):**
* **Training Loop:** The training process runs for a fixed number of epochs (`SAC_EPOCHS`).
* **Experience Generation** (`TradingSystem.generate_trading_experiences`):
* **Efficiency:** Pre-computes all required GRU outputs (predicted returns, uncertainties) for the entire validation set by calling `CryptoGRUModel.evaluate` *once*.
* **State Extraction:** Extracts pre-computed GRU outputs and relevant features (`momentum_5`, `volatility_20`) from the validation features dataframe.
* **Experience Format:** Iterates through the pre-computed results. Forms the 5D state `s_t = [pred_return_t, uncertainty_t, z_proxy_t, momentum_5_t, volatility_20_t]` (where `z_proxy` uses the position *before* the action). The SAC agent (`SimplifiedSACTradingAgent.get_action`) provides a *non-deterministic* action `a_t` and `log_prob`. The next state `s_{t+1}` is constructed similarly (using `action` for `z_proxy`). A reward `r_t = action * actual_return - cost` is calculated. The transition `(s_t, a_t, r_t, s_{t+1}, done)` is stored.
* **Note:** Experience sampling strategies (recency bias, stratification) defined in `experience_config` are currently *not* implemented in `generate_trading_experiences` but the configuration remains.
* **Agent Training** (`TradingSystem.train_sac` calls `SimplifiedSACTradingAgent.train`): Iterates for `SAC_EPOCHS`. In each epoch, the agent performs one training step. Batches are sampled from the replay buffer. Actor and Critic networks are updated using the SAC algorithm with automatic alpha tuning. Agent uses `store_transition` to add experiences to its internal NumPy buffer.
* **History Plotting:** After successful training, `plot_sac_training_history` is called to generate and save a plot of actor and critic losses.
5. **Backtesting (on Test Set):**
* *Pre-computation* (`ExtendedBacktester.backtest`): Preprocesses test data, scales, creates sequences, calls `CryptoGRUModel.evaluate` once for GRU outputs, and extracts required features (`momentum_5`, `volatility_20`).
* *State Generation*: Constructs the 5D state `s_t = [pred_return, uncertainty, z_proxy, momentum_5, volatility_20]` using pre-computed results and the current position.
* *Action Selection*: The trained `SimplifiedSACTradingAgent` selects a *deterministic* action `a_t` (unpacking the tuple returned by `get_action`).
* *Portfolio Simulation*: Calculates PnL based on the previous position, actual return, and transaction costs.
* *Logging*: Records detailed metrics, trade history, and timestamps.
6. **Evaluation:**
* *Performance Metrics*: `ExtendedBacktester._calculate_performance_metrics` computes overall portfolio metrics (Sharpe, Sortino, Drawdown, correlations, etc.) and Buy & Hold benchmark metrics.
* *Visualization*: `ExtendedBacktester.plot_results` generates a 3-panel plot: GRU Predictions vs Actual Price (with uncertainty), SAC Actions (Position Size), and Portfolio Value vs Buy & Hold (with trade markers).
* *Reporting*: `ExtendedBacktester.generate_performance_report` creates a detailed Markdown report.
### 2. Core Components & Inputs/Outputs The system is orchestrated by `run.py`, which sets up logging and I/O via `LoggerSetup` and `IOManager`, then instantiates and executes the `TradingPipeline` class (`src/trading_pipeline.py`). The pipeline follows a sequence of steps to process data, train models, and evaluate performance.
* **`src.crypto_db_fetcher.CryptoDBFetcher`**: Loads and resamples data from SQLite DBs. ```mermaid
* **`src.data_pipeline`**: Functions for DB loading, data splitting, sequence creation. %%{init: {'themeVariables': { 'fontSize': '26px' }}}%%
* **`src.trading_system.calculate_v6_features`**: Calculates features (TA-Lib based V6 set + past returns). flowchart TD
* **`src.trading_system._preprocess_data_for_gru_training`**: Prepares features, future price targets, and start prices. subgraph Initialization
* **`src.gru_predictor.CryptoGRUModel`**: (V6 Adaptation) A["run.py: Init Logger/IOManager"] --> B[TradingPipeline];
* `train()`: Trains the GRU price prediction model. Saves model (`.keras`) and scalers (`.joblib`). end
* `evaluate()`: Performs standard prediction and MC dropout inference. Returns dict including `pred_percent_change`, `mc_unscaled_std_dev`, `predicted_unscaled_prices`, `true_unscaled_prices`. subgraph DataPreparation ["Data Preparation"]
* **`src.sac_agent_simplified.SimplifiedSACTradingAgent`**: (V7 Simplified) B --> C["Load Data (DataLoader)"];
* **Goal:** Learns a policy mapping state to optimal position size (-1.0 to +1.0). Optimized for faster training. C --> D["Engineer Features (FeatureEngineer)"];
* **State Input:** 5-element array `[predicted_return, mc_unscaled_std_dev, z_proxy, momentum_5, volatility_20]`. D --> E["Define Labels (Binary/Ternary)"];
* **Action Output:** Float between -1.0 and +1.0. E --> F["Split Data (Train/Val/Test)"];
* `get_action()`: Selects action (stochastic or deterministic). Adds uncertainty-scaled noise during exploration. F --> G["Scale Features (StandardScaler)"];
* `store_transition()`: Adds experience to internal NumPy buffer. G --> I["Baseline Check (BaselineChecker)"];
* `train()`: Updates agent using buffer samples (internally handles batch size). Uses `@tf.function` for performance. I -- Pass --> H["Select/Prune Features"];
* `save()` / `load()`: Handles Actor/Critic weights (`.weights.h5`), potentially `alpha.npy`. H --> J[Create Sequences];
* **Note:** Models and optimizers are built explicitly during `__init__` using dummy inputs to prevent TensorFlow graph mode issues. end
* **`src.trading_system.TradingSystem`**: Integrates GRU and SAC. Manages training pipelines, feature calculation, experience generation. subgraph PredictionModel ["Prediction Model (GRU)"]
* **`src.trading_system.ExtendedBacktester`**: Performs efficient backtesting using pre-computed GRU outputs, calculates metrics, plots results, generates reports. J --> K["Train/Load GRU Model (GRUModelHandler)"];
* **`src.trading_system.plot_sac_training_history`**: Generates plot for SAC actor/critic losses during training. K --> L["Calibrate Probabilities (Calibrator/VectorCalibrator)"];
L --> M["Validation Gate: Edge Acc Check"];
end
subgraph ActionModel ["Action Model (SAC)"]
M -- Pass --> N["Train/Load SAC Agent (SACTrainer)"];
end
subgraph Evaluation
N --> O["Run Backtest (Backtester)"];
O --> P["Save Results (Backtester/IOManager)"];
P --> Q["Validation Gate: Backtest Perf Check"];
end
```
### 3. Model Architectures *Diagram outlines the v3 pipeline flow including setup, core stages, and validation gates.*
* **GRU (`src.gru_predictor.CryptoGRUModel._build_model`)**: V6 Architecture. ### Detailed Steps (Reflecting Current Implementation)
* Input -> GRU(100) -> Dropout(0.2) -> Dense(1, linear).
* Compiled with Adam (LR=0.001), MSE loss.
* **Simplified SAC (`src.sac_agent_simplified.SimplifiedSACTradingAgent`)**:
* **Actor Network**: MLP `(state_dim=5)` -> Dense(64, relu) -> [BN] -> Dense(64, relu) -> [BN] -> [Residual] -> Dense(1, name='mu'), Dense(1, name='log_std'). Output is `mu` and `log_std` for a **Gaussian policy**. `log_std` is clipped.
* **Critic Network (x2)**: MLP `(state_dim=5 + action_dim=1)` -> Dense(64, relu) -> [BN] -> Dense(64, relu) -> [BN] -> [Residual] -> Dense(1, linear).
* **Algorithm**: Implements SAC with Clipped Double-Q, **automatic entropy tuning** (optimizing `alpha` based on `target_entropy`), squashed actions (`tanh`), faster learning rates, smaller networks/buffer, optional Batch Normalization / Residual connections. Uses Huber loss for critics. `@tf.function` used for update steps (`_update_critics`, `_update_actor_and_alpha`).
### 4. Features & State Representation * **A (`run.py`):** Parses command-line arguments (`--config`, `--log-level`), generates a unique `run_id`, loads the specified `config.yaml`, initializes `IOManager` and `LoggerSetup` for managing outputs and logs, logs a system banner, and instantiates `TradingPipeline`, passing the configured `io_manager`.
* **C (`TradingPipeline.load_and_preprocess_data`):** Uses `DataLoader` to load the specified Parquet data files. Performs initial cleaning (e.g., handling NaNs, setting index). Saves `preprocess_summary.txt` and a preview (`head_preprocessed.*`) via `IOManager`.
* **D (`TradingPipeline.engineer_features`):** Employs `FeatureEngineer` to compute additional features (e.g., technical indicators, volatility-normalized returns, cyclical features) based on the raw price data.
* **E (`TradingPipeline.define_labels_and_align`):** Calculates target variables (future log-returns). Defines classification labels (soft binary or ternary based on `gru.use_ternary` and `gru.flat_sigma_multiplier`). Aligns features and labels. Saves `feature_corr_heatmap.png`.
* **F (`TradingPipeline.split_data`):** Splits the data chronologically into training, validation, and test sets based on configured percentages or dates. Saves `label_histogram.png`.
* **G (`TradingPipeline.scale_features`):** Fits a `StandardScaler` on the training set features. Saves the scaler object (`feature_scaler_{run_id}.joblib`). Transforms features in all splits (train, val, test).
* **I (`TradingPipeline.run_baseline_checks`):** Uses `BaselineChecker` to train a simple baseline model (e.g., Logistic Regression) on the *scaled, non-sequential* training data and evaluate it on the validation set. Saves `baseline1_report.txt`. **Exits if the baseline confidence interval lower bound (CI LB) on accuracy is below a threshold (e.g., 0.52)**.
* **H (`TradingPipeline.select_and_prune_features`):** Selects the final set of features based on a predefined list or criteria. Saves the final list (`final_whitelist.json`). Removes non-selected features from the *scaled, non-sequential* data splits.
* **J (`TradingPipeline.create_sequences`):** Transforms the *pruned, scaled* time-series data splits into overlapping sequences suitable for input to the GRU model, using specified sequence length.
* **K (`TradingPipeline.train_or_load_gru`):** Depending on `control.train_gru`, either trains a new GRU model (`model_gru_v3.py` if `control.use_v3` is true) using the *sequenced* training/validation data via `GRUModelHandler`, or loads a pre-trained model. Saves the trained model (`gru_model_v3_{run_id}.keras`), training history (`gru_history.csv`), and plots learning curves (`gru_learning_curve.png`).
* **L (`TradingPipeline.calibrate_probabilities`):** Takes the raw classification outputs (logits) from the GRU model on the validation set and calibrates them to better reflect true probabilities. Uses either `Calibrator` (Temperature Scaling) or `VectorCalibrator` (Vector Scaling) based on `calibration.method`. Saves calibration parameters (`calibration_{temp/vector}_{run_id}.npy`) and plots reliability curves (`reliability_curve_*.png`).
* **M (`TradingPipeline._perform_edge_filtered_accuracy_check`):** Calculates the accuracy of the calibrated GRU predictions on the validation set, but only considering predictions where the predicted probability (or 'edge') exceeds `calibration.edge_threshold`. **Exits if edge-filtered accuracy is below a threshold (e.g., 0.60)**.
* **N (`TradingPipeline.train_or_load_sac`):** Depending on `control.train_sac`, either trains a new SAC agent using `SACTrainer` or loads a pre-trained agent. The `SACTrainer` interacts with the `TradingEnv`, which uses the trained GRU model to provide market predictions as part of the agent's state. Handles state normalization (`MeanStdFilter` if `sac.use_state_filter`), optional heuristic seeding (`sac.oracle_seeding_pct`). Logs training progress (`episode_rewards.csv`, TensorBoard) and saves the trained agent components and state filter (`sac_agent.../`, `state_filter.npz`). Plots rewards (`sac_reward_plot.png`).
* **O (`TradingPipeline.run_backtest`):** Uses the trained/loaded GRU predictor and SAC agent within the `Backtester`. Simulates trading on the test set, applying the SAC agent's position sizing decisions based on the GRU's predictions. Calculates performance metrics (Sharpe, Sortino, Max Drawdown, etc.).
* **P (`TradingPipeline.save_results` & `Backtester`):** The `Backtester` saves detailed backtest outputs (`backtest_results.*`, `performance_metrics.txt`, `backtest_metrics_log.csv`, plots like `backtest_summary.png`, `confusion_matrix.png`).
* **Q (`TradingPipeline.save_results` - Validation):** Performs final validation checks on the backtest results. **Exits if Sharpe ratio < 1.2 or Maximum Drawdown > 15% (configurable thresholds)**. Saves the final `run_config.yaml`.
* **GRU Features:** Uses the V6 feature set plus basic past returns (see `calculate_v6_features`). Cyclical time features (`hour_sin`, `hour_cos`) are added *before* data splitting. ## Core Components Architecture
* **SAC State (`state_dim=5`):**
1. `predicted_return`: GRU predicted percentage return for the next period.
2. `uncertainty`: GRU MC dropout standard deviation (unscaled).
3. `z_proxy`: Risk proxy, calculated as `current_position * volatility_20`.
4. `momentum_5`: 5-minute return (`return_5m` feature).
5. `volatility_20`: 20-day volatility (`volatility_14d` feature, name mismatch intended).
* **Scaling:** Features for GRU scaled with `StandardScaler`. Target price for GRU scaled with `MinMaxScaler`. SAC state components are used directly without separate scaling.
### 5. Evaluation This section details the architecture and purpose of key modules within the system.
* **GRU Model:** Evaluated using RMSE loss on validation set. Callbacks monitor `val_rmse`. Plots compare predicted vs actual price. ### 1. Data Handling (`DataLoader`, `FeatureEngineer`)
* **SAC Agent & Overall System:** Evaluated via the `ExtendedBacktester` metrics (Sharpe, Sortino, Max Drawdown, correlations, etc.), plots (Portfolio vs B&H, Actions), and a final Markdown report. SAC training progress monitored via saved loss plots (`sac_training_history_<run_id>.png`).
* **`DataLoader` (`src/data_loader.py`):** Responsible for loading raw market data (OHLCV - Open, High, Low, Close, Volume) from specified Parquet files (`<ticker>_<interval>.parquet`). Handles basic preprocessing like setting a DatetimeIndex and potentially initial NaN handling.
* **`FeatureEngineer` (`src/feature_engineer.py`, `src/features.py`):** Takes the preprocessed OHLCV data and generates a richer feature set for the predictive model. This can include:
* **Technical Indicators:** Moving averages, RSI, MACD, Bollinger Bands, etc.
* **Volatility Features:** ATR (Average True Range), realized volatility.
* **Return-based Features:** Log returns over different periods, potentially volatility-normalized returns.
* **Time/Cyclical Features:** Day of week, hour of day, encoded cyclically using sine/cosine transforms.
* **Target Definition:** Calculates future log returns (the regression target `mu_target`) and derives classification labels (binary or ternary) based on thresholds (potentially dynamic using `flat_sigma_multiplier`).
### 2. GRU Predictor (`model_gru_v3.py`, `GRUModelHandler`)
* **`model_gru_v3.py`:** Defines the core GRU v3 network architecture using TensorFlow/Keras.
* **Input:** Sequences of scaled features `(batch_size, sequence_length, num_features)`.
* **Architecture:**
1. **GRU Layers:** One or more GRU layers to capture temporal dependencies in the input sequences.
2. **Attention Mechanism:** An attention layer (optional, configurable) applied to the GRU outputs to allow the model to focus on more relevant time steps within the sequence.
3. **Layer Normalization:** Applied after attention (or GRU if no attention) for stabilization.
4. **Output Heads:** Two separate dense output layers:
* `mu`: Predicts the continuous future log-return (single output neuron, linear activation).
* `dir3`: Predicts the logits for the ternary classification (down, flat, up) (3 output neurons, linear activation). If `gru.use_ternary` is false, this might adapt to binary classification or be ignored downstream.
* **Loss Function:** A combined loss is typically used during training:
* Mean Squared Error (MSE) for the `mu` regression output.
* Categorical Cross-Entropy (potentially with Focal Loss modification via `gru_v3.focal_gamma`) for the `dir3` classification output.
* **`GRUModelHandler` (`src/gru_model_handler.py`):** Manages the training lifecycle of the GRU model. Handles model compilation (optimizer, loss functions, metrics), data preparation (using `tf.data.Dataset` for efficiency), training loops (including early stopping), model saving/loading, and prediction generation.
### 3. Probability Calibration (`Calibrator`, `VectorCalibrator`)
* **Need:** Neural network outputs (logits/softmax) often don't directly represent true probabilities (i.e., they can be over/under-confident). Calibration adjusts these outputs post-training to be more reliable.
* **`Calibrator` (`src/calibrator.py`):** Implements Temperature Scaling. Learns a single scalar parameter (temperature `T`) on the validation set logits. Calibrated probabilities are obtained by dividing logits by `T` before applying softmax. Primarily suitable for binary or multi-class problems where miscalibration is consistent across classes.
* **`VectorCalibrator` (`src/calibrator_vector.py`):** Implements Vector Scaling. Learns a vector (matrix `W` and bias `b`) on the validation set logits. Calibrated logits are obtained via `logit' = W * logit + b`. More flexible than Temperature Scaling and generally preferred for multi-class (like ternary) classification.
### 4. SAC Agent (`sac_agent.py`, `SACTrainer`, `TradingEnv`)
* **Goal:** To learn an optimal position sizing strategy based on the GRU predictor's signals and the agent's current state.
* **`sac_agent.py`:** Defines the Soft Actor-Critic (SAC) agent components:
* **Actor Network:** Maps state to a probability distribution over actions (position size -1 to +1). Typically outputs parameters (mean, std dev) of a squashed Gaussian distribution.
* **Critic Networks (Q-Functions):** Estimate the expected future return (Q-value) for a given state-action pair. SAC uses two critics (and target critics) to mitigate overestimation bias.
* **Alpha (Entropy Temperature):** Controls the trade-off between maximizing expected return and maximizing policy entropy (encouraging exploration). Can be a fixed value or learned automatically (common).
* **`TradingEnv` (`src/trading_env.py`):** An OpenAI Gym-style environment simulating the trading process:
* **State:** The observation provided to the agent at each time step. Typically includes:
* Calibrated probabilities or derived 'edge' from the GRU model.
* The agent's current position (-1 to +1).
* Potentially other relevant features (e.g., recent volatility).
* **Action:** The position size chosen by the SAC agent (-1 to +1).
* **Reward:** Calculated based on the portfolio's change in value from one step to the next, considering the chosen position and market movement. May include:
* `environment.reward_scale` multiplier.
* Penalty for large actions (`environment.action_penalty_lambda`).
* Transaction costs (slippage, commissions - handled in `Backtester` usually, but could be in Env).
* **Normalization:** Uses `MeanStdFilter` (from `src/utils/running_stats.py`) if `sac.use_state_filter` is true to normalize the state variables, which is crucial for stable RL training.
* **`SACTrainer` (`src/sac_trainer.py`):** Orchestrates the SAC training loop:
* Manages the interaction between the agent and the environment.
* Stores experiences (state, action, reward, next_state) in a Replay Buffer.
* Samples batches from the buffer to update the Actor, Critic, and Alpha parameters.
* Handles state normalization filter updates.
* Implements "Oracle Seeding" (`sac.oracle_seeding_pct`): Pre-fills a portion of the replay buffer with transitions generated by a simple heuristic policy (e.g., size position based directly on predicted edge) to potentially speed up initial learning.
* Saves/loads agent models and the state filter.
### 5. Evaluation (`Backtester`, `BaselineChecker`)
* **`Backtester` (`src/backtester.py`):** Evaluates the combined GRU+SAC system on unseen test data.
* Takes the trained GRU model, calibrated outputs, and the trained SAC agent.
* Iterates through the test set step-by-step.
* At each step:
1. Gets the GRU prediction.
2. Constructs the state for the SAC agent.
3. Gets the position size action from the SAC agent.
4. Calculates the resulting portfolio performance, incorporating realistic factors like:
* Transaction Costs (configurable slippage and commission rates).
* Position constraints.
* Calculates and reports various performance metrics (`src/metrics.py`): Sharpe Ratio, Sortino Ratio, Max Drawdown, Calmar Ratio, Win Rate, Profit Factor, etc.
* Generates plots: Equity curve, drawdown periods, position changes, confusion matrix (based on predicted vs. actual moves when a position was taken).
* **`BaselineChecker` (`src/baseline_checker.py`):** Provides an initial sanity check before extensive GRU/SAC training.
* Trains a simple, fast model (e.g., Logistic Regression) on the prepared features and labels.
* Evaluates its performance (e.g., Accuracy, AUC) on the validation set.
* Calculates a confidence interval for the primary metric.
* The pipeline uses this to gate further execution, ensuring the features/labels have at least some minimal predictive power before committing to computationally expensive training.
### 6. Orchestration & Utilities (`TradingPipeline`, `IOManager`, `LoggerSetup`)
* **`TradingPipeline` (`src/trading_pipeline.py`):** The main class that coordinates the entire workflow, calling the different components in sequence as outlined in the "Detailed Steps" section. Reads configuration, manages data flow between steps, and implements validation gates.
* **`IOManager` (`src/io_manager.py`):** Handles all file input/output operations. Creates standardized directory structures based on `run_id`, saves/loads models, dataframes (CSV/Parquet), scaler objects, configuration files, plots, and text reports. Ensures outputs are organized and reproducible.
* **`LoggerSetup` (`src/logger_setup.py`):** Configures Python's standard `logging` module. Sets up logging to both console and file (`pipeline_<run_id>.log`), controls log levels based on configuration/command-line arguments, and standardizes log message formats.
## Configuration Parameters (v3 Highlights)
Refer to `config.yaml` for defaults. Key v3 parameters:
```yaml
base_dirs: {results: ..., models: ..., logs: ...} # Base output directories
output: {figure_dpi: ..., figure_size: ..., log_level: ...} # Output formatting
data:
label_smoothing: 0.0 # For soft binary labels
gru:
use_ternary: false # Use ternary labels?
flat_sigma_multiplier: 0.25 # k for dynamic flat threshold
gru_v3: # Section for GRU v3 specific hyperparameters
# (gru_units, attention_units, learning_rate, focal_gamma, etc.)
calibration:
method: 'temperature' # 'temperature' or 'vector'
edge_threshold: 0.1 # Threshold for edge_filtered_accuracy & backtest plot
sac:
target_entropy: null # null/default for auto-calculation
use_state_filter: true # Enable state normalization (MeanStdFilter)
oracle_seeding_pct: 0.2 # Percentage of buffer for heuristic seeding
environment:
reward_scale: 100.0 # Multiplier for environment reward
action_penalty_lambda: 0.0 # Penalty coefficient for action magnitude
control:
use_v3: true # Selects GRU v3 model and logic
train_gru: true # Train GRU?
train_sac: true # Train SAC?
run_backtest: true # Run backtest?
generate_plots: true # Generate and save plots?
# ... (load/resume flags)
```
## Usage
1. **Setup:**
* Clone the repository.
* Create and activate a Python virtual environment (e.g., using `conda` or `venv`).
* Install dependencies: `pip install -r requirements.txt`
* Ensure input data exists in the directory specified by `data.db_dir` in `config.yaml` (expected format: Parquet files named `<ticker>_<interval>.parquet`, e.g., `BTC-USD_1h.parquet`).
2. **Configuration (`config.yaml`):**
* Adjust parameters in `config.yaml` as needed.
* Ensure `base_dirs` point to desired locations.
* Configure the `control` section to define the desired workflow (train/load models, run backtest, etc.).
3. **Running the Main Pipeline (`run.py`):**
* Execute from the project root (`develop/gru_sac_predictor/`).
* The `run.py` script handles initialization and passes control to the `TradingPipeline`.
```bash
# Run using default config.yaml location
python gru_sac_predictor/run.py
# Specify a different config and override log level
python gru_sac_predictor/run.py --config path/to/your_config.yaml --log-level DEBUG
```
4. **Running Tests (`pytest`):**
* Run tests from the project root.
* `pytest tests/` runs all tests.
* `pytest tests/test_output_contract.py` runs the smoke test (requires sample data).
5. **Validation Script (`scripts/run_validation.sh`):**
* Runs multiple pipeline configurations and aggregates results using `scripts/aggregate_metrics.py`.
```bash
# Run from project root
bash gru_sac_predictor/scripts/run_validation.sh
```
## Output Contract & Reproducibility (v3)
Artifacts are saved under `results/`, `logs/`, and `models/` subdirectories named `run_<run_id>/` or `sac_train_<sac_run_id>/`, managed by `IOManager`.
| Stage | Key Artifacts |
|--------------------------|--------------------------------------------------------------------------------------------------------------------|
| **Run Setup** | `results/.../run_config.yaml`, `logs/.../pipeline_<run_id>.log` |
| **Data Load/Preprocess** | `results/.../preprocess_summary.txt`, `results/.../head_preprocessed.{csv/parquet}` |
| **Feature Engineering** | `results/.../feature_corr_heatmap.png` |
| **Label Generation** | `results/.../label_histogram.png` |
| **Baseline Check** | `results/.../baseline1_report.txt` |
| **Feature Whitelist** | `models/.../final_whitelist.json` |
| **GRU Training** | `models/.../gru_model_{v2/v3}_{run_id}.keras`, `models/.../feature_scaler_{run_id}.joblib`, `logs/.../gru_history.csv`, `results/.../gru_learning_curve.png` |
| **Calibration** | `models/.../calibration_{temp/vector}_{run_id}.npy`, `results/.../reliability_curve_{val/vector}.png` |
| **SAC Training** | `models/sac_train_.../sac_agent.../`, `models/sac_train_.../state_filter.npz`, `logs/sac_train_.../episode_rewards.csv`, `logs/sac_train_.../tensorboard/`, `results/.../sac_reward_plot.png` |
| **Back-test** | `results/.../backtest_results.{csv/parquet}`, `results/.../performance_metrics.txt`, `results/.../backtest_metrics_log.csv`, `results/.../backtest_summary.png`, `results/.../confusion_matrix.png` |
*File extensions for dataframes (`.csv` or `.parquet`) depend on size.*
## File Structure ## File Structure
- `downloaded_data/`: **Place your SQLite database files here.** (Or update `DB_DIR` in `main.py`). ```
- `gru_sac_predictor/`: Project root directory. gru_sac_predictor/ # Package Root
- `models/`: Trained models saved here under `run_<run_id>/` directories. ├── config.yaml
- `results/`: Backtest results saved here under `<run_id>/` directories. ├── requirements.txt
- `logs/`: Log files saved here under `<run_id>/` directories. ├── README.md # This file
- `src/`: Core Python modules. ├── run.py # Main pipeline entry point
- `crypto_db_fetcher.py` ├── train_sac_runner.py # Standalone SAC trainer (legacy?)
- `data_pipeline.py` ├── src/ # Source code
- `gru_predictor.py` │ ├── __init__.py
- `sac_agent_simplified.py` │ ├── trading_pipeline.py # Main pipeline orchestration
- `trading_system.py` │ ├── data_loader.py
- `main.py`: Main script. │ ├── feature_engineer.py
- `requirements.txt` │ ├── features.py
- `README.md` │ ├── gru_model_handler.py
│ ├── model_gru.py # v2 GRU model definition (Legacy?)
## Setup │ ├── model_gru_v3.py # v3 GRU model definition
│ ├── calibrator.py # Temperature Scaling
1. **Data:** Place your V6 `downloaded_data` directory containing the SQLite files relative to the `gru_sac_predictor` project root, or update the `DB_DIR` variable in `main.py` to point to the correct location. │ ├── calibrator_vector.py # Vector Scaling
2. **Dependencies:** Install required packages: │ ├── sac_trainer.py
```bash │ ├── sac_agent.py
pip install -r requirements.txt │ ├── trading_env.py
``` │ ├── backtester.py
*Strongly Recommended:* Install TA-Lib for the full feature set. See TA-Lib installation guides for your OS. │ ├── baseline_checker.py
3. **Configuration:** Review and adjust parameters in `main.py`. Key parameters include: │ ├── io_manager.py
* `DB_DIR`, `TICKER`, `EXCHANGE`, `START_DATE`, `END_DATE`, `INTERVAL` │ ├── logger_setup.py
* Model hyperparameters (GRU and SAC sections) │ ├── metrics.py
* Control Flags: `LOAD_EXISTING_SYSTEM`, `TRAIN_GRU_MODEL`, `TRAIN_SAC_AGENT`, `LOAD_SAC_AGENT` │ └── utils/
* Loading Specific Models: `GRU_MODEL_LOAD_RUN_ID` (set to a specific run ID string like `'YYYYMMDD_HHMMSS'` to load *only* the GRU model from `gru_sac_predictor/models/run_<run_id>/`). SAC loading depends on `LOAD_SAC_AGENT` flag. │ ├── run_id.py
* SAC Training: `SAC_EPOCHS` defines the number of training epochs. │ └── running_stats.py
* Experience Generation: `experience_config` dictionary (sampling strategies currently not implemented). ├── tests/ # Unit and integration tests
* Backtesting: `INITIAL_CAPITAL`, `TRANSACTION_COST`. │ ├── smoke.yaml
4. **Run:** Execute from the project root directory (the one *containing* `gru_sac_predictor`): │ ├── test_output_contract.py
```bash │ └── ... # Other test files
python -m gru_sac_predictor.main ├── scripts/ # Helper and validation scripts
``` │ ├── aggregate_metrics.py
Output files (logs, models, plots, report) will be generated in `gru_sac_predictor/logs/`, `gru_sac_predictor/models/`, and `gru_sac_predictor/results/` within run-specific subdirectories. │ └── run_validation.sh
├── docs/ # Documentation
## Reporting │ └── v3_changelog.md
├── models/ # Default output directory for models
The report generated by the `ExtendedBacktester` includes performance metrics, correlation analyses, and configuration details. Key metrics include: ├── results/ # Default output directory for results
├── logs/ # Default output directory for logs
* Total/Annualized Return └── data/ # Input data directory
* Sharpe & Sortino Ratios └── processed/
* Volatility & Max Drawdown ```
* Buy & Hold Comparison
* Position/Prediction Accuracy
* Prediction/Position/Uncertainty Correlations
* Total Trades

View File

@ -0,0 +1 @@

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,19 +3,38 @@
# --- Run Identification & Output --- # --- Run Identification & Output ---
run_id_template: '{timestamp}' # Template for generating unique run IDs. '{timestamp}' will be replaced by YYYYMMDD_HHMMSS. Allows grouping results, logs, and models. run_id_template: '{timestamp}' # Template for generating unique run IDs. '{timestamp}' will be replaced by YYYYMMDD_HHMMSS. Allows grouping results, logs, and models.
# --- Base Directories (Task 0.1) --- #
base_dirs: base_dirs:
results: 'results' # Base directory relative to package root results: 'results' # Base directory relative to package root
logs: 'logs' # Base directory relative to package root logs: 'logs' # Base directory relative to package root
models: 'models' # Base directory relative to package root models: 'models' # Base directory relative to package root
# --- End Base Directories --- #
# --- Output Settings (Task 0.1) --- #
output:
figure_dpi: 150 # DPI for saved matplotlib figures
figure_size: [16, 9] # Default figure size (width, height in inches)
log_level: INFO # Logging level (DEBUG, INFO, WARNING, ERROR)
# --- End Output Settings --- #
# --- Data Parameters --- # --- Data Parameters ---
data: data:
db_dir: '../../data/crypto_market_data' # Path to the directory containing the market data database (relative to where main.py is run). db_dir: '../data/crypto_market_data' # Path to the directory containing the market data database (relative to where main.py is run).
exchange: 'bnbspot' # Name of the exchange table/data source in the database. exchange: 'bnbspot' # Name of the exchange table/data source in the database.
ticker: 'SOL-USDT' # Instrument identifier (e.g., trading pair) within the exchange data. ticker: 'SOL-USDT' # Instrument identifier (e.g., trading pair) within the exchange data.
start_date: '2024-06-01' # Start date for loading data (YYYY-MM-DD). Note: Ensure enough data for lookback + splits. start_date: '2025-03-01' # Start date for loading data (YYYY-MM-DD). Note: Ensure enough data for lookback + splits.
end_date: '2025-03-10' # End date for loading data (YYYY-MM-DD). end_date: '2025-03-10' # End date for loading data (YYYY-MM-DD).
interval: '1min' # Data frequency/interval (e.g., '1min', '5min', '1h'). interval: '1min' # Data frequency/interval (e.g., '1min', '5min', '1h').
# --- New Data Loader Params (v3 Rev) ---
vol_sampling: false # Task 1.1: Enable volatility-based sampling in DataLoader
vol_window: 30 # Task 1.1: Window size for volatility calculation
vol_quantile: 0.5 # Task 1.1: Keep samples where vol > this quantile
label_smoothing: 0.0 # Task 1.2: Apply label smoothing to binary targets (0.0 = off, 0.1 = [0.05, 0.95])
# --- Feature Engineering Params ---
# (Placeholder for potential future config, like VIF skip - Task 2.5)
# features:
# skip_vif: false
# --- Data Split --- # --- Data Split ---
split_ratios: split_ratios:
@ -25,54 +44,89 @@ split_ratios:
# --- GRU Model Parameters --- # --- GRU Model Parameters ---
gru: gru:
lookback: 60 # General
epochs: 25 prediction_horizon: 5 # How many steps ahead the model predicts.
batch_size: 256 lookback: 60 # Sequence length input to the GRU.
prediction_horizon: 5 # --- New Label/Version Params (v3 Rev) ---
patience: 5 use_ternary: false # Task 1.3: Use ternary (up/flat/down) labels instead of binary.
model_load_run_id: '20250417_173635' flat_sigma_multiplier: 0.25 # Task 1.3: k for ternary flat threshold (eps = k * rolling_sigma_N).
# --- v2 Specific Params (Legacy) ---
epochs: 25 # Max training epochs (used if v2).
batch_size: 256 # Batch size (used if v2).
patience: 5 # Early stopping patience (used if v2).
model_load_run_id: null # '20250417_173635' # Run ID to load pre-trained v2 model from (if train_gru=false, use_v3=false).
# v2 Loss Weighting (Deprecated?)
recency_weighting: recency_weighting:
enabled: true enabled: false # true
linear_start: 0.2 linear_start: 0.2
linear_end: 1.0 linear_end: 1.0
signed_weighting_beta: 0.0 signed_weighting_beta: 0.0
composite_loss_kappa: 0.0 composite_loss_kappa: 0.0
# --- GRU v3 Model Specific Parameters (v3 Rev) --- #
gru_v3:
# Architecture (Task 3.1)
gru_units: 96
attention_units: 16
# Training (Task 3.4 - these replace v2 equivalents when use_v3=true)
epochs: 30
batch_size: 128
patience: 5
model_load_run_id: null # Run ID to load pre-trained v3 model from (if train_gru=false, use_v3=true).
# Compilation (Task 3.3 / 3.4)
learning_rate: 1e-4
focal_gamma: 2.0 # Gamma for Categorical Focal Crossentropy (dir3 head).
focal_label_smoothing: 0.1 # Label smoothing for Focal Loss (passed to loss func).
huber_delta: 1.0 # Delta for Huber loss (mu head).
loss_weight_mu: 0.3 # Weight for the mu head loss.
loss_weight_dir3: 1.0 # Weight for the dir3 head loss.
# --- Calibration Parameters --- # --- Calibration Parameters ---
calibration: calibration:
edge_threshold: 0.55 method: 'temperature' # Task 4.2: Calibration method: 'temperature' or 'vector'.
recalibrate_every_n: 0 edge_threshold: 0.1 # Edge threshold |2p-1| for edge_filtered_accuracy & binary action signal (e.g., 0.1 => p>0.55 or p<0.45)
recalibration_window: 10000 recalibrate_every_n: 0 # Recalibrate Temperature every N steps during backtest (0=disable).
recalibration_window: 10000 # Window size for rolling recalibration.
# --- SAC Agent Parameters --- # --- SAC Agent Parameters ---
sac: sac:
state_dim: 5 state_dim: 5 # Env state dimension (should match TradingEnv).
hidden_size: 64 hidden_size: 64 # Hidden layer size in actor/critic networks.
gamma: 0.97 gamma: 0.97 # Discount factor.
tau: 0.02 tau: 0.005 # Target network update rate.
actor_lr: 3e-4 actor_lr: 3e-4 # Initial learning rate for actor/critic/alpha optimizers.
buffer_max_size: 100000 lr_decay_rate: 0.96 # Decay rate for LR scheduler.
ou_noise_stddev: 0.2 decay_steps: 100000 # Decay steps for LR scheduler.
ou_noise_theta: 0.15 buffer_max_size: 100000 # Max size of the replay buffer.
ou_noise_dt: 0.01 ou_noise_stddev: 0.2 # OU Noise standard deviation.
alpha: 0.2 ou_noise_theta: 0.15 # OU Noise theta parameter.
alpha_auto_tune: true ou_noise_dt: 0.01 # OU Noise dt parameter.
use_batch_norm: true alpha: 0.2 # Initial alpha (entropy coefficient).
total_training_steps: 100 alpha_auto_tune: true # Automatically tune alpha?
min_buffer_size: 2000 target_entropy: null # Task 5.3: Target entropy. If null/default (-action_dim) & auto_tune=true, calculates -0.5*log(4). Otherwise uses value.
batch_size: 256 use_batch_norm: true # Use Batch Normalization in actor/critic?
log_interval: 1000 total_training_steps: 120000 # Total steps for SAC training.
save_interval: 10000 min_buffer_size: 10000 # Minimum experiences in buffer before training starts.
batch_size: 256 # Batch size for sampling from replay buffer.
log_interval: 1000 # Log training metrics every N steps.
save_interval: 10000 # Save agent checkpoints every N steps.
# --- New SAC Params (v3 Rev) ---
use_state_filter: true # Task 5.2: Normalize environment states using MeanStdFilter.
oracle_seeding_pct: 0.2 # Task 5.5: Percentage of buffer to pre-fill with heuristic actions (0.0 to disable).
# --- Environment Parameters (Used by train_sac.py) --- # --- Environment Parameters (Used by train_sac.py & backtester.py) ---
environment: environment:
initial_capital: 10000.0 # Notional capital for env/backtest consistency initial_capital: 10000.0 # Notional capital for env/backtest consistency.
transaction_cost: 0.0005 # Fractional cost per trade (e.g., 0.0005 = 0.05%) transaction_cost: 0.0005 # Fractional cost per trade (e.g., 0.0005 = 0.05%).
# --- New Env Params (v3 Rev) ---
reward_scale: 100.0 # Task 5.1: Multiplier applied to the raw environment reward.
action_penalty_lambda: 0.0 # Task 5.4: Coefficient (lambda) for action magnitude penalty (reward -= lambda * action^2).
# --- Backtesting Parameters --- # --- Backtesting Parameters ---
backtest: # (initial_capital, transaction_cost now primarily controlled under 'environment')
initial_capital: 10000.0 # Starting capital for run_pipeline backtest. # backtest:
transaction_cost: 0.0005 # Transaction cost for run_pipeline backtest. # initial_capital: 10000.0 # Deprecated: Use environment.initial_capital.
# transaction_cost: 0.0005 # Deprecated: Use environment.transaction_cost.
# --- Experience Generation (Simplified for config) --- # --- Experience Generation (Simplified for config) ---
# Configuration for how experiences are generated or sampled for SAC training. # Configuration for how experiences are generated or sampled for SAC training.
@ -83,8 +137,11 @@ experience:
# --- Control Flags --- # --- Control Flags ---
# Determine which parts of the pipeline to run. # Determine which parts of the pipeline to run.
control: control:
train_gru: true # Train the GRU model? # --- Model Version Control (Task 3.5) ---
train_sac: true # Run the offline SAC training script before backtesting? use_v3: true # Use GRU v3 model/logic? If false, uses v2.
# --- End Version Control --- #
train_gru: true # Train the selected GRU model? (v2 or v3 based on use_v3).
train_sac: true # Run the offline SAC training script before backtesting?
# --- SAC Loading/Resuming --- # --- SAC Loading/Resuming ---
# For resuming training in train_sac.py: # For resuming training in train_sac.py:

View File

@ -0,0 +1,100 @@
# Configuration for GRU-SAC Predictor
# --- Run Identification & Output ---
run_id_template: '{timestamp}' # Template for generating unique run IDs. '{timestamp}' will be replaced by YYYYMMDD_HHMMSS. Allows grouping results, logs, and models.
base_dirs:
results: 'results' # Base directory relative to package root
logs: 'logs' # Base directory relative to package root
models: 'models' # Base directory relative to package root
# --- Data Parameters ---
data:
db_dir: '../data/crypto_market_data' # Path to the directory containing the market data database (relative to where main.py is run).
exchange: 'bnbspot' # Name of the exchange table/data source in the database.
ticker: 'SOL-USDT' # Instrument identifier (e.g., trading pair) within the exchange data.
start_date: '2025-03-01' # Start date for loading data (YYYY-MM-DD). Note: Ensure enough data for lookback + splits.
end_date: '2025-03-10' # End date for loading data (YYYY-MM-DD).
interval: '1min' # Data frequency/interval (e.g., '1min', '5min', '1h').
# --- Data Split ---
split_ratios:
train: 0.6 # Proportion of the loaded data to use for training (0.0 to <1.0).
validation: 0.2 # Proportion of the loaded data to use for validation (0.0 to <1.0).
# Test ratio is calculated as 1.0 - train - validation. Ensure train + validation < 1.0.
# --- GRU Model Parameters ---
gru:
lookback: 60
epochs: 25
batch_size: 256
prediction_horizon: 5
patience: 5
model_load_run_id: '20250417_173635'
recency_weighting:
enabled: true
linear_start: 0.2
linear_end: 1.0
signed_weighting_beta: 0.0
composite_loss_kappa: 0.0
# --- Calibration Parameters ---
calibration:
edge_threshold: 0.55
recalibrate_every_n: 0
recalibration_window: 10000
# --- SAC Agent Parameters ---
sac:
state_dim: 5
hidden_size: 64
gamma: 0.97
tau: 0.02
actor_lr: 3e-4
buffer_max_size: 100000
ou_noise_stddev: 0.2
ou_noise_theta: 0.15
ou_noise_dt: 0.01
alpha: 0.2
alpha_auto_tune: true
use_batch_norm: true
total_training_steps: 100
min_buffer_size: 2000
batch_size: 256
log_interval: 1000
save_interval: 10000
# --- Environment Parameters (Used by train_sac.py) ---
environment:
initial_capital: 10000.0 # Notional capital for env/backtest consistency
transaction_cost: 0.0005 # Fractional cost per trade (e.g., 0.0005 = 0.05%)
# --- Backtesting Parameters ---
backtest:
initial_capital: 10000.0 # Starting capital for run_pipeline backtest.
transaction_cost: 0.0005 # Transaction cost for run_pipeline backtest.
# --- Experience Generation (Simplified for config) ---
# Configuration for how experiences are generated or sampled for SAC training.
# (Currently only 'generate_new_on_epoch' is directly used from here in main.py)
experience:
generate_new_on_epoch: False # If true, generate fresh experiences using validation data at the start of each SAC epoch. If false, generate experiences once initially.
# --- Control Flags ---
# Determine which parts of the pipeline to run.
control:
train_gru: true # Train the GRU model?
train_sac: true # Run the offline SAC training script before backtesting?
# --- SAC Loading/Resuming ---
# For resuming training in train_sac.py:
sac_resume_run_id: null # Run ID of SAC agent to load *before* starting training (e.g., "sac_train_..."). If null, starts fresh.
sac_resume_step: final # Checkpoint step to resume from: 'final' or step number.
# For loading agent for backtesting in run_pipeline.py:
sac_load_run_id: null # Run ID of the SAC training run to load weights from for *backtesting* (e.g., "sac_train_..."). If null, uses initial weights.
sac_load_step: final # Which SAC checkpoint to load for backtesting: 'final' or step number.
# --- Other Pipeline Controls ---
run_backtest: true # Run the backtest?
generate_plots: true # Generate output plots?
# generate_report: True # Deprecated: Metrics are saved to a .txt file.

File diff suppressed because one or more lines are too long

View File

@ -1,469 +0,0 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
from datetime import datetime
import warnings
import logging
import sys
import json
# --- Generate Run ID ---
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
# Import components
# V7 Update: Import load_data_from_db
from .src.data_pipeline import create_data_pipeline, load_data_from_db
from .src.trading_system import TradingSystem, ExtendedBacktester, plot_sac_training_history
# V7.3 Fix: Add missing imports
# V7-V6 Final Update: Import CryptoGRUModel
from .src.gru_predictor import CryptoGRUModel
# V7.5 Import the simplified agent
from .src.sac_agent_simplified import SimplifiedSACTradingAgent
# GRU and SAC classes are implicitly imported via TradingSystem
# --- Base Output Directories ---
BASE_RESULTS_DIR = "gru_sac_predictor/results"
BASE_LOGS_DIR = "gru_sac_predictor/logs"
BASE_MODELS_DIR = "gru_sac_predictor/models"
# --- Run Specific Directories ---
RUN_RESULTS_DIR = os.path.join(BASE_RESULTS_DIR, run_id)
RUN_LOGS_DIR = os.path.join(BASE_LOGS_DIR, run_id)
RUN_MODELS_DIR = os.path.join(BASE_MODELS_DIR, f"run_{run_id}")
# --- Logging Setup ---
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
# Ensure logs directory exists
os.makedirs(RUN_LOGS_DIR, exist_ok=True)
log_file_path = os.path.join(RUN_LOGS_DIR, f"main_{run_id}.log") # Removed _v7
logging.basicConfig(
level=logging.INFO,
format=log_format,
handlers=[
logging.FileHandler(log_file_path, mode='a'), # Use path variable
logging.StreamHandler(sys.stdout)
]
)
logger = logging.getLogger(__name__)
# --- Configuration Parameters ---
# V7.7 Move configuration to top-level for clarity
# V7.7 Adjusted path relative to main.py's location inside gru_sac_predictor/
DB_DIR = '../../data/crypto_market_data' # New path to crypto data
# Data Parameters
EXCHANGE = 'binance'
TICKER = 'BTC-USD' # Example ticker
START_DATE = '2025-03-01' # Example start date - NOTE: VERY SHORT!
END_DATE = '2025-03-10' # Example end date - NOTE: VERY SHORT!
INTERVAL = '1min' # Data interval to fetch and use
MODEL_SAVE_PATH = RUN_MODELS_DIR # Use run-specific directory
# Updated paths to use RUN_RESULTS_DIR and include run_id
RESULTS_PLOT_PATH = os.path.join(RUN_RESULTS_DIR, f'backtest_results_{run_id}.png') # Removed _v7
REPORT_SAVE_PATH = os.path.join(RUN_RESULTS_DIR, f'backtest_performance_report_{run_id}.md') # Removed _v7
# GRU_PLOT_PATH = 'gru_performance_v7.png' # Not used directly in main
# V7.6 Add specific run ID for loading GRU model
GRU_MODEL_LOAD_RUN_ID = '20250416_142744' # Set this to a specific 'YYYYMMDD_HHMMSS' string to load that GRU model
# Data split ratios
TRAIN_RATIO = 0.6
VALIDATION_RATIO = 0.2
# Model/Training Parameters (V7.3)
GRU_LOOKBACK = 60
GRU_PREDICTION_HORIZON = 1
GRU_EPOCHS = 20
GRU_BATCH_SIZE = 32 # Updated default
GRU_PATIENCE = 10 # Updated default
GRU_LR_PATIENCE = 10 # Updated default
GRU_LR_FACTOR = 0.5 # Updated default
GRU_RETURN_SCALE = 0.03 # Updated default
# SAC Parameters (V7.5 - Simplified Agent)
SAC_STATE_DIM = 5 # [pred_return, uncertainty, z, momentum_5, volatility_20] - Updated from 2
SAC_HIDDEN_SIZE = 64
SAC_GAMMA = 0.97
SAC_TAU = 0.02
# SAC_ALPHA = 0.1 # Removed - Will use automatic tuning
SAC_ACTOR_LR = 1.5e-5 # Halved from 3e-4 -> 10x lower again
SAC_CRITIC_LR = 2.5e-5 # Halved from 5e-4 -> 10x lower again
SAC_BATCH_SIZE = 64
SAC_BUFFER_MAX_SIZE = 20000
SAC_MIN_BUFFER_SIZE = 1000
SAC_UPDATE_INTERVAL = 1
SAC_TARGET_UPDATE_INTERVAL = 2
SAC_GRADIENT_CLIP = 1.0
SAC_REWARD_SCALE = 1.0 # Decreased from 10.0 -> 2.0 -> 1.0
SAC_USE_BATCH_NORM = True
SAC_USE_RESIDUAL = True
SAC_MODEL_DIR = 'models/simplified_sac' # Default dir within the agent class
SAC_EPOCHS = 5 # Keep this from previous config for training loop control
# V7.9 Experience Generation Config (Based on instructions.txt)
# TOTAL_TRAINING_STEPS = 1000 # Removed - Not used in current training loop
experience_config = {
# Basic setup
'initial_experiences': 3000, # Start with this many experiences
'experiences_per_batch': 64, # Generate this many in each new batch
'batch_generation_interval': 500, # Generate a new batch every N training steps
# Distribution control (Flags for future implementation in generate_trading_experiences)
'balance_market_regimes': False, # Not implemented
'recency_bias_strength': 0.5, # 0 = uniform, >0 weights recent data more
'high_uncertainty_quantile': 0.75, # Threshold for high uncertainty
'extreme_return_quantile': 0.1, # Threshold for extreme returns (upper/lower)
'min_uncertainty_ratio': 0.2, # Min % of samples with high uncertainty
'min_extreme_return_ratio': 0.1, # Min % of samples with extreme returns
# Efficient processing
'use_parallel_generation': False, # Not implemented
'precompute_all_gru_outputs': True, # Already implemented
'buffer_update_strategy': 'fifo', # Agent currently uses FIFO
# Training optimization
'training_iterations_per_step': 1, # Number of agent.train calls per main loop step
# Max/Min buffer size are defined by the agent itself now
}
# Backtesting Parameters
INITIAL_CAPITAL = 10000.0
TRANSACTION_COST = 0.0005
# V7.12 Add Opportunity Cost Penalty Parameters
OPPORTUNITY_COST_PENALTY_FACTOR = 0.0 # How much to penalize missed high returns - Disabled (was 1.0)
HIGH_RETURN_THRESHOLD = 0.002 # Actual return magnitude threshold to trigger penalty check
ACTION_TOLERANCE = 0.3 # Action magnitude below which penalty applies if return threshold met - Lowered from 0.5
# RISK_PENALTY_FACTOR = 0.0 # Removed as state reverted
# Control Flags
LOAD_EXISTING_SYSTEM = True
TRAIN_GRU_MODEL = False
TRAIN_SAC_AGENT = True # V7.8 Set to True to train SAC
LOAD_SAC_AGENT = False # V7.8 Set to False to avoid loading SAC
RUN_BACKTEST = True
GENERATE_PLOTS = True
GENERATE_REPORT = True
# --- End Configuration ---
def main():
# Access config variables defined at module level
global LOAD_EXISTING_SYSTEM, TRAIN_GRU_MODEL, TRAIN_SAC_AGENT, LOAD_SAC_AGENT
logger.info(f"--- Starting GRU+SAC Trading System Pipeline (Run ID: {run_id}) ---") # Removed V7
# Ensure results directory exists
os.makedirs(RUN_RESULTS_DIR, exist_ok=True)
# Ensure base models directory exists (RUN_MODELS_DIR created later if training)
os.makedirs(BASE_MODELS_DIR, exist_ok=True)
# LOAD_EXISTING_SYSTEM is now declared global before use here
# --- Save Configuration ---
config_to_save = {
"run_id": run_id,
"db_dir": DB_DIR,
"ticker": TICKER,
"exchange": EXCHANGE,
"start_date": START_DATE,
"end_date": END_DATE,
"interval": INTERVAL,
"model_save_path": MODEL_SAVE_PATH,
"results_plot_path": RESULTS_PLOT_PATH,
"report_save_path": REPORT_SAVE_PATH,
"train_ratio": TRAIN_RATIO,
"validation_ratio": VALIDATION_RATIO,
"gru_lookback": GRU_LOOKBACK,
"gru_prediction_horizon": GRU_PREDICTION_HORIZON,
"gru_epochs": GRU_EPOCHS,
"gru_batch_size": GRU_BATCH_SIZE,
"gru_patience": GRU_PATIENCE,
"gru_lr_factor": GRU_LR_FACTOR,
"gru_return_scale": GRU_RETURN_SCALE,
"gru_model_load_run_id": GRU_MODEL_LOAD_RUN_ID,
"sac_state_dim": SAC_STATE_DIM,
"sac_hidden_size": SAC_HIDDEN_SIZE,
"sac_gamma": SAC_GAMMA,
"sac_tau": SAC_TAU,
"sac_actor_lr": SAC_ACTOR_LR,
"sac_critic_lr": SAC_CRITIC_LR,
"sac_batch_size": SAC_BATCH_SIZE,
"sac_buffer_max_size": SAC_BUFFER_MAX_SIZE,
"sac_min_buffer_size": SAC_MIN_BUFFER_SIZE,
"sac_update_interval": SAC_UPDATE_INTERVAL,
"sac_target_update_interval": SAC_TARGET_UPDATE_INTERVAL,
"sac_gradient_clip": SAC_GRADIENT_CLIP,
"sac_reward_scale": SAC_REWARD_SCALE,
"sac_use_batch_norm": SAC_USE_BATCH_NORM,
"sac_use_residual": SAC_USE_RESIDUAL,
"sac_model_dir": SAC_MODEL_DIR,
"sac_epochs": SAC_EPOCHS,
"experience_config": experience_config,
"initial_capital": INITIAL_CAPITAL,
"transaction_cost": TRANSACTION_COST,
# V7.12 Add new params to saved config
"opportunity_cost_penalty_factor": OPPORTUNITY_COST_PENALTY_FACTOR,
"high_return_threshold": HIGH_RETURN_THRESHOLD,
"action_tolerance": ACTION_TOLERANCE,
"load_existing_system": LOAD_EXISTING_SYSTEM,
"train_gru_model": TRAIN_GRU_MODEL,
"train_sac_agent": TRAIN_SAC_AGENT,
"load_sac_agent": LOAD_SAC_AGENT,
"run_backtest": RUN_BACKTEST,
"generate_plots": GENERATE_PLOTS,
"generate_report": GENERATE_REPORT
}
config_save_path = os.path.join(RUN_RESULTS_DIR, f'config_{run_id}.json')
try:
with open(config_save_path, 'w') as f:
json.dump(config_to_save, f, indent=4)
logger.info(f"Run configuration saved to {config_save_path}")
except Exception as e:
logger.error(f"Failed to save run configuration: {e}")
# --- End Save Configuration ---
# 1. Load Data from Database
logger.info(f"Loading data from DB: {TICKER}/{EXCHANGE} ({START_DATE}-{END_DATE}) @ {INTERVAL}")
data = load_data_from_db(
db_dir=DB_DIR,
ticker=TICKER,
exchange=EXCHANGE,
start_date=START_DATE,
end_date=END_DATE,
interval=INTERVAL
)
if data.empty:
logger.error("Failed to load data from database. Please check DB_DIR and parameters. Aborting.")
return
# --- Re-inserted Steps Start ---
# Basic Data Validation (Timestamp index assumed from load_data_from_db)
if 'close' not in data.columns: # Check essential columns
raise ValueError("Loaded data must contain 'close' column.")
logger.info(f"Data loaded: {len(data)} rows, from {data.index.min()} to {data.index.max()}")
initial_len = len(data); data.dropna(subset=['open', 'high', 'low', 'close', 'volume'], inplace=True)
if len(data) < initial_len: logger.info(f"Dropped {initial_len - len(data)} NaN rows.")
if len(data) < GRU_LOOKBACK * 3: raise ValueError(f"Insufficient data ({len(data)} rows) for lookback/splits.")
# Add cyclical features immediately
logger.info("Calculating cyclical time features (hour_sin, hour_cos)...")
timestamp_source = None
if isinstance(data.index, pd.DatetimeIndex):
timestamp_source = data.index
logger.debug("Using index for hour features.")
elif 'timestamp' in data.columns and pd.api.types.is_datetime64_any_dtype(data['timestamp']):
timestamp_source = pd.to_datetime(data['timestamp'])
logger.debug("Using 'timestamp' column for hour features.")
elif 'date' in data.columns and pd.api.types.is_datetime64_any_dtype(data['date']):
timestamp_source = pd.to_datetime(data['date'])
logger.debug("Using 'date' column for hour features.")
if timestamp_source is not None:
data['hour_sin'] = np.sin(2 * np.pi * timestamp_source.hour / 24)
data['hour_cos'] = np.cos(2 * np.pi * timestamp_source.hour / 24)
logger.info("Added hour_sin/hour_cos to main dataframe.")
else:
logger.warning("Could not find suitable timestamp source. Setting hour_sin/cos defaults (0.0, 1.0).")
data['hour_sin'] = 0.0
data['hour_cos'] = 1.0 # Default to cos(0) = 1
# 2. Split Data Chronologically
logger.info("Splitting data...")
test_ratio = round(1.0 - TRAIN_RATIO - VALIDATION_RATIO, 2)
if test_ratio <= 0: raise ValueError("Train+Validation ratios must sum to < 1.")
train_data, val_data, test_data = create_data_pipeline(data, [TRAIN_RATIO, VALIDATION_RATIO, test_ratio])
if len(train_data) < GRU_LOOKBACK or len(val_data) < GRU_LOOKBACK or len(test_data) < GRU_LOOKBACK:
warnings.warn(f"Splits smaller than GRU lookback ({GRU_LOOKBACK}). Backtesting might fail.")
# 3. Initialize Trading System
logger.info("Initializing Trading System...")
trading_system = TradingSystem(
gru_model=CryptoGRUModel(), # Instantiate the correct model
sac_agent=SimplifiedSACTradingAgent(
state_dim=SAC_STATE_DIM,
hidden_size=SAC_HIDDEN_SIZE,
gamma=SAC_GAMMA,
tau=SAC_TAU,
actor_lr=SAC_ACTOR_LR,
critic_lr=SAC_CRITIC_LR,
batch_size=SAC_BATCH_SIZE,
buffer_max_size=SAC_BUFFER_MAX_SIZE,
min_buffer_size=SAC_MIN_BUFFER_SIZE,
update_interval=SAC_UPDATE_INTERVAL,
target_update_interval=SAC_TARGET_UPDATE_INTERVAL,
gradient_clip=SAC_GRADIENT_CLIP,
reward_scale=SAC_REWARD_SCALE,
use_batch_norm=SAC_USE_BATCH_NORM,
use_residual=SAC_USE_RESIDUAL,
model_dir=os.path.join(MODEL_SAVE_PATH, 'sac_agent') # Point to subfolder within run
), # Pass the configured agent
gru_lookback=GRU_LOOKBACK
)
# --- Model Loading/Training ---
gru_loaded = False; sac_loaded = False
if LOAD_EXISTING_SYSTEM:
load_base_path = MODEL_SAVE_PATH
logger.info(f"Attempting to load existing system components...")
logger.info(f"Base path for loading: {load_base_path}")
gru_model_load_dir = None
sac_model_load_dir = None
if GRU_MODEL_LOAD_RUN_ID:
gru_model_load_dir = os.path.join(BASE_MODELS_DIR, f'run_{GRU_MODEL_LOAD_RUN_ID}')
logger.info(f"Using specific GRU load path based on run ID: {gru_model_load_dir}")
if LOAD_SAC_AGENT:
sac_model_load_dir = os.path.join(BASE_MODELS_DIR, f'run_{GRU_MODEL_LOAD_RUN_ID}')
logger.info(f"Using specific SAC load path based on GRU run ID (LOAD_SAC_AGENT=True): {sac_model_load_dir}")
else:
sac_model_load_dir = os.path.join(MODEL_SAVE_PATH, 'sac_agent')
logger.info(f"Defaulting SAC path to current run (LOAD_SAC_AGENT=False): {sac_model_load_dir}")
elif os.path.exists(load_base_path):
gru_model_load_dir = os.path.join(load_base_path, 'gru_model')
sac_model_load_dir = os.path.join(load_base_path, 'sac_agent')
logger.info(f"Using GRU load path based on MODEL_SAVE_PATH: {gru_model_load_dir}")
logger.info(f"Using SAC load path based on MODEL_SAVE_PATH: {sac_model_load_dir}")
else:
logger.warning(f"LOAD_EXISTING_SYSTEM is True, but MODEL_SAVE_PATH does not exist: {load_base_path}. Cannot determine model paths.")
LOAD_EXISTING_SYSTEM = False
if LOAD_EXISTING_SYSTEM:
try:
if gru_model_load_dir and os.path.isdir(gru_model_load_dir):
logger.info(f"Found GRU model directory: {gru_model_load_dir}. Loading...")
if trading_system.gru_model is None: trading_system.gru_model = CryptoGRUModel()
if trading_system.gru_model.load(gru_model_load_dir):
logger.info("GRU model loaded successfully.")
gru_loaded = True
trading_system.feature_scaler = trading_system.gru_model.feature_scaler
trading_system.y_scaler = trading_system.gru_model.y_scaler
logger.info("Scalers propagated from loaded GRU model.")
else: logger.warning(f"GRU model directory found, but loading failed.")
elif gru_model_load_dir: logger.warning(f"GRU model directory specified or derived, but not found at {gru_model_load_dir}. GRU model cannot be loaded.")
else: logger.warning("GRU model path could not be determined. GRU model cannot be loaded.")
if LOAD_SAC_AGENT:
if sac_model_load_dir and os.path.isdir(sac_model_load_dir):
logger.info(f"Found SAC model directory: {sac_model_load_dir}. Loading (LOAD_SAC_AGENT=True)...")
if trading_system.sac_agent is None:
trading_system.sac_agent = SimplifiedSACTradingAgent(state_dim=SAC_STATE_DIM, model_dir=sac_model_load_dir)
if trading_system.sac_agent.load(sac_model_load_dir):
logger.info("SAC agent loaded successfully.")
sac_loaded = True
else: logger.warning(f"SAC model directory found, but loading failed.")
elif sac_model_load_dir: logger.warning(f"SAC agent model directory derived, but not found at {sac_model_load_dir}. SAC agent cannot be loaded (LOAD_SAC_AGENT=True).")
else: logger.info("Skipping SAC agent loading (LOAD_SAC_AGENT=False).")
if gru_loaded: TRAIN_GRU_MODEL = False
if sac_loaded: TRAIN_SAC_AGENT = False; LOAD_SAC_AGENT = True
except Exception as e:
logger.warning(f"Could not load existing system components: {e}. Proceeding based on training flags.")
gru_loaded = False; sac_loaded = False
TRAIN_GRU_MODEL = True; TRAIN_SAC_AGENT = True; LOAD_SAC_AGENT = False
elif LOAD_EXISTING_SYSTEM: pass
else: logger.info("LOAD_EXISTING_SYSTEM=False. Proceeding with training flags.")
# --- Sanity Check After Loading ---
if not gru_loaded and not TRAIN_GRU_MODEL:
logger.error("Critical Error: GRU model was not loaded and TRAIN_GRU_MODEL is False. Cannot proceed.")
return
if not sac_loaded and not TRAIN_SAC_AGENT:
if RUN_BACKTEST:
logger.error("Critical Error: SAC agent was not loaded and TRAIN_SAC_AGENT is False. Aborting because RUN_BACKTEST is True.")
return
else: logger.warning("Proceeding without a functional SAC agent as RUN_BACKTEST is False.")
# Train GRU Model (if flag is set and not loaded)
if TRAIN_GRU_MODEL:
logger.info("--- Training GRU Model --- ")
gru_save_dir = MODEL_SAVE_PATH
history = trading_system.train_gru(
train_data=train_data, val_data=val_data,
prediction_horizon=GRU_PREDICTION_HORIZON,
epochs=GRU_EPOCHS, batch_size=GRU_BATCH_SIZE,
patience=GRU_PATIENCE,
model_save_dir=gru_save_dir
)
if history is None: logger.error("GRU Training failed. Aborting."); return
logger.info("--- GRU Model Training Finished --- ")
elif not gru_loaded: logger.error("GRU Model must be trained or loaded."); return
else: logger.info("Skipping GRU training (already loaded).")
# Train SAC Agent (if flag is set and not loaded)
if TRAIN_SAC_AGENT:
logger.info("--- Training SAC Agent --- ")
if not trading_system.gru_model or not (trading_system.gru_model.is_trained or trading_system.gru_model.is_loaded):
logger.error("Cannot train SAC: GRU model not ready."); return
if trading_system.sac_agent is None: logger.error("SAC Agent instance is missing in the trading system before training."); return
trading_system.sac_agent.model_dir = os.path.join(MODEL_SAVE_PATH, 'sac_agent')
logger.info(f"Ensured SAC agent model save dir is set to: {trading_system.sac_agent.model_dir}")
sac_history = trading_system.train_sac(
val_data=val_data,
epochs=SAC_EPOCHS,
batch_size=SAC_BATCH_SIZE,
transaction_cost=TRANSACTION_COST,
prediction_horizon=GRU_PREDICTION_HORIZON
)
logger.info("Finished training SAC agent.")
if sac_history is not None:
sac_save_dir = os.path.join(MODEL_SAVE_PATH, 'sac_agent')
logger.info(f"Saving Simplified SAC agent to {sac_save_dir}")
trading_system.sac_agent.save(sac_save_dir)
if sac_history:
sac_plot_save_path = os.path.join(RUN_RESULTS_DIR, f'sac_training_history_{run_id}.png')
logger.info(f"Plotting SAC training history to {sac_plot_save_path}...")
try: plot_sac_training_history(sac_history, save_path=sac_plot_save_path)
except Exception as plot_e: logger.error(f"Failed to plot SAC training history: {plot_e}", exc_info=True)
else: logger.warning("SAC training finished, but no history data returned for plotting.")
elif not sac_loaded and LOAD_SAC_AGENT:
# This block handles loading SAC if LOAD_EXISTING_SYSTEM was False but LOAD_SAC_AGENT was True (unlikely case)
if trading_system.sac_agent is None: trading_system.sac_agent = SimplifiedSACTradingAgent(state_dim=SAC_STATE_DIM)
sac_load_path = os.path.join(MODEL_SAVE_PATH, 'sac_agent') # Load from current run models
if os.path.isdir(sac_load_path):
logger.info(f"Attempting to load SAC weights from {sac_load_path} (LOAD_SAC_AGENT=True)...")
try: trading_system.sac_agent.load(sac_load_path); logger.info("SAC weights loaded."); sac_loaded = True
except Exception as e: logger.warning(f"Could not load SAC weights: {e}")
else: logger.warning(f"LOAD_SAC_AGENT=True but no weights found at {sac_load_path}.")
elif not sac_loaded: logger.warning("SAC Agent not trained or loaded.")
else: logger.info("Skipping SAC training (already loaded).")
# 5. Backtest on Test Data
if RUN_BACKTEST:
logger.info("--- Running Extended Backtest --- ")
if not trading_system.gru_model or not (trading_system.gru_model.is_trained or trading_system.gru_model.is_loaded):
logger.error("Cannot backtest: GRU model not ready."); return
if not trading_system.sac_agent: logger.error("Cannot backtest: SAC Agent not initialized."); return
instrument_label = f"{TICKER}/{EXCHANGE}"
backtester = ExtendedBacktester(
trading_system,
initial_capital=INITIAL_CAPITAL,
transaction_cost=TRANSACTION_COST,
instrument_label=instrument_label
)
backtest_results = backtester.backtest(test_data, verbose=True)
# 6. Generate Plots and Report
if GENERATE_PLOTS:
logger.info(f"Generating overall performance plot: {RESULTS_PLOT_PATH}...")
backtester.plot_results(save_path=RESULTS_PLOT_PATH)
if GENERATE_REPORT:
logger.info(f"Generating performance report: {REPORT_SAVE_PATH}...")
backtester.generate_performance_report(report_path=REPORT_SAVE_PATH)
else:
logger.info("Skipping backtesting.")
# --- Re-inserted Steps End ---
logger.info("--- GRU+SAC Pipeline Finished --- ")
if __name__ == "__main__":
main()

View File

@ -1,13 +0,0 @@
[
"ATR_14",
"EMA_50",
"MACD_signal",
"chaikin_AD_10",
"hour_cos",
"hour_sin",
"return_15m",
"return_1m",
"return_60m",
"svi_10",
"volatility_14d"
]

View File

@ -1,13 +0,0 @@
[
"ATR_14",
"EMA_50",
"MACD_signal",
"chaikin_AD_10",
"hour_cos",
"hour_sin",
"return_15m",
"return_1m",
"return_60m",
"svi_10",
"volatility_14d"
]

View File

@ -1,13 +0,0 @@
[
"ATR_14",
"EMA_10",
"MACD_signal",
"chaikin_AD_10",
"hour_cos",
"hour_sin",
"return_15m",
"return_1m",
"return_60m",
"svi_10",
"volatility_14d"
]

View File

@ -1,337 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# GRU-SAC Trading Pipeline: Example Usage\n",
"\n",
"This notebook demonstrates how to instantiate and run the refactored `TradingPipeline` class.\n",
"\n",
"**Goal:** Run the complete pipeline (data loading, feature engineering, GRU training/loading, calibration, optional SAC training, backtesting) using a configuration file and inspect the results."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Imports and Setup"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initial sys.path: ['/home/yasha/develop', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/yasha/develop/gru_sac_predictor/.venv/lib/python3.10/site-packages']\n",
"Notebook directory (notebook_dir): /home/yasha/develop/gru_sac_predictor/notebooks\n",
"Calculated path for imports (project_root_for_imports): /home/yasha/develop/gru_sac_predictor\n",
"Checking if /home/yasha/develop/gru_sac_predictor is in sys.path...\n",
"Path not found. Adding /home/yasha/develop/gru_sac_predictor to sys.path.\n",
"sys.path after insert: ['/home/yasha/develop/gru_sac_predictor', '/home/yasha/develop', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/yasha/develop/gru_sac_predictor/.venv/lib/python3.10/site-packages']\n",
"Package path (package_path): /home/yasha/develop/gru_sac_predictor/gru_sac_predictor\n",
"Src path (src_path): /home/yasha/develop/gru_sac_predictor/gru_sac_predictor/src\n",
"\n",
"Attempting to import TradingPipeline...\n",
"ERROR: Failed to import TradingPipeline: No module named 'gru_sac_predictor.src'\n",
"Final sys.path before error: ['/home/yasha/develop/gru_sac_predictor', '/home/yasha/develop', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '', '/home/yasha/develop/gru_sac_predictor/.venv/lib/python3.10/site-packages']\n",
"Please verify the calculated paths above and ensure the directory containing 'gru_sac_predictor' is correctly added to sys.path.\n"
]
}
],
"source": [
"import os\n",
"import sys\n",
"import yaml\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.image as mpimg\n",
"import logging\n",
"\n",
"print(f'Initial sys.path: {sys.path}')\n",
"\n",
"# --- Path Setup ---\n",
"# Initialize project_root to None\n",
"project_root = None\n",
"project_root_for_imports = None # Initialize separately for clarity\n",
"try:\n",
" notebook_dir = os.path.abspath('') # Get current directory (should be notebooks/)\n",
" print(f'Notebook directory (notebook_dir): {notebook_dir}')\n",
"\n",
" # *** CORRECTED LINE BELOW ***\n",
" # Go up ONE level to get the directory containing the gru_sac_predictor package\n",
" # Assuming notebook is in develop/gru_sac_predictor/notebooks/\n",
" # This should result in '/home/yasha/develop/gru_sac_predictor'\n",
" project_root_for_imports = os.path.dirname(notebook_dir)\n",
" print(f'Calculated path for imports (project_root_for_imports): {project_root_for_imports}')\n",
"\n",
" # Add the calculated path to sys.path to allow imports from gru_sac_predictor\n",
" print(f'Checking if {project_root_for_imports} is in sys.path...')\n",
" if project_root_for_imports not in sys.path:\n",
" print(f'Path not found. Adding {project_root_for_imports} to sys.path.')\n",
" sys.path.insert(0, project_root_for_imports)\n",
" print(f'sys.path after insert: {sys.path}')\n",
" else:\n",
" print(f'Path {project_root_for_imports} already in sys.path.')\n",
"\n",
" # Define project_root consistently, used later for finding config.yaml\n",
" project_root = project_root_for_imports\n",
" if project_root: # Check if project_root was set successfully\n",
" package_path = os.path.join(project_root, 'gru_sac_predictor')\n",
" src_path = os.path.join(package_path, 'src')\n",
" print(f'Package path (package_path): {package_path}')\n",
" print(f'Src path (src_path): {src_path}')\n",
" else:\n",
" print(\"Project root could not be determined.\")\n",
"\n",
"except Exception as e:\n",
" print(f'Error during path setup: {e}')\n",
"\n",
"# --- Import the main pipeline class ---\n",
"print(\"\\nAttempting to import TradingPipeline...\")\n",
"try:\n",
" # Now this import should work if the path setup is correct\n",
" from gru_sac_predictor.src.trading_pipeline import TradingPipeline\n",
" print('Successfully imported TradingPipeline.')\n",
"except ImportError as e:\n",
" print(f'ERROR: Failed to import TradingPipeline: {e}')\n",
" print(f'Final sys.path before error: {sys.path}')\n",
" print(\"Please verify the calculated paths above and ensure the directory containing 'gru_sac_predictor' is correctly added to sys.path.\")\n",
" # Handle error appropriately, maybe raise it\n",
"except Exception as e: # Catch other potential errors\n",
" print(f'An unexpected error occurred during import: {e}')\n",
" print(f'Final sys.path before error: {sys.path}')\n",
"\n",
"# Configure basic logging for the notebook\n",
"logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Configuration\n",
"\n",
"Specify the path to the configuration file (`config.yaml`). This file defines all parameters for the data, models, training, and backtesting."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using config file: /home/../gru_sac_predictor/config.yaml\n",
"ERROR: Config file not found at /home/../gru_sac_predictor/config.yaml\n"
]
}
],
"source": [
"# Path to the configuration file \n",
"# Assumes config.yaml is in the gru_sac_predictor package directory, one level above src\n",
"config_rel_path = '../config.yaml'\n",
"# Construct absolute path relative to the project root identified earlier\n",
"if 'project_root' in locals():\n",
" config_abs_path = os.path.join(project_root, config_rel_path)\n",
"else:\n",
" print('ERROR: project_root not defined. Cannot find config file.')\n",
" config_abs_path = None\n",
"\n",
"if config_abs_path:\n",
" print(f'Using config file: {config_abs_path}')\n",
" # Verify the config file exists\n",
" if not os.path.exists(config_abs_path):\n",
" print(f'ERROR: Config file not found at {config_abs_path}')\n",
" else:\n",
" print('Config file found.')\n",
" # Optionally load and display config for verification\n",
" try:\n",
" with open(config_abs_path, 'r') as f:\n",
" config_data = yaml.safe_load(f)\n",
" # print('\\nConfiguration:')\n",
" # print(yaml.dump(config_data, default_flow_style=False)) # Pretty print\n",
" except Exception as e:\n",
" print(f'Error reading config file: {e}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Instantiate and Run the Pipeline\n",
"\n",
"Create an instance of the `TradingPipeline` and run its `execute()` method. This will perform all the steps defined in the configuration.\n",
"\n",
"**Note:** Depending on the configuration (especially `train_gru` and `train_sac` flags) and the data size, this cell might take a significant amount of time to run."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pipeline_instance = None # Define outside try block\n",
"if 'TradingPipeline' in locals() and config_abs_path and os.path.exists(config_abs_path): \n",
" try:\n",
" # Instantiate the pipeline\n",
" pipeline_instance = TradingPipeline(config_path=config_abs_path)\n",
" \n",
" # Execute the full pipeline\n",
" print('\\n=== Starting Pipeline Execution ===')\n",
" pipeline_instance.execute()\n",
" print('=== Pipeline Execution Finished ===')\n",
" \n",
" except FileNotFoundError as e:\n",
" print(f'ERROR during pipeline instantiation (FileNotFound): {e}')\n",
" except Exception as e:\n",
" print(f'An error occurred during pipeline execution: {e}')\n",
" logging.error('Pipeline execution failed.', exc_info=True) # Log traceback\n",
"else:\n",
" print('TradingPipeline class not imported, config path invalid, or config file not found. Cannot run pipeline.')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Inspect Results\n",
"\n",
"After the pipeline execution, we can inspect the results stored within the `pipeline_instance` object and the files saved to the run directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if pipeline_instance is not None and pipeline_instance.backtest_metrics:\n",
" print('\\n--- Backtest Metrics --- ')\n",
" # Pretty print the metrics dictionary\n",
" metrics = pipeline_instance.backtest_metrics\n",
" # Update Run ID in metrics before printing\n",
" metrics['Run ID'] = pipeline_instance.run_id \n",
" \n",
" for key, value in metrics.items():\n",
" if key == \"Confusion Matrix (GRU Signal vs Actual Dir)\":\n",
" print(f'{key}:\\n{np.array(value)}') \n",
" elif key == \"Classification Report (GRU Signal)\":\n",
" print(f'{key}:\\n{value}')\n",
" elif isinstance(value, float):\n",
" print(f'{key}: {value:.4f}')\n",
" else:\n",
" print(f'{key}: {value}')\n",
"else:\n",
" print('\\nPipeline object not found or backtest did not produce metrics.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if pipeline_instance is not None and pipeline_instance.backtest_results_df is not None:\n",
" print('\\n--- Backtest Results DataFrame (Head) --- ')\n",
" pd.set_option('display.max_columns', None) # Show all columns\n",
" pd.set_option('display.width', 1000) # Wider display\n",
" display(pipeline_instance.backtest_results_df.head())\n",
" print('\\n--- Backtest Results DataFrame (Tail) --- ')\n",
" display(pipeline_instance.backtest_results_df.tail())\n",
" \n",
" # Display basic stats\n",
" print('\\n--- Backtest Results DataFrame (Description) --- ')\n",
" display(pipeline_instance.backtest_results_df.describe())\n",
"else:\n",
" print('\\nPipeline object not found or backtest did not produce results DataFrame.')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Display Saved Plots\n",
"\n",
"Load and display the plots generated during the backtest. These are saved in the `results/<run_id>` directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if pipeline_instance is not None and pipeline_instance.dirs.get('results'):\n",
" results_dir = pipeline_instance.dirs['results']\n",
" run_id = pipeline_instance.run_id\n",
" print(f'Looking for plots in: {results_dir}\\n')\n",
" \n",
" plot_files = [\n",
" f'backtest_summary_{run_id}.png', \n",
" f'confusion_matrix_{run_id}.png', \n",
" f'reliability_curve_val_{run_id}.png' # Optional validation plot\n",
" ]\n",
" \n",
" for plot_file in plot_files:\n",
" plot_path = os.path.join(results_dir, plot_file)\n",
" if os.path.exists(plot_path):\n",
" print(f'--- Displaying: {plot_file} ---')\n",
" try:\n",
" img = mpimg.imread(plot_path)\n",
" # Determine appropriate figure size based on plot type\n",
" figsize = (15, 12) if 'summary' in plot_file else (7, 6)\n",
" plt.figure(figsize=figsize)\n",
" plt.imshow(img)\n",
" plt.axis('off') # Hide axes for image display\n",
" plt.title(plot_file)\n",
" plt.show()\n",
" except Exception as e:\n",
" print(f' Error loading/displaying plot {plot_file}: {e}')\n",
" else:\n",
" print(f'Plot not found: {plot_path}')\n",
" \n",
"else:\n",
" print('\\nPipeline object not found or results directory is not available. Cannot display plots.')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Conclusion\n",
"\n",
"This notebook demonstrated the basic workflow of using the `TradingPipeline`. You can modify the `config.yaml` file to experiment with different parameters, data ranges, and control flags (e.g., enabling/disabling GRU or SAC training). The results (metrics, plots, detailed CSV) are saved in the run-specific directory under `results/`."
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@ -1,10 +1,17 @@
pandas pandas==2.1.0
numpy numpy==1.26.0 # Or newer
tensorflow tensorflow==2.18.0 # Upgrade to TF 2.18
tensorflow-probability tf-keras==2.18.0 # Match TF version
tensorflow-probability==0.25.0 # Matches TF >= 2.18 requirement
matplotlib matplotlib
joblib joblib
scikit-learn scikit-learn
tqdm tqdm
PyYAML PyYAML
# TA-Lib # TA-Lib C library wrapper (requires libta-lib-dev installed)
# TA-Lib
ta # Use pure Python ta library
# tensorflow-addons==0.23.0 # Removed - incompatible
scipy
pytest
statsmodels # Added for VIF calculation

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 14:29:57.872322
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $10,320.55
* **Total return:** 3.21%
* **Annualized return:** 506709.93%
* **Sharpe ratio (annualized):** 10.5985
* **Sortino ratio (annualized):** 16.0926
* **Volatility (annualized):** 83.80%
* **Maximum drawdown:** 5.18%
* **Total trades:** 1
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.7616
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** nan
* **Uncertainty-Position Size correlation:** nan
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 KiB

View File

@ -1,45 +0,0 @@
{
"run_id": "20250416_142744",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/crypto_trading_system_v7_20250416_142744",
"results_plot_path": "v7/results/20250416_142744/backtest_results_v7_20250416_142744.png",
"report_save_path": "v7/results/20250416_142744/backtest_performance_report_v7_20250416_142744.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"sac_state_dim": 2,
"sac_initial_lr": 0.0003,
"sac_end_lr": 5e-06,
"sac_decay_steps": 100000,
"sac_lr_decay_rate": 0.96,
"sac_gamma": 0.99,
"sac_tau": 0.005,
"sac_alpha_initial": 0.2,
"sac_alpha_auto_tune": true,
"sac_target_entropy": -1.0,
"sac_ou_noise_stddev": 0.2,
"sac_ou_noise_theta": 0.15,
"sac_ou_noise_dt": 0.01,
"sac_buffer_capacity": 100000,
"sac_batch_size": 256,
"sac_min_buffer_size": 1000,
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": false,
"train_gru_model": true,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_144232",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/crypto_trading_system_v7_20250416_144232",
"results_plot_path": "v7/results/20250416_144232/backtest_results_v7_20250416_144232.png",
"report_save_path": "v7/results/20250416_144232/backtest_performance_report_v7_20250416_144232.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_144418",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_144418",
"results_plot_path": "v7/results/20250416_144418/backtest_results_v7_20250416_144418.png",
"report_save_path": "v7/results/20250416_144418/backtest_performance_report_v7_20250416_144418.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_144645",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_144645",
"results_plot_path": "v7/results/20250416_144645/backtest_results_v7_20250416_144645.png",
"report_save_path": "v7/results/20250416_144645/backtest_performance_report_v7_20250416_144645.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_144757",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_144757",
"results_plot_path": "v7/results/20250416_144757/backtest_results_v7_20250416_144757.png",
"report_save_path": "v7/results/20250416_144757/backtest_performance_report_v7_20250416_144757.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_144847",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_144847",
"results_plot_path": "v7/results/20250416_144847/backtest_results_v7_20250416_144847.png",
"report_save_path": "v7/results/20250416_144847/backtest_performance_report_v7_20250416_144847.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_145035",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_145035",
"results_plot_path": "v7/results/20250416_145035/backtest_results_v7_20250416_145035.png",
"report_save_path": "v7/results/20250416_145035/backtest_performance_report_v7_20250416_145035.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 14:54:21.018426
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,839.98
* **Total return:** -1.60%
* **Annualized return:** -98.72%
* **Sharpe ratio (annualized):** -11.7108
* **Sortino ratio (annualized):** -17.6542
* **Volatility (annualized):** 36.67%
* **Maximum drawdown:** 3.81%
* **Total trades:** 1622
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.2889
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3861
* **Uncertainty-Position Size correlation:** 0.9980
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 388 KiB

View File

@ -1,49 +0,0 @@
{
"run_id": "20250416_145128",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_145128",
"results_plot_path": "v7/results/20250416_145128/backtest_results_v7_20250416_145128.png",
"report_save_path": "v7/results/20250416_145128/backtest_performance_report_v7_20250416_145128.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_150616",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_150616",
"results_plot_path": "v7/results/20250416_150616/backtest_results_v7_20250416_150616.png",
"report_save_path": "v7/results/20250416_150616/backtest_performance_report_v7_20250416_150616.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 100000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:09:06.744482
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,811.94
* **Total return:** -1.88%
* **Annualized return:** -99.41%
* **Sharpe ratio (annualized):** -7.9546
* **Sortino ratio (annualized):** -11.8533
* **Volatility (annualized):** 62.11%
* **Maximum drawdown:** 6.00%
* **Total trades:** 1756
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.5121
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3196
* **Uncertainty-Position Size correlation:** 0.9811
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 384 KiB

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_150829",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_150829",
"results_plot_path": "v7/results/20250416_150829/backtest_results_v7_20250416_150829.png",
"report_save_path": "v7/results/20250416_150829/backtest_performance_report_v7_20250416_150829.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 100,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:11:02.339105
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,946.65
* **Total return:** -0.53%
* **Annualized return:** -76.46%
* **Sharpe ratio (annualized):** -11.2012
* **Sortino ratio (annualized):** -17.0343
* **Volatility (annualized):** 12.84%
* **Maximum drawdown:** 1.32%
* **Total trades:** 1128
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.1015
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.4118
* **Uncertainty-Position Size correlation:** 1.0000
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 KiB

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_150924",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_150924",
"results_plot_path": "v7/results/20250416_150924/backtest_results_v7_20250416_150924.png",
"report_save_path": "v7/results/20250416_150924/backtest_performance_report_v7_20250416_150924.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:15:17.184796
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,857.64
* **Total return:** -1.42%
* **Annualized return:** -97.93%
* **Sharpe ratio (annualized):** -7.9260
* **Sortino ratio (annualized):** -11.9087
* **Volatility (annualized):** 47.49%
* **Maximum drawdown:** 4.68%
* **Total trades:** 1702
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.3745
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3604
* **Uncertainty-Position Size correlation:** 0.9947
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 KiB

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_151322",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_151322",
"results_plot_path": "v7/results/20250416_151322/backtest_results_v7_20250416_151322.png",
"report_save_path": "v7/results/20250416_151322/backtest_performance_report_v7_20250416_151322.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.2,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:20:34.953163
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,863.85
* **Total return:** -1.36%
* **Annualized return:** -97.54%
* **Sharpe ratio (annualized):** -9.5883
* **Sortino ratio (annualized):** -14.1873
* **Volatility (annualized):** 37.91%
* **Maximum drawdown:** 3.68%
* **Total trades:** 1638
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.2993
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3821
* **Uncertainty-Position Size correlation:** 0.9978
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 KiB

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_151849",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_151849",
"results_plot_path": "v7/results/20250416_151849/backtest_results_v7_20250416_151849.png",
"report_save_path": "v7/results/20250416_151849/backtest_performance_report_v7_20250416_151849.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 1.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 KiB

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:26:31.107123
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,828.39
* **Total return:** -1.72%
* **Annualized return:** -99.07%
* **Sharpe ratio (annualized):** -7.6460
* **Sortino ratio (annualized):** -11.7314
* **Volatility (annualized):** 58.94%
* **Maximum drawdown:** 5.78%
* **Total trades:** 1737
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.4765
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3427
* **Uncertainty-Position Size correlation:** 0.9854
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 397 KiB

View File

@ -1,65 +0,0 @@
{
"run_id": "20250416_152415",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_152415",
"results_plot_path": "v7/results/20250416_152415/backtest_results_v7_20250416_152415.png",
"report_save_path": "v7/results/20250416_152415/backtest_performance_report_v7_20250416_152415.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.05,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 10.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:33:21.447644
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $8,969.88
* **Total return:** -10.30%
* **Annualized return:** -100.00%
* **Sharpe ratio (annualized):** -42.8779
* **Sortino ratio (annualized):** -49.6834
* **Volatility (annualized):** 68.01%
* **Maximum drawdown:** 10.92%
* **Total trades:** 1771
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.5605
* **Position sign accuracy vs return:** 49.07%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** -0.3021
* **Uncertainty-Position Size correlation:** 0.9760
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 KiB

View File

@ -1,68 +0,0 @@
{
"run_id": "20250416_153132",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_153132",
"results_plot_path": "v7/results/20250416_153132/backtest_results_v7_20250416_153132.png",
"report_save_path": "v7/results/20250416_153132/backtest_performance_report_v7_20250416_153132.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.05,
"sac_actor_lr": 0.0005,
"sac_critic_lr": 0.0008,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 10.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 1.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.5,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 15:45:06.190054
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,859.25
* **Total return:** -1.41%
* **Annualized return:** -97.83%
* **Sharpe ratio (annualized):** -45.8767
* **Sortino ratio (annualized):** -51.2465
* **Volatility (annualized):** 8.35%
* **Maximum drawdown:** 1.50%
* **Total trades:** 623
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.0662
* **Position sign accuracy vs return:** 49.07%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** -0.4139
* **Uncertainty-Position Size correlation:** 1.0000
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB

View File

@ -1,68 +0,0 @@
{
"run_id": "20250416_153846",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_153846",
"results_plot_path": "v7/results/20250416_153846/backtest_results_v7_20250416_153846.png",
"report_save_path": "v7/results/20250416_153846/backtest_performance_report_v7_20250416_153846.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 5000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 1.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

View File

@ -1,42 +0,0 @@
# GRU+SAC Backtesting Performance Report
Report generated on: 2025-04-16 16:07:30.131377
Data range: 2025-03-06 15:23:00+00:00 to 2025-03-07 23:57:00+00:00
Total duration: 1 days 08:34:00
## Strategy Performance Metrics
* **Initial capital:** $10,000.00
* **Final portfolio value:** $9,808.33
* **Total return:** -1.92%
* **Annualized return:** -99.47%
* **Sharpe ratio (annualized):** -8.4100
* **Sortino ratio (annualized):** -12.3689
* **Volatility (annualized):** 60.07%
* **Maximum drawdown:** 5.96%
* **Total trades:** 1745
## Buy and Hold Benchmark
* **Final value (B&H):** $9,658.75
* **Total return (B&H):** -3.41%
## Position & Prediction Analysis
* **Average absolute position size:** 0.4862
* **Position sign accuracy vs return:** 50.93%
* **Prediction sign accuracy vs return:** 48.92%
* **Prediction RMSE (on returns):** 0.004036
## Correlations
* **Prediction-Return correlation:** -0.0042
* **Prediction-Position correlation:** 0.3155
* **Uncertainty-Position Size correlation:** 0.9861
## Notes
* Transaction cost used: 0.0500% per position change value.
* GRU lookback period: 60 minutes.
* V6 features + return features used.
* Uncertainty estimated via MC Dropout standard deviation.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 KiB

View File

@ -1,68 +0,0 @@
{
"run_id": "20250416_154636",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_154636",
"results_plot_path": "v7/results/20250416_154636/backtest_results_v7_20250416_154636.png",
"report_save_path": "v7/results/20250416_154636/backtest_performance_report_v7_20250416_154636.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 2,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_alpha": 0.1,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 5000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_162528",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_162528",
"results_plot_path": "v7/results/20250416_162528/backtest_results_v7_20250416_162528.png",
"report_save_path": "v7/results/20250416_162528/backtest_performance_report_v7_20250416_162528.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_162624",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_162624",
"results_plot_path": "v7/results/20250416_162624/backtest_results_v7_20250416_162624.png",
"report_save_path": "v7/results/20250416_162624/backtest_performance_report_v7_20250416_162624.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_162718",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_162718",
"results_plot_path": "v7/results/20250416_162718/backtest_results_v7_20250416_162718.png",
"report_save_path": "v7/results/20250416_162718/backtest_performance_report_v7_20250416_162718.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_162921",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_162921",
"results_plot_path": "v7/results/20250416_162921/backtest_results_v7_20250416_162921.png",
"report_save_path": "v7/results/20250416_162921/backtest_performance_report_v7_20250416_162921.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_163030",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_163030",
"results_plot_path": "v7/results/20250416_163030/backtest_results_v7_20250416_163030.png",
"report_save_path": "v7/results/20250416_163030/backtest_performance_report_v7_20250416_163030.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_163440",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "v7/models/run_20250416_163440",
"results_plot_path": "v7/results/20250416_163440/backtest_results_v7_20250416_163440.png",
"report_save_path": "v7/results/20250416_163440/backtest_performance_report_v7_20250416_163440.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_164410",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "gru_sac_predictor/models/run_20250416_164410",
"results_plot_path": "gru_sac_predictor/results/20250416_164410/backtest_results_20250416_164410.png",
"report_save_path": "gru_sac_predictor/results/20250416_164410/backtest_performance_report_20250416_164410.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

View File

@ -1,67 +0,0 @@
{
"run_id": "20250416_164547",
"db_dir": "../downloaded_data",
"ticker": "BTC-USD",
"exchange": "COINBASE",
"start_date": "2025-03-01",
"end_date": "2025-03-10",
"interval": "1min",
"model_save_path": "gru_sac_predictor/models/run_20250416_164547",
"results_plot_path": "gru_sac_predictor/results/20250416_164547/backtest_results_20250416_164547.png",
"report_save_path": "gru_sac_predictor/results/20250416_164547/backtest_performance_report_20250416_164547.md",
"train_ratio": 0.6,
"validation_ratio": 0.2,
"gru_lookback": 60,
"gru_prediction_horizon": 1,
"gru_epochs": 20,
"gru_batch_size": 32,
"gru_patience": 10,
"gru_lr_factor": 0.5,
"gru_return_scale": 0.03,
"gru_model_load_run_id": "20250416_142744",
"sac_state_dim": 5,
"sac_hidden_size": 64,
"sac_gamma": 0.97,
"sac_tau": 0.02,
"sac_actor_lr": 0.0003,
"sac_critic_lr": 0.0005,
"sac_batch_size": 64,
"sac_buffer_max_size": 20000,
"sac_min_buffer_size": 1000,
"sac_update_interval": 1,
"sac_target_update_interval": 2,
"sac_gradient_clip": 1.0,
"sac_reward_scale": 2.0,
"sac_use_batch_norm": true,
"sac_use_residual": true,
"sac_model_dir": "models/simplified_sac",
"sac_epochs": 50,
"total_training_steps": 1000,
"experience_config": {
"initial_experiences": 3000,
"experiences_per_batch": 64,
"batch_generation_interval": 500,
"balance_market_regimes": false,
"recency_bias_strength": 0.5,
"high_uncertainty_quantile": 0.75,
"extreme_return_quantile": 0.1,
"min_uncertainty_ratio": 0.2,
"min_extreme_return_ratio": 0.1,
"use_parallel_generation": false,
"precompute_all_gru_outputs": true,
"buffer_update_strategy": "fifo",
"training_iterations_per_step": 1
},
"initial_capital": 10000.0,
"transaction_cost": 0.0005,
"opportunity_cost_penalty_factor": 0.0,
"high_return_threshold": 0.002,
"action_tolerance": 0.3,
"load_existing_system": true,
"train_gru_model": false,
"train_sac_agent": true,
"load_sac_agent": false,
"run_backtest": true,
"generate_plots": true,
"generate_report": true
}

Some files were not shown because too many files have changed in this diff Show More