Commit Graph
159 Commits
Author SHA1 Message Date
Luke Mosoti d656d1b672 feat: Enhance CPCV metrics handling and reporting across multiple modules 2026-05-16 22:58:04 +03:00
Luke Mosoti 2af8c2fb0f Refactor guardian and TCN maintenance logic
- Removed TCN staleness checks and auto-retraining from guardian.py.
- Eliminated TCNMaintenanceScheduler and related functions from tcn_maintenance.py.
- Updated mt5_trader.py to remove TCN maintenance checks.
- Adjusted signal_engine.py to remove TCN multiplier logic.
- Cleaned up processor.py by removing optional LSTM context features.
- Modified validation warnings to suggest appropriate periods based on trade counts.
- Updated visualizer.py to streamline signal computation and improve clarity in equity curve plotting.
2026-05-16 22:07:50 +03:00
Luke Mosoti a0758dfe62 feat: Implement two-stage optimization process with XGB exploration
- Added `--stage` argument to `cmd_optimize` for selecting between Stage-1 (XGB exploration) and Stage-2 (CPCV optimization).
- Introduced `run_optimization_stage1` for fast single hold-out XGB trials, significantly improving optimization speed.
- Updated `run_optimization` to support warm-starting from Stage-1 best parameters.
- Enhanced logging with dedicated score logging for trial monitoring.
- Adjusted hyperparameter ranges for XGBoost to allow deeper trees and finer splits.
- Added synthetic VIX feature computation to the feature application process.
- Persisted best parameters from Stage-1 to JSON for future use in Stage-2.
- Updated documentation for new optimization stages and usage instructions.
2026-05-16 20:25:18 +03:00
Luke Mosoti 09adea905e Refactor backtester logic to introduce cooldown mechanism and simplify exit checks
- Added a cooldown period to prevent immediate re-entries after a trade, reducing churn in rapidly oscillating regimes.
- Simplified exit conditions by removing ATR trailing, partial close, and profit guard during optimization.
- Adjusted minimum confirmation bars for H1 to enhance stability before entries and exits.
- Lowered the floor for reg_lambda in optimizer to allow for better HMM state signals.
- Implemented a regime oscillation guard in the CPCV execution to skip paths with excessive transitions, mitigating potential drawdowns.
2026-05-16 12:05:36 +03:00
Luke Mosoti 42c1cb7f7f fix: Correct raw ATR calculation to prevent negative SL/TP distances and improve trade execution logic 2026-05-16 11:21:55 +03:00
Luke Mosoti 329dd0dad5 feat: Update target variable calculation to use future returns over a rolling horizon 2026-05-16 10:32:23 +03:00
Luke Mosoti 975899abd4 feat: Update optimizer to version 3.7 and refactor WFO to CPCV
- Bump optimizer version from 3.6 to 3.7.
- Refactor make_objective function to use Combinatorial Purged Cross-Validation (CPCV) instead of WFO.
- Implement execute_cpcv function for CPCV analysis with strict HMM and scaler fitting.
- Update run_wfa to utilize CPCV and maintain backward compatibility with WFO key aliases.
- Remove deprecated WFO-related code and metrics, replacing them with CPCV equivalents.
- Enhance logging for CPCV trials and results.
2026-05-15 07:47:35 +03:00
Luke Mosoti d0db33062d Refactor XGBoost training logic and update optimizer parameters
- Removed the early stopping guard fold in the XGBoost training process to enhance model generalization.
- Updated optimizer version to 3.6 and adjusted search space for regularization parameters (reg_alpha and reg_lambda) to prevent overfitting.
- Implemented a purged inner cross-validation split to avoid leakage between training and validation sets.
- Adjusted scoring penalties for WFE to better reflect model performance discrepancies.
2026-05-15 01:24:34 +03:00
Luke Mosoti 6fce4177f3 Refactor code structure for improved readability and maintainability 2026-05-15 00:36:34 +03:00
Luke Mosoti 8057d7ff30 Enhance XGBoost training and optimizer configurations
- Introduced adaptive min_child_weight cap in `engine_xgb.py` to prevent zero-split models for small training sets.
- Implemented early stopping with a guard fold in `train_xgb` function for better model validation.
- Updated optimizer version to 3.5 and expanded search space parameters in `optimizer.py`, including adjustments to `reg_lambda`, `min_child_weight`, and added `subsample`, `colsample_bytree`, and `gamma` parameters.
- Improved WFO score calculation to only consider valid windows, addressing overfitting detection.
2026-05-15 00:33:59 +03:00
Luke Mosoti 8a7a84480f feat(optimizer): Update WFO parameters and improve window selection logic
- Bump optimizer version from 3.1 to 3.3.
- Adjusted H1 step size to 4320 bars for better independent test periods.
- Introduced MAX_WFO_WINDOWS to limit the number of evaluated windows per trial.
- Refactored window selection logic to pre-compute valid start positions and skip oldest windows if exceeding the maximum.
- Modified scoring parameters: reduced reg_lambda max from 10.0 to 5.0 and min_child_weight from 100 to 40.
- Enhanced WFE calculation to avoid misinterpretation of consistently negative models.
2026-05-14 21:58:52 +03:00
Luke Mosoti eed11f9692 Enhance model training and evaluation processes
- Updated the state remapping logic in `engine_hmm.py` to ensure consistent labeling of states based on volatility and returns, addressing issues with out-of-sample regime inconsistency.
- Modified `train_xgb` in `engine_xgb.py` to handle cases where the dataset may not have a holdout set, ensuring robust model training and evaluation.
- Introduced annualization in the scoring function within `optimizer.py` to improve the Calmar ratio calculation, making it more comparable across different timeframes.
- Added penalties for high cross-window Sharpe variance and negative WFE ratios in the objective function to discourage overfitting and promote model consistency.
- Enhanced logging to provide clearer insights during the WFO process, including warnings for skipped windows and potential issues with model training.
2026-05-14 21:06:18 +03:00
Luke Mosoti 57f13084e0 Update study_headway_cent.db with new data revisions 2026-05-14 13:33:32 +03:00
Luke Mosoti 3f2d7b5cde Refactor code structure for improved readability and maintainability 2026-05-14 13:18:44 +03:00
Luke Mosoti 10483cef72 Refactor code structure for improved readability and maintainability 2026-05-14 13:15:41 +03:00
Luke Mosoti 91194835cc Update README: Remove Changelog section, enhance feature descriptions, and clarify external asset roles 2026-05-14 11:56:17 +03:00
Luke Mosoti 9f8d61bdc0 Fix notebook merge conflicts, update ensemble API, and update README
- Resolve 5 committed git merge conflict markers in GoldRegimeX_Explorer.ipynb
  that rendered it invalid JSON and unexecutable in Jupyter
- Conflict resolution: keep wfo_mode_w dropdown, reg_lambda5_w / min_child_weight5_w
  sliders, Run WFO Score Comparison button, and Section 6 CV Path Inspector from
  copilot branch; keep ensemble API imports (load_xgb_ensemble, get_predictions_ensemble)
  from HEAD
- Fix notebook Sections 1 and 5 to use load_xgb_ensemble / train_xgb_ensemble /
  get_predictions_ensemble instead of old single-model API; ensures equity curves
  and WFO scores match production vol-bucketed ensemble
- Update README changelog with merge conflict resolution and ensemble API fix entry
2026-05-14 10:49:45 +03:00
Luke Mosoti ca2c17286d Refactor optimization scoring and WFO parameters
- Updated MIN_OOS_TRADES_HARD for M15 from 30 to 60.
- Introduced WFO_PARAMS_FAST for quicker intraday regime detection.
- Adjusted WFO_TRIALS and added WFO_TRIALS_FAST to accommodate wider search space.
- Revised scoring formula in compute_cpcv_score to improve accuracy and range.
- Enhanced _run_wfo to support different WFO modes and adjusted CV folds based on TF.
- Aligned feature preparation and state alignment for consistency in backtesting.
- Updated make_objective to include new parameters and improved tree depth and learning rate settings.
- Changed pruner strategy based on TF in run_optimization for better trial management.
2026-05-14 10:25:59 +03:00
Luke Mosoti e741208111 Refactor code structure for improved readability and maintainability 2026-05-14 10:23:09 +03:00
Luke MosotiandGitHub 2ca578efc7 Merge pull request #1 from lucasmos/copilot/fix-oos-scaling-issue
Fix WFO data leakage/misalignment bugs, revise scoring formula, expand Optuna search space
2026-05-14 10:22:10 +03:00
de59b2d9b7 Merge remote-tracking branch 'origin/main' into copilot/fix-oos-scaling-issue
# Conflicts:
#	notebooks/GoldRegimeX_Explorer.ipynb
#	src/optimizer.py

Co-authored-by: lucasmos <160877590+lucasmos@users.noreply.github.com>
2026-05-14 07:19:32 +00:00
7132851128 Rewrite README.md to document all WFO bug fixes, scoring formula changes, Optuna improvements, and new notebook sections
Agent-Logs-Url: https://github.com/lucasmos/GoldRegime_X/sessions/975bbd90-d267-4b2a-af8a-1d4eb67cd2b7

Co-authored-by: lucasmos <160877590+lucasmos@users.noreply.github.com>
2026-05-14 07:13:18 +00:00
342101f4e5 Address code review: improve comments for M5 params and update docstring for 0.20 variance penalty
Agent-Logs-Url: https://github.com/lucasmos/GoldRegime_X/sessions/4537788d-1709-47c0-8a49-0c7fa9086451

Co-authored-by: lucasmos <160877590+lucasmos@users.noreply.github.com>
2026-05-11 12:53:40 +00:00
87af6a51df Fix WFO bugs, improve scoring formula, add WFO fast mode, update Optuna params and notebook
Agent-Logs-Url: https://github.com/lucasmos/GoldRegime_X/sessions/4537788d-1709-47c0-8a49-0c7fa9086451

Co-authored-by: lucasmos <160877590+lucasmos@users.noreply.github.com>
2026-05-11 12:51:34 +00:00
Luke Mosoti 335fcc7b3f Fix out-of-sample states alignment in backtesting
Updated the out-of-sample (OOS) backtesting process to ensure that the states used are aligned with the OOS data frame index. This change addresses potential mismatches by applying a mask to the states based on the aligned index, improving the accuracy of the backtest results.
2026-05-11 15:43:42 +03:00
copilot-swe-agent[bot]andGitHub d32f9da3d7 Initial plan 2026-05-11 12:41:52 +00:00
Luke Mosoti b2724a4115 Add interactive research notebook for GoldRegime X and update study_headway_cent.db 2026-05-11 14:14:21 +03:00
Luke Mosoti 600edff829 feat: Remove US500 and USDJPY from external asset features and streamline data processing in pipeline 2026-05-11 09:18:27 +03:00
Luke Mosoti 55d9a869b5 feat: Refine data processing in pipeline by selectively dropping NaN rows and backfilling external asset columns 2026-05-11 08:40:10 +03:00
Luke Mosoti 847fb89308 feat: Enhance map_asset_to_bars function to support raw return option and improve data handling 2026-05-10 23:50:55 +03:00
Luke Mosoti 091348c569 feat: Implement Rolling Walk-Forward Optimization (WFO) and enhance asset feature processing
- Added WFO parameters and trial configurations for H1, M15, and M5 timeframes.
- Introduced _run_wfo function to evaluate hyperparameters across non-overlapping OOS windows.
- Updated make_objective to utilize WFO instead of CPCV for scoring.
- Enhanced asset feature processing in processor.py to include additional external assets (XAGUSD, XTIUSD, US500, USDJPY) and their log-return calculations.
- Implemented a generic load_asset_data function to streamline loading and processing of asset data.
- Added compute_synth_vix function to calculate a synthetic VIX proxy from OHLC data.
- Improved handling of missing data and logging for asset features.
2026-05-10 22:40:40 +03:00
Luke Mosoti c582af6041 feat: Implement Combinatorial Purged Cross-Validation (CPCV) for enhanced model evaluation and scoring 2026-05-10 16:49:21 +03:00
Luke Mosoti 966af3d06e feat: Improve UTF-8 handling in output and refine CPCV scoring thresholds for better performance 2026-05-10 15:53:16 +03:00
Luke Mosoti 97dc0b324a Enhance backtesting and optimization with Combinatorial Purged Cross-Validation (CPCV)
- Introduced CPCV for train/test splitting, allowing for more robust evaluation across multiple market regimes.
- Updated backtester to support test masks, ensuring trades are only executed during test periods.
- Refactored optimizer to compute scores using CPCV, improving trial efficiency and accuracy.
- Adjusted signal engine logic to incorporate directional probabilities for trade entries based on XGBoost predictions.
- Improved overall code structure and readability, ensuring better maintainability and performance.
2026-05-09 20:55:10 +03:00
Luke Mosoti 2d104d0895 feat: Enhance signal engine with exit confirmation logic and improve performance metrics calculation 2026-05-09 20:00:05 +03:00
Luke Mosoti 583aa11c75 fix: Update trade metrics in compute_purged_ts_score for consistency 2026-05-09 10:00:49 +03:00
Luke Mosoti f81a2ddcf8 feat: Add live command for MT5 account connection and signal execution loop
refactor: Remove legacy signal computation functions from backtester
delete: Remove unused TCN model files and metadata
2026-05-09 09:06:27 +03:00
Luke Mosoti 77caf6db0a Refactor signal evaluation logic: remove SignalEvaluator and introduce SignalEngine
- Deleted `signal_evaluator.py`, which contained the previous Z-Score and RCEV evaluation logic.
- Added `signal_engine.py`, implementing a new stateful signal engine for regime confirmation and trade management.
- The new engine evaluates entry and exit conditions based on regime stability, XGBoost confidence, and Bollinger Band positions.
- Introduced constants for minimum confirmation bars, entry probabilities, maximum hold bars, and profit erosion thresholds.
2026-05-09 08:52:33 +03:00
Luke Mosoti a6f72863ef feat: Implement Regime-Conditional Expected Value (RCEV) scoring system
- Introduced RCEVScorer class for calculating expected dollar profit based on historical trade outcomes and market conditions.
- Replaced Z-Score signal gating with RCEV scoring in SignalEvaluator for live evaluations.
- Added new configuration for RCEV thresholds and tiered floors based on timeframes.
- Enhanced MT5 trader logic to utilize RCEV scoring for trade decision-making, including regime-aware take-profit and stop-loss calculations.
- Updated ATR trailing stop logic to incorporate new RCEV parameters and configurations.
- Maintained backward compatibility with existing Z-Score logic for scenarios without RCEV calibration.
2026-04-29 09:17:28 +03:00
Luke Mosoti e2b05755a2 feat: Update Z cutoff values and improve M5 chop state calibration in signal evaluator 2026-04-28 10:15:22 +03:00
Luke Mosoti 16560d2541 Add feature scaler and metadata for M15_headway_cent model
- Created a new StandardScaler object for feature scaling, saved as tcn_feature_scaler.pkl.
- Added metadata in JSON format for the M15_headway_cent model, including sequence length, number of features, number of states, temperature, and training timestamp.
2026-04-28 08:33:50 +03:00
Luke Mosoti d75f728255 feat: Enhance TCN training with TF-specific sequence lengths and forward-window targets 2026-04-27 22:33:29 +03:00
Luke Mosoti 8754b7f9d6 Remove LSTM model files and metadata for H1 and M15 headway cent models
- Deleted ensemble metadata, feature scalers, and model metadata for H1 headway cent models.
- Removed LSTM regime classifier files for H1 headway cent models.
- Deleted corresponding files for model_0, model_1, and model_2 in both H1 and M15 headway cent directories.
- Cleaned up unnecessary files to streamline the model directory structure.
2026-04-27 22:28:26 +03:00
Luke Mosoti 02498fb42e feat: Implement TCN for dynamic Z-Score adjustment and replace LSTM ensemble
- Introduced `engine_tcn.py` for Temporal Convolutional Network (TCN) model to score confidence based on recent market data.
- Added `data_updater.py` for automatic weekly data updates from MT5, ensuring fresh data for TCN.
- Created `tcn_maintenance.py` for automatic TCN model maintenance, including staleness checks and background retraining.
- Updated `mt5_trader.py` to integrate TCN confidence scoring, replacing the previous LSTM ensemble logic.
- Enhanced logging and error handling throughout the new modules for better traceability.
2026-04-27 22:13:50 +03:00
Luke Mosoti 9e90919dfb fix: update training timestamps and improve error handling in LSTM predictions 2026-04-27 08:58:42 +03:00
Luke Mosoti f03ff830d7 Refactor code structure for improved readability and maintainability 2026-04-27 06:45:57 +03:00
Luke Mosoti b6717af55e fix: adjust minimum out-of-sample trades and Z cutoff values for improved model performance 2026-04-26 12:22:00 +03:00
Luke Mosoti 94f6e6ae9b docs: comprehensive README rewrite covering all V5 features
- Full workflow from raw data to live trading (Phase 0–7)
- LSTM ensemble, temperature calibration, fine-tuning, staleness/auto-retrain
- Sensitivity analysis and tiered Z-Score trading modes
- Updated command reference (all 16 modes + 22 CLI options)
- Signal logic with exact TF Z-Score cutoffs
- Guardian LSTM auto-retrain documentation
- Model files layout and troubleshooting guide
2026-04-25 14:23:16 +03:00
Luke Mosoti 99fc1cb55d feat: enhance LSTM training with ensemble support and fine-tuning capabilities 2026-04-25 14:14:36 +03:00
Luke Mosoti 62d93fe9f7 feat: enhance LSTM health checks and handle collapsed model scenarios 2026-04-25 00:27:18 +03:00