--- tags: - ml-intern --- # 🏦 Forex Predictive Model — ML Ensemble with Nadaraya-Watson + Bollinger A production-grade machine learning pipeline for **intraday forex price prediction** using Nadaraya-Watson envelope estimation, multi-window Bollinger Bands, and 180+ technical indicators. Outputs **BUY / SELL / NEUTRAL** signals with pip-based price targets. ## 🚀 Quick Start ```bash pip install yfinance pandas numpy scikit-learn lightgbm ta torch pyarrow joblib scipy git clone https://huggingface.co/AcyLa/forex-predictive-model cd forex-predictive-model # Get predictions immediately (pre-trained models included) python predict.py --ticker EURUSD=X # Fast mode (LightGBM only, sub-ms) python predict.py --ticker EURUSD=X --no-lstm # Single horizon python predict.py --ticker EURUSD=X --horizon 8 --features ``` ## 🏗 Architecture ``` Yahoo Finance FX Data → 180+ Features → Multi-Horizon Labels → LightGBM + LSTM Ensemble → BUY/SELL/NEUTRAL ↑ ↑ ↑ 730 days 1h bars Nadaraya-Watson Pip-based targets Bollinger (3 windows) Consensus voting RSI, MACD, ADX, Ichimoku Stochastic, ATR, Donchian Session timing (London/NY/Tokyo) ``` ## 📊 Key Components ### Nadaraya-Watson Envelope (12 features) Non-parametric kernel regression that smooths price to identify trend + overbought/oversold zones. Vectorized implementation computes 17k bars in 0.3s. ### Bollinger Bands System (45 features) - 3 windows (20, 50, 100) × 3 std devs (2.0, 2.5, 3.0) - Bandwidth, %B position, squeeze detection, band-walk signals ### All Best Indicators (180+ total) | Category | Indicators | |----------|-----------| | **Trend** | EMA stack (9/21/50/100/200), SMA, MACD, ADX, Ichimoku Cloud, CCI | | **Momentum** | RSI (7/14/21), Stochastic, Williams %R, ROC, Awesome Oscillator | | **Volatility** | ATR (14/21/50), Bollinger, Keltner, Donchian, Historical Vol | | **Volume** | OBV, MFI, VWAP, CMF, Volume ratios | | **Price** | Multi-horizon returns, candlestick, support/resistance, drawdown | | **Session** | Tokyo/London/NY sessions, overlaps, opens/closes, day-of-week | | **NW** | Smooth, envelopes, slope, crossovers, trend regime, breakout signals | ### Trading Session Awareness The model knows when London opens (08:00 UTC), NY opens (13:00 UTC), and the high-activity London-NY overlap (13:00-17:00 UTC). This is critical for FX — most price action happens during session overlaps. ## 📈 Prediction Output ``` ══════════════════════════════════════════════════════ EURUSD=X | Multi-Horizon FX Predictions Latest Bar: 2026-09-11 22:00 Current Price: 1.16023 ══════════════════════════════════════════════════════ 1h: 🟡 NEUTRAL | -0.0 pips | target=1.16023 4h: 🟡 NEUTRAL | +0.2 pips | target=1.16025 8h: 🟡 NEUTRAL | +0.8 pips | target=1.16030 24h: 🟡 NEUTRAL | +3.9 pips | target=1.16062 ────────────────────────────────────────────────────── CONSENSUS: 🟡 NEUTRAL (confidence: 50%) ══════════════════════════════════════════════════════ ``` ## 🔧 Python API ```python from predict import ForexPredictor predictor = ForexPredictor(ticker="EURUSD=X") # Multi-horizon with consensus result = predictor.get_multi_horizon() print(f"Consensus: {result['consensus']}") # Single horizon signal = predictor.get_signal(horizon=8) # signal = { # 'pair': 'EURUSD=X', 'signal': 'BUY', 'confidence': 0.65, # 'predicted_pips': 12.3, 'current_price': 1.16023, # 'target_price': 1.16146, 'horizon_hours': 8 # } # Fast HFT mode (LightGBM only) fast = predictor.get_signal(horizon=1, use_lstm=False) # Batch prediction on your own data preds = predictor.predict_batch(your_ohlcv_df, horizon=4) ``` ## 🔄 Training Other Pairs ```bash # Train on GBP/USD python train.py --ticker GBPUSD=X --no-backtest # Train on USD/JPY (pip size auto-detected as 0.01) python train.py --ticker USDJPY=X --no-backtest # Full walk-forward backtest (slower) python train.py --ticker EURUSD=X ``` Supported pairs: EURUSD, GBPUSD, USDJPY, USDCHF, AUDUSD, USDCAD, NZDUSD ## 📁 Files ``` forex-predictive-model/ ├── config.py # All hyperparameters ├── data_loader.py # Yahoo Finance FX download ├── nadaraya_watson.py # NW envelope estimator (vectorized) ├── features.py # 180+ indicators (Bollinger, RSI, MACD, etc.) ├── labels.py # Pip-based labels + triple-barrier ├── models.py # LightGBM + LSTM ensemble ├── backtest.py # Walk-forward backtester (pip P&L) ├── train.py # Training pipeline CLI ├── predict.py # Prediction API + CLI └── fx_models/EURUSD_X/ # Pre-trained models (4 horizons) ``` ## ⚠️ Disclaimer Research tool, not financial advice. FX trading carries high risk. Always use stop-losses and proper position sizing. ## Generated by ML Intern This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub. - Try ML Intern: https://smolagents-ml-intern.hf.space - Source code: https://github.com/huggingface/ml-intern ## Usage ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_id = 'AcyLa/forex-predictive-model' tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id) ``` For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.