Skip to content

Repository files navigation

Forecasting Short-Term NIFTY Returns

A Comparative Study of Naive, HMM, LSTM and Hybrid HMM-LSTM Models

Python TensorFlow HMM Research


Project Overview

Can deep learning predict short-term stock index returns?

This project investigates one of the most common assumptions in quantitative finance:

Can a deep learning model outperform a simple statistical baseline when forecasting the next 25-minute return of the NIFTY 50 Index?

To answer this question, four forecasting models were evaluated using a strict chronological train-validation-test split:

  • Naive Baseline
  • Hidden Markov Model (HMM)
  • Long Short-Term Memory Network (LSTM)
  • Hybrid HMM + LSTM

Rather than optimizing until a positive result appeared, the goal was to objectively evaluate whether increasingly sophisticated models genuinely improved forecasting performance.


Dataset

  • NIFTY 50 Index
  • Two years of historical 1-minute OHLCV data
  • Resampled to 5-minute candles
  • Approximately 37,000 observations after feature engineering

Feature Engineering

The forecasting models were trained using technical and volatility-based features including:

  • Log Returns
  • Rolling Volatility (5, 10 and 20 bars)
  • ATR Ratio
  • EMA Distance (10,20,50)
  • EMA Spread
  • RSI(14)

For the HMM, only market-state variables were used:

  • Log Return
  • Volatility
  • ATR Ratio

Forecasting Pipeline

1-Minute Data │ ▼ 5-Minute Resampling │ ▼ Feature Engineering │ ▼ Predict 25-Minute Return │ ▼ ──────────────────────────────── Naive Baseline │ LSTM │ Gaussian HMM │ Hybrid HMM + LSTM ──────────────────────────────── │ ▼ Out-of-Sample Evaluation


Models Compared

1. Naive Baseline

Assumes the next return is approximately equal to the current return.

This provides the minimum benchmark every forecasting model should outperform.


2. Gaussian Hidden Markov Model

Learns latent market regimes directly from market behaviour using:

  • Returns
  • Volatility
  • ATR

Instead of predicting returns directly, the HMM predicts hidden market states.

For forecasting, each hidden state predicts the average future return historically observed in that regime.


3. LSTM

A recurrent neural network trained using:

  • 10-candle lookback window
  • 32 hidden units
  • Dropout Regularization
  • Adam Optimizer
  • Early Stopping

4. Hybrid HMM + LSTM

The hidden market regime discovered by the HMM is one-hot encoded and appended to the LSTM feature vector.

This tests whether latent market-state information improves neural network forecasting.


Evaluation Metrics

Each model was evaluated using:

  • Mean Absolute Error (MAE)
  • Root Mean Squared Error (RMSE)
  • R² Score
  • Directional Accuracy
  • Sharpe Ratio
  • Maximum Drawdown
  • Final Equity Curve

A simple long-short signal strategy with transaction costs was also simulated to evaluate economic usefulness.


Results

The experiment produced an unexpected result.

While the Hybrid HMM + LSTM consistently improved upon the standalone LSTM, none of the machine learning models outperformed the naive baseline out-of-sample.

This highlights an important lesson in quantitative finance:

Increasing model complexity does not necessarily improve predictive performance.


Key Takeaways

  • Chronological validation is essential for financial machine learning.
  • Naive benchmarks are surprisingly difficult to beat.
  • HMM-derived market regimes improved neural network performance but not enough to outperform a simple baseline.
  • Short-horizon return prediction remains an extremely challenging problem.

Repository Structure

Forecasting-Short-Term-NIFTY-Returns/

│ ├── data/ │ ├── results/ │ ├── model_comparison.csv │ ├── feature_correlation.png │ ├── hmm_regimes.png │ ├── residuals_grid.png │ ├── training_curves.png │ ├── predicted_vs_actual_grid.png │ ├── model_performance_summary.png │ └── comparison_equity_curves.png │ ├── main.py │ ├── requirements.txt │ └── README.md


Future Work

This project intentionally concludes with a negative result.

Rather than continuing to optimize return prediction, future work focuses on:

  • Market regime classification
  • Probabilistic forecasting
  • Multi-horizon market state prediction
  • Regime-aware decision support systems

Those ideas are implemented in the follow-up project:

NIFTY Market State Engine


Technologies Used

  • Python
  • TensorFlow / Keras
  • hmmlearn
  • NumPy
  • Pandas
  • Scikit-learn
  • Matplotlib
  • Seaborn

Author

Anand Rai

Quantitative Finance • Machine Learning • Systematic Trading

If you found this project useful, consider starring the repository.

About

A quantitative research project investigating short-term NIFTY return forecasting, demonstrating the challenges of outperforming a simple naive baseline with deep learning. Comparing Naive, HMM, LSTM, and Hybrid HMM-LSTM models for forecasting 25-minute NIFTY returns using out-of-sample evaluation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages