Financial Time Series Forecasting Models
This directory contains a comprehensive collection of forecasting models organized into three main categories: Traditional, Neural, and Ensemble models. All models follow a consistent interface with fit() and forecast() methods.
Model Categories
1. Traditional Models (traditional/)
Classical statistical and econometric approaches for time series forecasting.
ARIMA (arima_model.py)
- Type: AutoRegressive Integrated Moving Average
- Use Case: Baseline statistical model, handles trend and seasonality
- Parameters: (p=2, d=1, q=2) - AR order, differencing, MA order
- Advantages: Well-established, interpretable, handles non-stationarity
- Limitations: Assumes linear relationships, sensitive to outliers
Moving Average (moving_average_model.py)
- Type: Simple Moving Average
- Use Case: Baseline model, smoothing noisy data
- Parameters: window_size=10 (number of recent observations to average)
- Advantages: Simple, robust, computationally efficient
- Limitations: Always lags trends, cannot predict turning points
VAR (var_model.py)
- Type: Vector Autoregression (adapted for univariate series)
- Use Case: Captures complex lag relationships, multivariate extension ready
- Parameters: maxlags=5 (maximum number of lags)
- Advantages: Captures interdependencies, statistical framework
- Limitations: Assumes linear relationships, computationally intensive
2. Neural Models (neural/)
Deep learning architectures for complex pattern recognition in financial time series.
LSTM (lstm_model.py)
- Type: Long Short-Term Memory Network
- Use Case: Capturing long-term dependencies, complex patterns
- Parameters: lookback=20, epochs=10
- Architecture: Input → LSTM(32) → Dense(1)
- Advantages: Handles long-term dependencies, non-linear patterns
- Limitations: Computationally intensive, requires more data
GRU (gru_model.py)
- Type: Gated Recurrent Unit
- Use Case: Lighter alternative to LSTM, faster training
- Parameters: lookback=20, epochs=10
- Architecture: Input → GRU(32) → Dense(1)
- Advantages: Faster than LSTM, fewer parameters, less overfitting
- Limitations: May miss some complex patterns that LSTM captures
Transformer (transformer_model.py)
- Type: Attention-based Transformer
- Use Case: State-of-the-art sequence modeling, long-range dependencies
- Parameters: lookback=20, d_model=64, num_heads=4, epochs=10
- Architecture: Input → Embedding → Multi-Head Attention → FFN → Output
- Advantages: Captures long-range dependencies, parallelizable, attention weights
- Limitations: Requires more data, computationally intensive
3. Ensemble Models (ensemble/)
Methods for combining multiple models to improve prediction accuracy and robustness.
Simple Ensemble (ensemble_models.py)
- Type: Equal-weighted averaging
- Use Case: Basic ensemble, reduces variance
- Models: All 6 base models (ARIMA, MA, VAR, LSTM, GRU, Transformer)
- Advantages: Simple, often effective, reduces overfitting
- Limitations: Doesn't account for individual model performance
Weighted Ensemble (ensemble_models.py)
- Type: Performance-based weighted averaging
- Use Case: Learning optimal weights from validation performance
- Process: Train on 80% data, validate on 20%, weight inversely to error
- Advantages: Adapts to model performance, better than simple averaging
- Limitations: Requires sufficient validation data
Stacking Ensemble (ensemble_models.py)
- Type: Meta-model learns optimal combinations
- Use Case: Learning non-linear combinations of base models
- Meta-model: Linear regression trained on base model predictions
- Advantages: Can learn complex combinations, often best performance
- Limitations: Most complex, requires most data
Model Interface
All models follow a consistent interface:
# Initialize model
model = ModelName(parameters...)
# Train on historical data
model.fit(close_series: List[float])
# Generate forecasts
predictions = model.forecast(steps: int) -> List[float]
Model Selection Guide
For Beginners
- Start with Moving Average or ARIMA for baseline performance
- Use Simple Ensemble to combine multiple approaches
For Better Performance
- Try LSTM or GRU for neural network approaches
- Use Weighted Ensemble for adaptive weighting
For Advanced Use Cases
- Transformer for state-of-the-art performance (with sufficient data)
- Stacking Ensemble for maximum performance (with lots of data)
For Production Systems
- Weighted Ensemble or Stacking Ensemble for robustness
- Consider computational constraints (neural models are slower)
Performance Characteristics
| Model | Training Speed | Inference Speed | Data Requirements | Interpretability |
|---|
| Moving Average | Very Fast | Very Fast | Low | High |
| ARIMA | Fast | Fast | Medium | High |
| VAR | Medium | Medium | Medium | Medium |
| LSTM | Slow | Medium | High | Low |
| GRU | Medium | Medium | High | Low |
| Transformer | Very Slow | Medium | Very High | Low |
| Simple Ensemble | Slow | Slow | High | Medium |
| Weighted Ensemble | Slow | Slow | High | Medium |
| Stacking Ensemble | Very Slow | Slow | Very High | Low |
Usage Examples
from app.models import LSTMForecaster, SimpleEnsembleForecaster
# Single model
lstm = LSTMForecaster(lookback=20, epochs=50)
lstm.fit(price_data)
predictions = lstm.forecast(steps=10)
# Ensemble model
ensemble = SimpleEnsembleForecaster()
ensemble.fit(price_data)
predictions = ensemble.forecast(steps=10)
Dependencies
- Traditional: pandas, numpy, statsmodels
- Neural: tensorflow, keras, numpy
- Ensemble: scikit-learn, numpy
- All: typing, datetime
Notes
- All models are designed for univariate time series (single price series)
- Models handle missing data gracefully where possible
- Neural models use CPU by default (GPU support available with CUDA)
- Ensemble models automatically handle model failures gracefully
- All models return predictions as lists of floats for consistency