JonusNattapong commited on
Commit
37a8fd4
·
verified ·
1 Parent(s): fd41815

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +420 -0
README.md ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ library_name: sklearn
5
+ tags:
6
+ - trading
7
+ - finance
8
+ - gold
9
+ - xauusd
10
+ - forex
11
+ - algorithmic-trading
12
+ - smart-money-concepts
13
+ - smc
14
+ - xgboost
15
+ - machine-learning
16
+ - backtesting
17
+ - technical-analysis
18
+ - multi-timeframe
19
+ - intraday-trading
20
+ - high-frequency-trading
21
+ datasets:
22
+ - yahoo-finance-gc-f
23
+ metrics:
24
+ - accuracy
25
+ - precision
26
+ - recall
27
+ - f1
28
+ model-index:
29
+ - name: xauusd-trading-ai-smc-daily
30
+ results:
31
+ - task:
32
+ type: binary-classification
33
+ name: Daily Price Direction Prediction
34
+ dataset:
35
+ type: yahoo-finance-gc-f
36
+ name: Gold Futures (GC=F)
37
+ metrics:
38
+ - type: accuracy
39
+ value: 80.3
40
+ name: Accuracy
41
+ - type: precision
42
+ value: 71
43
+ name: Precision (Class 1)
44
+ - type: recall
45
+ value: 81
46
+ name: Recall (Class 1)
47
+ - type: f1
48
+ value: 76
49
+ name: F1-Score
50
+ - name: xauusd-trading-ai-smc-15m
51
+ results:
52
+ - task:
53
+ type: binary-classification
54
+ name: 15-Minute Price Direction Prediction
55
+ dataset:
56
+ type: yahoo-finance-gc-f
57
+ name: Gold Futures (GC=F)
58
+ metrics:
59
+ - type: accuracy
60
+ value: 77.0
61
+ name: Accuracy
62
+ - type: precision
63
+ value: 76
64
+ name: Precision (Class 1)
65
+ - type: recall
66
+ value: 77
67
+ name: Recall (Class 1)
68
+ - type: f1
69
+ value: 76
70
+ name: F1-Score
71
+ ---
72
+ ---
73
+
74
+ # XAUUSD Multi-Timeframe Trading AI Model
75
+
76
+ ## Files Included
77
+
78
+ ### Core Models
79
+ - `trading_model.pkl` - Original daily timeframe XGBoost model (85.4% win rate)
80
+ - `trading_model_15m.pkl` - 15-minute intraday model (77% validation accuracy)
81
+ - `trading_model_1m.pkl` - 1-minute intraday model (partially trained)
82
+ - `trading_model_30m.pkl` - 30-minute intraday model (ready for training)
83
+
84
+ ### Documentation
85
+ - `README.md` - This comprehensive model card
86
+ - `XAUUSD_Trading_AI_Paper.md` - **Research paper with academic structure, literature review, and methodology**
87
+ - `XAUUSD_Trading_AI_Paper.docx` - **Word document version (professional format)**
88
+ - `XAUUSD_Trading_AI_Paper.html` - **HTML web version (styled and readable)**
89
+ - `XAUUSD_Trading_AI_Paper.tex` - **LaTeX source (for academic publishing)**
90
+ - `XAUUSD_Trading_AI_Technical_Whitepaper.md` - **Technical whitepaper with mathematical formulations and implementation details**
91
+ - `XAUUSD_Trading_AI_Technical_Whitepaper.docx` - **Word document version (professional format)**
92
+ - `XAUUSD_Trading_AI_Technical_Whitepaper.html` - **HTML web version (styled and readable)**
93
+ - `XAUUSD_Trading_AI_Technical_Whitepaper.tex` - **LaTeX source (for academic publishing)**
94
+
95
+ ### Performance & Analysis
96
+ - `backtest_report.csv` - Daily model yearly backtesting performance results
97
+ - `backtest_multi_timeframe_results.csv` - Intraday model backtesting results
98
+ - `feature_importance_15m.csv` - 15-minute model feature importance analysis
99
+
100
+ ### Scripts & Tools
101
+ - `train_multi_timeframe.py` - Multi-timeframe model training script
102
+ - `backtest_multi_timeframe.py` - Intraday model backtesting framework
103
+ - `multi_timeframe_summary.py` - Comprehensive performance analysis tool
104
+ - `fetch_data.py` - Enhanced data acquisition for multiple timeframes
105
+
106
+ ### Dataset Files
107
+ - **Daily Data**: `daily_data.csv`, `processed_daily_data.csv`, `smc_features_dataset.csv`, `X_features.csv`, `y_target.csv`
108
+ - **Intraday Data**: `1m_data.csv` (5,204 samples), `15m_data.csv` (3,814 samples), `30m_data.csv` (1,910 samples)
109
+
110
+ ## Recent Enhancements (v2.0)
111
+
112
+ ### Visual Documentation
113
+ - **Dataset Flow Diagram**: Complete data processing pipeline from raw Yahoo Finance data to model training
114
+ - **Model Architecture Diagram**: XGBoost ensemble structure with decision flow visualization
115
+ - **Buy/Sell Workflow Diagram**: End-to-end trading execution process with risk management
116
+
117
+ ### Advanced Formulas & Techniques
118
+ - **Position Sizing Formula**: Risk-adjusted position calculation with Kelly Criterion adaptation
119
+ - **Risk Metrics**: Sharpe Ratio, Sortino Ratio, Calmar Ratio, and Maximum Drawdown calculations
120
+ - **SMC Techniques**: Advanced Order Block detection with volume profile analysis
121
+ - **Dynamic Thresholds**: Market volatility-based prediction threshold adjustment
122
+ - **Ensemble Signals**: Multi-source signal confirmation (ML + Technical + SMC)
123
+
124
+ ### Performance Analytics
125
+ - **Monthly Performance Heatmap**: Visual representation of returns across all test years
126
+ - **Risk-Return Scatter Plot**: Performance comparison across different risk levels
127
+ - **Market Regime Analysis**: Performance breakdown by trending vs sideways markets
128
+
129
+ ### Documentation Updates
130
+ - **Enhanced Technical Whitepaper**: Added comprehensive visual diagrams and mathematical formulations
131
+ - **Enhanced Research Paper**: Added Mermaid diagrams, advanced algorithms, and detailed performance analysis
132
+ - **Professional Exports**: Both documents now available in HTML, Word, and LaTeX formats
133
+
134
+ ## Multi-Timeframe Trading System (Latest Addition)
135
+
136
+ ### Overview
137
+ The system has been extended to support intraday trading across multiple timeframes, enabling higher-frequency trading strategies while maintaining the proven SMC + technical indicator approach.
138
+
139
+ ### Supported Timeframes
140
+ - **1-minute (1m)**: Ultra-short-term scalping opportunities
141
+ - **15-minute (15m)**: Short-term swing trading
142
+ - **30-minute (30m)**: Medium-term position trading
143
+ - **Daily (1d)**: Original baseline model (85.4% win rate)
144
+
145
+ ### Data Acquisition
146
+ - **Source**: Yahoo Finance API with enhanced intraday data fetching
147
+ - **Limitations**: Historical intraday data restricted (recent periods only)
148
+ - **Current Datasets**:
149
+ - 1m: 5,204 samples (7 days of recent data)
150
+ - 15m: 3,814 samples (60 days of recent data)
151
+ - 30m: 1,910 samples (60 days of recent data)
152
+
153
+ ### Model Architecture
154
+ - **Base Algorithm**: XGBoost Classifier (same as daily model)
155
+ - **Features**: 23 features (technical indicators + SMC elements)
156
+ - **Training**: Grid search hyperparameter optimization
157
+ - **Validation**: 80/20 train/test split with stratification
158
+
159
+ ### Training Results
160
+ - **15m Model**: Successfully trained with 77% validation accuracy
161
+ - **Feature Importance**: Technical indicators dominant (SMA_50, EMA_12, BB_lower)
162
+ - **Training Status**: 1m model partially trained, 30m model interrupted (available for completion)
163
+
164
+ ### Backtesting Performance
165
+ - **Framework**: Backtrader with realistic commission modeling
166
+ - **Risk Management**: Fixed stake sizing ($1,000 per trade)
167
+ - **15m Results**: -0.83% return with 1 trade (conservative strategy)
168
+ - **Analysis**: Models show conservative behavior to avoid overtrading
169
+
170
+ ### Key Insights
171
+ - ✅ Successfully scaled daily model architecture to intraday timeframes
172
+ - ✅ Technical indicators remain most important across all timeframes
173
+ - ✅ Conservative prediction thresholds prevent excessive trading
174
+ - ⚠️ Limited historical data affects backtesting statistical significance
175
+ - ⚠️ Yahoo Finance API constraints limit comprehensive validation
176
+
177
+ ### Files Added
178
+ - `train_multi_timeframe.py` - Multi-timeframe model training script
179
+ - `backtest_multi_timeframe.py` - Intraday model backtesting framework
180
+ - `multi_timeframe_summary.py` - Comprehensive performance analysis
181
+ - `trading_model_15m.pkl` - Trained 15-minute model
182
+ - `feature_importance_15m.csv` - Feature importance analysis
183
+ - `backtest_multi_timeframe_results.csv` - Backtesting performance data
184
+
185
+ ### Next Steps
186
+ 1. Complete 30m model training
187
+ 2. Implement walk-forward optimization
188
+ 3. Add extended historical data sources
189
+ 4. Deploy best performing intraday model
190
+ 5. Compare intraday vs daily performance
191
+
192
+ ## Model Description
193
+
194
+ This is an AI-powered trading model for XAUUSD (Gold vs US Dollar) futures, trained using Smart Money Concepts (SMC) strategy elements. The model uses machine learning to predict 5-day ahead price movements and generate trading signals with high win rates.
195
+
196
+ ### Key Features
197
+ - **Asset**: XAUUSD (Gold Futures)
198
+ - **Strategy**: Smart Money Concepts (SMC) with technical indicators
199
+ - **Prediction Horizon**: 5-day ahead price direction
200
+ - **Model Type**: XGBoost Classifier
201
+
202
+ ## Romeo (V5) — Ensemble model
203
+
204
+ Romeo (codename V5) is the latest ensemble model combining tree-based learners (XGBoost / LightGBM) and an optional Keras head. The artifacts live in `models_romeo/` and include a canonical feature list used by the backtester to align unseen data.
205
+
206
+ Artifacts
207
+ - `models_romeo/trading_model_romeo_daily.pkl` — ensemble artifact (joblib) with `models`, `weights`, and `features` keys.
208
+ - `models_romeo/romeo_keras_daily.keras` — optional Keras model file when included in training.
209
+ - `models_romeo/MODEL_CARD.md` — this model's card with evaluation and transparency notes.
210
+
211
+ Evaluation (selected run on unseen daily data)
212
+ - Initial capital: 100
213
+ - Final capital: 484.8199
214
+ - CAGR: 0.0444
215
+ - Annual volatility: 0.4118
216
+ - Sharpe: 0.3119
217
+ - Max Drawdown: -47.66%
218
+ - Total trades: 3610
219
+ - Win rate: 49.47%
220
+
221
+ Uploading to Hugging Face
222
+ -------------------------
223
+ There is a helper script to upload the model artifacts to Hugging Face Hub:
224
+
225
+ 1. Install dependencies:
226
+ ```bash
227
+ pip install huggingface_hub
228
+ ```
229
+
230
+ 2. Set your HF token in the environment (Windows cmd.exe):
231
+ ```cmd
232
+ set HF_TOKEN=hf_YourTokenHere
233
+ ```
234
+
235
+ 3. Upload:
236
+ ```cmd
237
+ python v5\upload_model_v5_to_hf.py --repo-name your-username/romeo-v5 --model-dir models_romeo
238
+ ```
239
+
240
+ The script will create the repo (if it doesn't exist) and upload all files from `models_romeo/`.
241
+
242
+ Usage example
243
+ -------------
244
+ Load the artifact and run predictions:
245
+
246
+ ```python
247
+ import joblib
248
+ artifact = joblib.load('models_romeo/trading_model_romeo_daily.pkl')
249
+ features = artifact['features']
250
+ # prepare X matching features
251
+ # model usage depends on artifact['models'] layout; check MODEL_CARD.md for details
252
+ ```
253
+
254
+ Notes & Next Steps
255
+ ------------------
256
+ - Position sizing is simplified in the backtester; consider implementing fixed-risk sizing before live use.
257
+ - Consider re-running the robustness scan using the M2M metric as primary evaluation (recommended).
258
+
259
+ - **Accuracy**: 80.3% on test data
260
+ - **Win Rate**: 85.4% in backtesting
261
+
262
+ ## Intended Use
263
+
264
+ This model is designed for:
265
+ - Educational purposes in algorithmic trading
266
+ - Research on SMC strategies
267
+ - Backtesting trading strategies
268
+ - Understanding ML applications in financial markets
269
+
270
+ **⚠️ Warning**: This is not financial advice. Trading involves risk of loss. Use at your own discretion.
271
+
272
+ ## Training Data
273
+
274
+ - **Source**: Yahoo Finance (GC=F - Gold Futures)
275
+ - **Period**: 2000-2020 (excluding recent months for efficiency)
276
+ - **Features**: 23 features including:
277
+ - Price data (Open, High, Low, Close, Volume)
278
+ - Technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands)
279
+ - SMC features (Fair Value Gaps, Order Blocks, Recovery patterns)
280
+ - Lag features (Close prices from previous days)
281
+ - **Target**: Binary classification (1 if price rises in 5 days, 0 otherwise)
282
+ - **Dataset Size**: 8,816 samples
283
+ - **Class Distribution**: 54% down, 46% up (balanced with scale_pos_weight)
284
+
285
+ ## Performance Metrics
286
+
287
+ ### Model Performance
288
+ - **Accuracy**: 80.3%
289
+ - **Precision (Class 1)**: 71%
290
+ - **Recall (Class 1)**: 81%
291
+ - **F1-Score**: 76%
292
+
293
+ ### Backtesting Results (2015-2020)
294
+ - **Overall Win Rate**: 85.4%
295
+ - **Total Return**: 18.2%
296
+ - **Sharpe Ratio**: 1.41
297
+ - **Yearly Win Rates**:
298
+ - 2015: 62.5%
299
+ - 2016: 100.0%
300
+ - 2017: 100.0%
301
+ - 2018: 72.7%
302
+ - 2019: 76.9%
303
+ - 2020: 94.1%
304
+
305
+ ## Limitations
306
+
307
+ - Trained on historical data only (2000-2020)
308
+ - May not perform well in unprecedented market conditions
309
+ - Requires proper risk management
310
+ - No consideration of transaction costs, slippage, or market impact
311
+ - Model predictions are probabilistic, not guaranteed
312
+
313
+ ## Usage
314
+
315
+ ### Prerequisites
316
+ ```python
317
+ pip install joblib scikit-learn pandas numpy
318
+ ```
319
+
320
+ ### Loading the Model
321
+ ```python
322
+ import joblib
323
+ import pandas as pd
324
+ from sklearn.preprocessing import StandardScaler
325
+
326
+ # Load model
327
+ model = joblib.load('trading_model.pkl')
328
+
329
+ # Load scalers (you need to recreate or save them)
330
+ # ... preprocessing code ...
331
+
332
+ # Prepare features
333
+ features = prepare_features(your_data)
334
+ prediction = model.predict(features)
335
+ probability = model.predict_proba(features)
336
+ ```
337
+
338
+ ### Features Required
339
+ The model expects 23 features in this order:
340
+ 1. Close
341
+ 2. High
342
+ 3. Low
343
+ 4. Open
344
+ 5. Volume
345
+ 6. SMA_20
346
+ 7. SMA_50
347
+ 8. EMA_12
348
+ 9. EMA_26
349
+ 10. RSI
350
+ 11. MACD
351
+ 12. MACD_signal
352
+ 13. MACD_hist
353
+ 14. BB_upper
354
+ 15. BB_middle
355
+ 16. BB_lower
356
+ 17. FVG_Size
357
+ 18. FVG_Type_Encoded
358
+ 19. OB_Type_Encoded
359
+ 20. Recovery_Type_Encoded
360
+ 21. Close_lag1
361
+ 22. Close_lag2
362
+ 23. Close_lag3
363
+
364
+ ## Training Details
365
+
366
+ - **Algorithm**: XGBoost Classifier
367
+ - **Hyperparameters**:
368
+ - n_estimators: 200
369
+ - max_depth: 7
370
+ - learning_rate: 0.2
371
+ - scale_pos_weight: 1.17 (for class balancing)
372
+ - **Cross-validation**: 3-fold
373
+ - **Optimization**: Grid search on hyperparameters
374
+
375
+ ## SMC Strategy Elements
376
+
377
+ The model incorporates Smart Money Concepts:
378
+ - **Fair Value Gaps (FVG)**: Price imbalances between candles
379
+ - **Order Blocks (OB)**: Areas of significant buying/selling
380
+ - **Recovery Patterns**: Pullbacks in trending markets
381
+
382
+ ## Upload to Hugging Face
383
+
384
+ To share this model on Hugging Face:
385
+
386
+ 1. Create a Hugging Face account at https://huggingface.co/join
387
+ 2. Generate an access token at https://huggingface.co/settings/tokens with "Write" permissions
388
+ 3. Test your token: `python test_token.py YOUR_TOKEN`
389
+ 4. Upload: `python upload_to_hf.py YOUR_TOKEN`
390
+
391
+ The script will upload:
392
+ - `trading_model.pkl` - The trained XGBoost model
393
+ - `README.md` - This model card with metadata
394
+ - All dataset files (CSV format)
395
+
396
+ ## Citation
397
+
398
+ If you use this model in your research, please cite:
399
+
400
+ ```
401
+ @misc{xauusd-trading-ai,
402
+ title={XAUUSD Trading AI Model with SMC Strategy},
403
+ author={AI Trading System},
404
+ year={2025},
405
+ url={https://huggingface.co/JonusNattapong/xauusd-trading-ai-smc}
406
+ }
407
+ ```
408
+
409
+ ### Academic Paper
410
+ For the complete academic research paper with methodology, results, and analysis:
411
+
412
+ **arXiv Paper**: [XAUUSD Trading AI: A Machine Learning Approach Using Smart Money Concepts](https://arxiv.org/abs/XXXX.XXXXX)
413
+
414
+ ## License
415
+
416
+ This model is released under the MIT License. See LICENSE file for details.
417
+
418
+ ## Contact
419
+
420
+ For questions or issues, please open an issue on the Hugging Face repository.