A production-ready deep learning system for forecasting US commodity prices using LSTM, BiLSTM, and Transformer architectures.
Live Demo β’ Documentation β’ API Access
This project implements state-of-the-art time series forecasting models to predict prices for major US commodities including:
- Energy: Crude Oil (WTI), Natural Gas
- Precious Metals: Gold, Silver
- Base Metals: Copper
- Agriculture: Corn, Wheat, Soybeans
- π§ Multiple Model Architectures: LSTM, BiLSTM, CNN-LSTM, Transformer, and hybrid models
- π 100+ Technical Features: Moving averages, RSI, MACD, Bollinger Bands, volatility measures
- π Interactive Dashboard: Real-time visualization with Chart.js
- β‘ Automated Pipeline: Daily predictions via GitHub Actions
- π― Multi-Horizon Forecasts: 1-day, 5-day, and 10-day predictions
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA INGESTION β
β Yahoo Finance API β Raw OHLCV Data β Data Validation β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FEATURE ENGINEERING β
β Price Lags β Returns β Moving Averages β Volatility β RSI β
β MACD β Bollinger Bands β Cross-commodity β Calendar Features β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MODEL ENSEMBLE β
β βββββββββββ βββββββββββ βββββββββββββββ ββββββββββββββββ β
β β LSTM β β BiLSTM β β Transformer β β LSTM+Transf. β β
β ββββββ¬βββββ ββββββ¬βββββ ββββββββ¬βββββββ ββββββββ¬ββββββββ β
β ββββββββββββββ΄βββββββββββββββ΄ββββββββββββββββββ β
β βΌ β
β Weighted Ensemble β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PREDICTIONS β
β 1-Day Forecast β 5-Day Forecast β 10-Day Forecast β
β Confidence Intervals β Direction Probability β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Backtested on 2 years of out-of-sample data (2023-2025):
| Model | RMSE | MAE | MAPE | Directional Accuracy |
|---|---|---|---|---|
| LSTM | 1.847 | 1.423 | 2.31% | 54.2% |
| BiLSTM | 1.756 | 1.352 | 2.18% | 55.8% |
| Transformer | 1.892 | 1.478 | 2.45% | 53.1% |
| Hybrid (LSTM+Transformer) | 1.698 | 1.287 | 2.04% | 57.3% |
Results on Crude Oil WTI daily price prediction
git clone https://github.com/YOUR_USERNAME/commodity-predictor.git
cd commodity-predictor
pip install -r requirements.txt# Train models and generate predictions with sample data
python demo.py# Full training pipeline
python train.py --commodity "Crude Oil WTI" --epochs 100commodity-predictor/
βββ models.py # Neural network architectures
βββ feature_engineering.py # Technical indicator generation
βββ data_loader.py # Data fetching and preprocessing
βββ train.py # Training pipeline
βββ demo.py # Demo with sample data
βββ dashboard.html # Interactive web dashboard
βββ sample_data.py # Synthetic data generator
βββ requirements.txt # Dependencies
class BiLSTMModel(nn.Module):
"""
Bidirectional LSTM for capturing both forward
and backward temporal patterns.
Architecture:
- Input projection layer
- 2-layer Bidirectional LSTM (hidden_size=64)
- Dropout regularization (p=0.2)
- Fully connected output layer
"""The system generates 100+ features including:
| Category | Features |
|---|---|
| Lag Features | 1, 2, 3, 5, 7, 14, 21, 30, 60, 90 day lags |
| Returns | 1, 5, 10, 21, 63 day returns |
| Moving Averages | SMA & EMA (5, 10, 20, 50, 100, 200) |
| Volatility | Rolling std dev (5, 10, 21, 63 day) |
| Momentum | RSI, MACD, Rate of Change |
| Bands | Bollinger Band position & width |
| Cross-Commodity | Gold/Silver ratio, WTI/Brent spread |
| Calendar | Day of week, month, seasonality encoding |
The interactive dashboard provides:
- Real-time price cards with prediction badges
- Historical charts with forecast overlay
- Multi-horizon forecasts (1, 5, 10 days)
- Model performance metrics
Predictions are available via JSON endpoint:
fetch('https://YOUR_USERNAME.github.io/commodity-predictor/predictions/sample_predictions.json')
.then(response => response.json())
.then(data => {
console.log(data.predictions['Crude Oil WTI'].forecasts['1d']);
// { price: 69.15, change_pct: 0.63 }
});Premium API with real-time predictions available β Contact for access
- Deep Learning: PyTorch
- Data Processing: Pandas, NumPy
- Data Source: Yahoo Finance, FRED
- Visualization: Chart.js, Matplotlib
- Deployment: GitHub Actions, GitHub Pages
MIT License β see LICENSE for details.
Brian Curry β brian at vector1.ai
- Yahoo Finance for market data
- World Bank for historical commodity data
- Research papers on LSTM and Transformer architectures for financial forecasting
