Skip to content

IlyasFardaouix/GOLD-TRADING-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gold Trading AI - Intelligent Decision Support System for XAU/USD

===========================================================

Overview


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.

Key Features

  • 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

Project Architecture


The project is organized into the following directories:

Data Directory (data/)

  • raw_market_data.csv: Raw market data (~7 MB)
  • processed_features.csv: Processed features (~37 MB)

Models Directory (models/)

  • xgboost_gold_predictor.joblib: XGBoost model
  • feature_scaler.joblib: Feature scaler

Logs Directory (logs/)

  • Log files

Configuration File (config.py)

  • Global configuration

Data Collection Module (data_collector.py)

  • Fetches raw market data

Feature Engineering Module (feature_engineering.py)

  • Creates 344 features

Model Training Module (model_training.py)

  • Trains XGBoost classifier

Streamlit Dashboard (app.py)

  • Interactive Streamlit dashboard (1100+ lines)

Pipeline Execution (run_pipeline.py)

  • Complete pipeline execution

Requirements File (requirements.txt)

  • Python dependencies

License (LICENSE)

  • MIT License

Contribution Guidelines (CONTRIBUTING.md)

  • Contribution guidelines

Makefile (Makefile)

  • Development shortcuts

Git Ignore File (gitignore)

  • Git ignore rules

Environment Variables Template (env.example)

  • Environment variables template

Data Flow


The data flow is as follows:

  1. Yahoo Finance API: Fetches 16 assets, 25+ years of data
  2. Data Collector: Fetches raw market data
  3. Feature Engineering: Creates 344 features
  4. Model Training: Trains XGBoost classifier
  5. Streamlit Dashboard: Provides real-time predictions

Data Sources


The system tracks the following assets:

Tracked Assets (16)

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

Data Period

  • Start: January 1, 2000
  • End: Today
  • Duration: 25+ years
  • Rows: ~6,000+ trading days

Features Created (344)


The system creates the following features:

Price & Returns

  • 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

Moving Averages

  • 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)

Momentum

  • 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

Volatility

  • Bollinger Bands (periods: 10, 20, 50 x std: 1.5, 2, 2.5)
  • Position within bands, BB Squeeze
  • Breakout signals

Volume

  • Volume ratio, Volume spike detection
  • OBV, VPT, MFI, A/D Line

Macroeconomic

  • 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

Temporal

  • Cyclic encoding (day, month)
  • Flags: Monday, Friday, start/end of month, quarter
  • Gold seasonality (Q1, Q3, Q4)

Patterns

  • Consecutive up/down days
  • Candlestick patterns (Doji, Hammer, Engulfing)
  • Higher Highs, Lower Lows

Machine Learning Model


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'
}

Performance Metrics

Metric Score
Accuracy ~90%
Precision ~93%
Recall ~91%
F1-Score ~92%
ROC-AUC ~98%

Streamlit Dashboard


The dashboard has the following sections:

  1. Real-Time Data
    • XAU/USD price with variation
    • DXY, US 10Y, VIX
    • Silver, S&P 500, Oil, Bitcoin
  2. Trading Signal
    • Recommendation (Strong Buy/Buy/Neutral/Sell/Strong Sell)
    • Probabilities with progress bars
    • Technical indicators (RSI, MACD, Bollinger)
  3. Technical Chart
    • Japanese candlesticks
    • SMA 20/50/200
    • Bollinger Bands
    • RSI, MACD, Volume
  4. Correlations
    • Normalized comparative performance
    • Correlation guide
  5. Feature Importance
    • Top 20 decision factors
    • Interpretation

Installation & Usage


Prerequisites

  • Python 3.9+
  • pip

Installation

# 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

Execution

# 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.py

The application will be accessible at http://localhost:8501

Decision Thresholds


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

Skills Demonstrated


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

Disclaimer


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.

Future Improvements


  • 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)

About

AI-assisted gold market forecasting and signal analysis for trading research.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors