Downloads · 30 days
0
Rogendo/forex-lstm-models
forex-lstm-models is a machine learning model from Rogendo. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras. The card lists the license as mit.
This repository hosts a collection of 80+ specialized Long Short-Term Memory (LSTM) and vector scalars neural network models designed to forecast future price movements and directional trends for major currency pairs.…
Downloads · 30 days
0
Access
Public
Updated Feb 7, 2026
Repo size
38.9 MB
Likes
4
Public
Click a slice to open those files.
.h528.1 MB · 98%
From the Hugging Face model README
This repository hosts a collection of **80+ specialized Long Short-Term Memory (LSTM) and vector scalars ** neural network models designed to forecast future price movements and directional trends for major currency pairs. Each model is trained on a specific pair and timeframe tuple.
This project explores the application of Deep Learning to financial time-series forecasting. Unlike generic models, this collection treats every currency pair and timeframe combination (e.g., EURUSD on 15m) as a unique environment requiring a dedicated model.
The models utilize historical OHLCV (Open, High, Low, Close, Volume) data to predict two simultaneous outputs:
Note: These models are part of a larger full-stack research project ("FX-Predict") involving a FastAPI backend and a real-time dashboard.
These models are intended for:
The models are designed to be consumed by an inference engine (like the model_service.py in the FX-Predict app) which applies post-processing logic:
During testing, a critical discrepancy was observed:
yfinance (Yahoo Finance).The inputs are currently limited to raw OHLCV. The models lack "Macro-Awareness" (Economic Calendar events) and Order Flow data, limiting their ability to react to news events.
Users should treat these models as Directional Compasses, not Crystal Balls. They work best when validated by "Market Breadcrumbs" such as:
You need the .h5 model file and the corresponding .pkl feature scaler file to ensure data is normalized exactly as the model expects.
import numpy as np
import pickle
import os
from tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
# 1. Select Pair and Interval
PAIR = "EURUSD_X" # Options: GBPUSD_X, USDJPY_X, etc.
INTERVAL = "15m" # Options: 5m, 15m, 30m, 1h, 4h
# 2. Download Files
model_path = hf_hub_download(repo_id="rogendo/forex-lstm-models", filename=f"{PAIR}_{INTERVAL}_model.h5")
scaler_path = hf_hub_download(repo_id="rogendo/forex-lstm-models", filename=f"{PAIR}_{INTERVAL}_features.pkl")
# 3. Load Model
model = load_model(model_path)
with open(scaler_path, 'rb') as f:
feature_info = pickle.load(f)
print(f"Loaded {PAIR} {INTERVAL} | Lookback: {feature_info['lookback']}")
# 4. Prepare Dummy Data (Replace with real OHLCV data scaled via RobustScaler)
# Shape: (1, Lookback_Steps, 5_Features)
dummy_input = np.random.rand(1, feature_info['lookback'], 5)
# 5. Predict
prediction = model.predict(dummy_input)
price_change = prediction[0][0][0]
direction_conf = prediction[1][0][0]
print(f"Predicted Change: {price_change:.5f}")
print(f"Direction Confidence: {direction_conf:.2f}")
The models were trained on historical Forex data fetched via yfinance.
Pairs: EURUSD, GBPUSD, USDJPY, AUDUSD, USDCAD, USDCHF, NZDUSD.
Timeframes: 5m, 15m (approx 60 days history); 30m, 1h, 4h (approx 2 years history).
Scaling: RobustScaler (sklearn) was used to handle outliers in financial data.
Windowing: Data was transformed into sequences of 15 lookback steps.
Optimizer: Adam (learning_rate=0.001)
Loss Functions:
Price: mean_squared_error
Direction: binary_crossentropy
Batch Size: 32
Epochs: 50 (with Early Stopping patience=15)
Testing Data
Data was split 80/20 for Training/Validation. Due to the rolling window nature of time series, the validation set represents the most recent market data available at the time of training.
RMSE (Root Mean Squared Error): Measures price prediction magnitude error.
MAE (Mean Absolute Error): Average error in pips.
Directional Accuracy: % of time the model correctly predicted Positive vs Negative close.
4H, 14min Models: Showed the highest stability and profitability because price trends are cleaner.
5M Models: Showed high noise. While directional accuracy remained >50%, the realizable profit was often eaten by spreads.
Model Architecture
The architecture is designed to capture temporal dependencies:
Input Layer: Shape (15, 5)
LSTM Layer 1: 50 units, Return Sequences=True, Dropout=0.2
LSTM Layer 2: 25 units, Return Sequences=False, Dropout=0.2
Dense Layer: 20 units, ReLU
Output 1 (Regression): 1 Unit (Price Change)
Output 2 (Classification): 1 Unit (Sigmoid - Direction)
To improve the "Realizable Profitability" of these models, the following upgrades are planned:
Data Pipeline Overhaul: Move away from yfinance to a professional provider (OANDA/Alpha Vantage) to access 2+ years of 5m data and faster api.
Feature Expansion: Triple the input features to include:
Rolling Technical Indicators (RSI, MACD, Bollinger Bands) as inputs (not just validators).
Time-of-day embeddings (to learn session volatility).
Architecture: Experiment with CNN-LSTM hybrids (to catch chart patterns) and Transformer models (TimeGPT).
For questions regarding the implementation or the "FX-Predict" dashboard integration, please open a discussion in the Community tab.