Skip to content

Bebelon2000/price_prediction_neural_networks

Repository files navigation

💹 Forex Price Prediction with Deep Neural Networks: LSTM vs. MLP Comparison

A Deep Learning project focused on predicting the price variation of USD/EUR and USD/JPY currency pairs for a 5-day horizon. Unlike simple price-prediction models, this project utilizes a multivariate approach, integrating key macroeconomic indicators to capture the fundamental drivers of the Forex market.

🎯 Project Objective

The goal is to leverage a 30-day window of historical market and economic data (7 features) to forecast the exchange rates for the next 5 business days simultaneously.

📊 Dataset & Feature Engineering

The model is trained on a comprehensive dataset spanning from January 2010 to the present, combining currency price action with global macroeconomic signals.

Feature Composition (Multivariate Input):

The input vector includes 7 primary features derived from the following macroeconomic sources:

Category Indicator File Source Impact on Forex
Price Action USD/EUR & USD/JPY usd_eur.csv, jpy_eur.csv Direct historical price trends.
Market Index US Dollar Index (DXY) dxy.csv Measures USD strength against a basket of currencies.
Stock Market S&P 500 Index sp500.csv Reflects global risk appetite and investor sentiment.
Economic Growth GDP (US & Eurozone) us_gdp.csv, euro_gdp.csv Fundamental indicator of currency strength.
Monetary Policy US Interest Rates us_interest_rate.csv High rates often attract foreign capital.
Inflation CPI (US & Eurozone) us_inflation.csv, euro_cpi.csv Influences central bank decisions on interest rates.

🤖 Neural Network Architecture & Performance

This section details the internal structure and performance of the implemented models. Both networks were trained on a dataset of 4,472 samples covering 15 years of market data.

1. MLP / Backpropagation Model

  • Complexity: 67,860 trainable parameters.
  • Architecture: 3 Dense layers with decreasing dimensionality (200 -> 100 -> 50) and Dropout layers (0.15 and 0.07) to prevent overfitting on market noise.
  • Input: Flattened 210-feature vector (30 days × 7 features).
Model Summary (MLP):
- Layer 1 (Dense): 200 units (42,200 params)
- Layer 2 (Dense): 100 units (20,100 params)
- Layer 3 (Dense): 50 units (5,050 params)
- Output (Dense): 10 units (510 params)

2. LSTM Model (Sequence Optimized)

  • Complexity: 281,322 trainable parameters (significantly higher capacity for temporal patterns).

  • Architecture: A 256-unit LSTM layer followed by a specialized Dense block (32 -> 64) to refine the temporal features.

  • Input: 3D Tensor (4472, 30, 7), maintaining the time-series structure of the 30-day window.

Model Summary (LSTM):
- Layer 1 (LSTM): 256 units (270,336 params)
- Layer 2 (Dense): 32 units (8,224 params)
- Layer 3 (Dense): 64 units (2,112 params)
- Output (Dense): 10 units (650 params)

🔮 Sample Predictions (Next 5 Days)

Based on the latest logs, here are the model outputs for the USD/EUR and USD/JPY exchange rates:

Day MLP Prediction (Price) LSTM Prediction (Price)
Day +1 1.1478 / 124.00 1.1486 / 129.56
Day +2 1.1431 / 124.22 1.1508 / 128.61
Day +3 1.1432 / 124.69 1.1453 / 130.17
Day +4 1.1334 / 124.78 1.1506 / 128.96
Day +5 1.1320 / 124.84 1.1483 / 129.29

🛠️ Technical Implementation

  • Framework: TensorFlow/Keras, Pandas, and Scikit-learn.
  • Multi-Step Forecasting: The model outputs 10 values ($5 \text{ days} \times 2 \text{ currency pairs}$) simultaneously.
  • Data Scaling: Features are normalized using MinMaxScaler. Predictions are converted back to real-world currency values via inverse scaling.

📈 Performance Benchmarking

The models were evaluated using Mean Squared Error (MSE) and Mean Absolute Error (MAE).

Model Loss Function Training Insight
MLP MSE Faster convergence but more sensitive to market noise.
LSTM Huber Loss Better stability and generalization across economic cycles.

📁 Repository Structure

├── dados_macro/        # Raw macroeconomic CSVs (Jan 2010 - Present)
├── checkpoints/        # Saved model weights (.h5)
├── pre_processing/     # Merged datasets and scaling objects (.pkl)
├── scripts/
│   ├── modelo_BP.py    # MLP / Backpropagation implementation
│   └── modelo_LSTM.py  # LSTM architecture and future forecasting
└── results/            # Performance plots (Loss & MAE)

About

Multivariate currency forecasting (USD/EUR & USD/JPY) using MLP and LSTM architectures. Features a 15-year macroeconomic dataset (2010-2025).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages