===========================================================
This project is an end-to-end algorithmic trading system dedicated to gold (XAU/USD). It combines data engineering, quantitative analysis, machine learning, and full-stack development to provide real-time trading recommendations.
- Massive Dataset: 25+ years of historical data (2000-present)
- 344 Features: Technical and macroeconomic indicators
- XGBoost Model: Optimized binary classification (~90% accuracy)
- Professional Interface: Interactive Streamlit dashboard
- Real-Time: Live market data via yFinance
The project is organized into the following directories:
raw_market_data.csv: Raw market data (~7 MB)processed_features.csv: Processed features (~37 MB)
xgboost_gold_predictor.joblib: XGBoost modelfeature_scaler.joblib: Feature scaler
- Log files
- Global configuration
- Fetches raw market data
- Creates 344 features
- Trains XGBoost classifier
- Interactive Streamlit dashboard (1100+ lines)
- Complete pipeline execution
- Python dependencies
- MIT License
- Contribution guidelines
- Development shortcuts
- Git ignore rules
- Environment variables template
The data flow is as follows:
- Yahoo Finance API: Fetches 16 assets, 25+ years of data
- Data Collector: Fetches raw market data
- Feature Engineering: Creates 344 features
- Model Training: Trains XGBoost classifier
- Streamlit Dashboard: Provides real-time predictions
The system tracks the following assets:
| Category | Assets | Symbols |
|---|---|---|
| Gold | Gold Futures, GLD ETF, Gold Miners | GC=F, GLD, GDX |
| Dollar | Dollar Index | DX-Y.NYB |
| Rates | US 10Y, US 2Y | ^TNX, ^IRX |
| Volatility | VIX | ^VIX |
| Indices | S&P 500, NASDAQ | ^GSPC, ^IXIC |
| Metals | Silver, Platinum, Copper | SI=F, PL=F, HG=F |
| Energy | Crude Oil | CL=F |
| Forex | EUR/USD, USD/JPY | EURUSD=X, JPY=X |
| Crypto | Bitcoin | BTC-USD |
- Start: January 1, 2000
- End: Today
- Duration: 25+ years
- Rows: ~6,000+ trading days
The system creates the following features:
- Multi-period returns (1d, 2d, 3d, 5d, 10d, 15d, 20d, 30d, 60d, 90d)
- Log returns, Historical volatility (annualized)
- True Range, ATR (7, 14, 21)
- Opening gap, Distance to extremes
- SMA/EMA (5, 8, 10, 13, 20, 21, 34, 50, 55, 89, 100, 144, 200, 233)
- Distance to price, MA slopes
- Crossovers (Golden Cross, Death Cross)
- RSI (5, 7, 9, 14, 21, 28) with extreme zones
- MACD standard and alternative
- Stochastic (5, 9, 14, 21), Stochastic RSI
- Williams %R, CCI, ADX, Ultimate Oscillator
- Rate of Change multi-periods
- Bollinger Bands (periods: 10, 20, 50 x std: 1.5, 2, 2.5)
- Position within bands, BB Squeeze
- Breakout signals
- Volume ratio, Volume spike detection
- OBV, VPT, MFI, A/D Line
- Ratios: Gold/DXY, Gold/Silver, Gold/Platinum, Gold/Copper
- Rolling correlations (20d, 60d)
- VIX levels, Yield Curve, Oil trends
- S&P 500, NASDAQ, Bitcoin correlations
- Cyclic encoding (day, month)
- Flags: Monday, Friday, start/end of month, quarter
- Gold seasonality (Q1, Q3, Q4)
- Consecutive up/down days
- Candlestick patterns (Doji, Hammer, Engulfing)
- Higher Highs, Lower Lows
The system uses an XGBoost classifier with the following configuration:
{
'n_estimators': 500,
'max_depth': 8,
'learning_rate': 0.03,
'subsample': 0.8,
'colsample_bytree': 0.7,
'min_child_weight': 5,
'gamma': 0.15,
'reg_alpha': 0.5,
'reg_lambda': 2.0,
'eval_metric': 'auc'
}| Metric | Score |
|---|---|
| Accuracy | ~90% |
| Precision | ~93% |
| Recall | ~91% |
| F1-Score | ~92% |
| ROC-AUC | ~98% |
The dashboard has the following sections:
- Real-Time Data
- XAU/USD price with variation
- DXY, US 10Y, VIX
- Silver, S&P 500, Oil, Bitcoin
- Trading Signal
- Recommendation (Strong Buy/Buy/Neutral/Sell/Strong Sell)
- Probabilities with progress bars
- Technical indicators (RSI, MACD, Bollinger)
- Technical Chart
- Japanese candlesticks
- SMA 20/50/200
- Bollinger Bands
- RSI, MACD, Volume
- Correlations
- Normalized comparative performance
- Correlation guide
- Feature Importance
- Top 20 decision factors
- Interpretation
- Python 3.9+
- pip
# Clone the repository
git clone https://github.com/IlyasFardaouix/GOLD-TRADING-AI.git
cd GOLD-TRADING-AI
# Create virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt# Option 1: Complete pipeline (recommended for first time)
python run_pipeline.py
# Option 2: Individual steps
python data_collector.py # Data collection
python feature_engineering.py # Feature creation
python model_training.py # Model training
# Option 3: Launch application (after training)
streamlit run app.pyThe application will be accessible at http://localhost:8501
The system uses the following decision thresholds:
| Level | Probability | Signal |
|---|---|---|
| Strong | >= 70% | Strong Buy / Strong Sell |
| Moderate | 55-70% | Buy / Sell |
| Weak | < 55% | Weak Signal |
The system demonstrates the following skills:
- Data Engineering: ETL, Financial APIs, Data pipelines
- Quantitative Analysis: Technical indicators, Macro correlations, Statistics
- Machine Learning: Advanced feature engineering, XGBoost, Temporal validation
- Full-Stack Data: Streamlit, Plotly, UI/UX, Interactive visualizations
This system is developed for educational and demonstration purposes only.
The predictions provided do not constitute financial advice in any way. Trading involves significant risk of capital loss. Any investment decision should be made after consulting a qualified financial advisor.
- Fundamental data (inflation, employment, GDP)
- Ensemble models (Random Forest + LSTM + Transformer)
- Backtesting with Sharpe ratio calculation
- Email/SMS alerts
- Cloud deployment (AWS/GCP/Azure)
- REST API for external integration
- Sentiment analysis (news, Twitter)