Rogendo commited on
Commit
5ad129f
·
verified ·
1 Parent(s): 668e3e8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +208 -3
README.md CHANGED
@@ -1,3 +1,208 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: keras
4
+ tags:
5
+ - time-series
6
+ - finance
7
+ - forex
8
+ - lstm
9
+ - tensorflow
10
+ - economics
11
+ metrics:
12
+ - mean_squared_error
13
+ - accuracy
14
+ ---
15
+
16
+ # Model Card for Forex-LSTM-Predictor-Collection
17
+
18
+ This repository hosts a collection of **20 specialized Long Short-Term Memory (LSTM)** 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.
19
+
20
+ ## Model Details
21
+
22
+ ### Model Description
23
+
24
+ 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.
25
+
26
+ The models utilize historical **OHLCV** (Open, High, Low, Close, Volume) data to predict two simultaneous outputs:
27
+ 1. **Price Vector:** The projected closing price for the next time step.
28
+ 2. **Directional Probability:** A confidence score indicating the likelihood of the price moving Up or Down.
29
+
30
+ *Note: These models are part of a larger full-stack research project ("FX-Predict") involving a FastAPI backend and a real-time dashboard.*
31
+
32
+ - **Developed by:** Rogendo
33
+ - **Model type:** Dual-Output LSTM (Regression + Classification)
34
+ - **Language(s):** Python 3.12 (TensorFlow/Keras)
35
+ - **License:** MIT
36
+ - **Finetuned from model:** N/A (Trained from scratch)
37
+
38
+ ### Model Sources
39
+
40
+ - **Repository:** [https://huggingface.co/rogendo/forex-lstm-models](https://huggingface.co/rogendo/forex-lstm-models)
41
+
42
+ ## Uses
43
+
44
+ ### Direct Use
45
+
46
+ These models are intended for:
47
+ * **Algorithmic Trading Research:** Backtesting ML strategies on forex markets.
48
+ * **Signal Generation:** Providing baseline buy/sell signals based on price action history.
49
+ * **Market Analysis:** Identifying potential trend reversals via directional confidence scores.
50
+
51
+ ### Downstream Use
52
+
53
+ 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:
54
+ * **Risk Management:** Calculating dynamic Stop Loss/Take Profit levels using ATR (Average True Range).
55
+ * **Confluence checking:** Comparing predictions across timeframes (e.g., 15m vs 4h).
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ * **Unsupervised Live Trading:** These models are Proof-of-Concept tools. They should not control real capital without a strict risk management wrapper (see Limitations).
60
+ * **Long-term Forecasting:** The models are optimized for the next candle ($t+1$) only.
61
+
62
+ ## Bias, Risks, and Limitations
63
+
64
+ ### The "Accuracy vs. Profitability" Paradox
65
+ During testing, a critical discrepancy was observed:
66
+ * **High Directional Accuracy:** The models frequently achieved **>55% accuracy** in predicting the color of the next candle.
67
+ * **Low Win Rate (~40%):** Without external logic, the raw model predictions often led to losses.
68
+ * *Cause:* The model predicts the *vector* correctly but not the *path*. On volatile timeframes (5m/15m), market noise often triggered standard Stop Losses before the prediction materialized.
69
+ * *Mitigation:* We strongly recommend using **ATR-based dynamic stops** rather than fixed percentage stops when using these models.
70
+
71
+ ### Data Limitations
72
+ * **Data Source:** Trained on data from `yfinance` (Yahoo Finance).
73
+ * **Lag & Limits:** Yahoo Finance data can be delayed. Crucially, intraday data (5m/15m) is restricted to the last **60 days**. This introduces **Recency Bias**, as the model has not seen historical market regimes (e.g., the 2008 crash or 2020 volatility).
74
+
75
+ ### Feature Poverty
76
+ 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.
77
+
78
+ ### Recommendations
79
+
80
+ Users should treat these models as **Directional Compasses**, not Crystal Balls. They work best when validated by "Market Breadcrumbs" such as:
81
+ * Session High/Low breaks (e.g., 9:30 AM NY Open).
82
+ * Key psychological levels (0.000 / 0.500).
83
+ * Multi-timeframe confluence.
84
+
85
+ ## How to Get Started with the Model
86
+
87
+ You need the `.h5` model file and the corresponding `.pkl` feature scaler file to ensure data is normalized exactly as the model expects.
88
+
89
+ ```python
90
+ import numpy as np
91
+ import pickle
92
+ import os
93
+ from tensorflow.keras.models import load_model
94
+ from huggingface_hub import hf_hub_download
95
+
96
+ # 1. Select Pair and Interval
97
+ PAIR = "EURUSD_X" # Options: GBPUSD_X, USDJPY_X, etc.
98
+ INTERVAL = "15m" # Options: 5m, 15m, 30m, 1h, 4h
99
+
100
+ # 2. Download Files
101
+ model_path = hf_hub_download(repo_id="rogendo/forex-lstm-models", filename=f"{PAIR}_{INTERVAL}_model.h5")
102
+ scaler_path = hf_hub_download(repo_id="rogendo/forex-lstm-models", filename=f"{PAIR}_{INTERVAL}_features.pkl")
103
+
104
+ # 3. Load Model
105
+ model = load_model(model_path)
106
+ with open(scaler_path, 'rb') as f:
107
+ feature_info = pickle.load(f)
108
+
109
+ print(f"Loaded {PAIR} {INTERVAL} | Lookback: {feature_info['lookback']}")
110
+
111
+ # 4. Prepare Dummy Data (Replace with real OHLCV data scaled via RobustScaler)
112
+ # Shape: (1, Lookback_Steps, 5_Features)
113
+ dummy_input = np.random.rand(1, feature_info['lookback'], 5)
114
+
115
+ # 5. Predict
116
+ prediction = model.predict(dummy_input)
117
+ price_change = prediction[0][0][0]
118
+ direction_conf = prediction[1][0][0]
119
+
120
+ print(f"Predicted Change: {price_change:.5f}")
121
+ print(f"Direction Confidence: {direction_conf:.2f}")
122
+
123
+ ```
124
+
125
+ ### Training Details
126
+ #### Training Data
127
+
128
+ The models were trained on historical Forex data fetched via yfinance.
129
+
130
+ Pairs: **EURUSD, GBPUSD, USDJPY, AUDUSD, USDCAD, USDCHF, NZDUSD**.
131
+
132
+ Timeframes: **5m, 15m (approx 60 days history); 30m, 1h, 4h** (approx 2 years history).
133
+
134
+ #### Training Procedure
135
+ ##### Preprocessing
136
+
137
+ Scaling: RobustScaler (sklearn) was used to handle outliers in financial data.
138
+
139
+ Windowing: Data was transformed into sequences of 15 lookback steps.
140
+
141
+ ##### Training Hyperparameters
142
+
143
+ Optimizer: Adam (learning_rate=0.001)
144
+
145
+ Loss Functions:
146
+
147
+ Price: mean_squared_error
148
+
149
+ Direction: binary_crossentropy
150
+
151
+ Batch Size: 32
152
+
153
+ Epochs: 50 (with Early Stopping patience=15)
154
+
155
+ ##### Evaluation
156
+ ###### Testing Data, Factors & Metrics
157
+ **Testing Data**
158
+
159
+ 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.
160
+
161
+ ##### Metrics
162
+
163
+ RMSE (Root Mean Squared Error): Measures price prediction magnitude error.
164
+
165
+ MAE (Mean Absolute Error): Average error in pips.
166
+
167
+ Directional Accuracy: % of time the model correctly predicted Positive vs Negative close.
168
+
169
+ ##### Results
170
+
171
+
172
+ 4H, 14min Models: Showed the highest stability and profitability because price trends are cleaner.
173
+
174
+ 5M Models: Showed high noise. While directional accuracy remained >50%, the realizable profit was often eaten by spreads.
175
+
176
+ ##### Technical Specifications
177
+ **Model Architecture**
178
+
179
+ The architecture is designed to capture temporal dependencies:
180
+
181
+ Input Layer: Shape (15, 5)
182
+
183
+ LSTM Layer 1: 50 units, Return Sequences=True, Dropout=0.2
184
+
185
+ LSTM Layer 2: 25 units, Return Sequences=False, Dropout=0.2
186
+
187
+ Dense Layer: 20 units, ReLU
188
+
189
+ Output 1 (Regression): 1 Unit (Price Change)
190
+
191
+ Output 2 (Classification): 1 Unit (Sigmoid - Direction)
192
+
193
+ ##### Future Roadmap
194
+
195
+ To improve the "Realizable Profitability" of these models, the following upgrades are planned:
196
+
197
+ **Data Pipeline Overhaul**: Move away from yfinance to a professional provider (OANDA/Alpha Vantage) to access 2+ years of 5m data and faster api.
198
+
199
+ **Feature Expansion**: Triple the input features to include:
200
+
201
+ - Rolling Technical Indicators (RSI, MACD, Bollinger Bands) as inputs (not just validators).
202
+
203
+ - Time-of-day embeddings (to learn session volatility).
204
+
205
+ **Architecture**: Experiment with CNN-LSTM hybrids (to catch chart patterns) and Transformer models (TimeGPT).
206
+
207
+
208
+ For questions regarding the implementation or the "FX-Predict" dashboard integration, please open a discussion in the Community tab.