Fetches real historical Forex data using yfinance, trains an LSTM model (TensorFlow) for next-step close prediction, supports walk-forward backtesting with RMSE/MAPE metrics, and includes a Streamlit dashboard for visualization and interactive predictions.
All code is local — run scripts to download data and train models. No credentials required for yfinance (uses Yahoo Finance symbols like 'EURUSD=X', 'GBPUSD=X', etc.).
- Create and activate a virtual environment (recommended):
python -m venv venv
# Linux / macOS
source venv/bin/activate
# Windows (PowerShell)
venv\Scripts\Activate.ps1- Install dependencies:
pip install -r requirements.txt- Fetch data for a currency pair (example: EURUSD):
python backend/data/fetch_data.py --pair EURUSD --period 5y --interval 1d
# This saves CSV to backend/data/EURUSD_1d.csv- Train LSTM model for a pair:
python backend/model/train_lstm.py --pair EURUSD --epochs 20 --window 30
# saves model to backend/model/<pair>_lstm/- Run backtest notebook:
jupyter notebook backend/notebooks/forex_backtest.ipynb- Run Streamlit dashboard:
streamlit run frontend/streamlit_app.py- Historical Forex data is downloaded using yfinance, supporting daily (
1d) and hourly (1h) intervals. - Data stored as CSV in
backend/data/PAIR_INTERVAL.csvformat (e.g.,EURUSD_1d.csv).
- Uses a Single-Layer LSTM neural network with:
- Input shape: (window_size, 1)
- Hidden units: 64
- Dropout: 0.2
- Output: 1 (next-day close)
- Trained with Mean Squared Error (MSE) loss and Adam optimizer.
- Scaler (MinMaxScaler) stored for consistent feature scaling during inference.
- Implements stepwise walk-forward validation.
- Re-trains the model incrementally with expanding window.
- Evaluates RMSE and MAPE on out-of-sample predictions.
- Implements a trading simulation using Backtrader framework (
backend/model/backtest_backtrader.py). - Strategy logic:
- Predict next close each day using trained LSTM.
- If predicted close > current close → enter long position
- If predicted close < current close → enter short position
- Close position when prediction reverses.
- Plots equity curve and computes final portfolio value.
- Displays recent price charts, last model predictions, and basic analytics.
- Supports user input for currency pair and window size.
- Provides a real-time prediction button for quick inference.
- RMSE (Root Mean Square Error): Measures average prediction error.
- MAPE (Mean Absolute Percentage Error): Relative accuracy metric for forecast magnitude.
- Add ensemble forecasting (ARIMA + LSTM hybrid).
- Integrate sentiment data (Twitter/Reddit) for macro signals.
- Deploy on web with FastAPI backend for automated predictions.
- Run
python backend/model/backtest_report.py --pair EURUSD --cash 10000 --window 30 - Outputs saved under
reports/as HTML (with charts), CSV (trades), and metrics CSV/JSON.