An end-to-end quantitative trading pipeline using Cointegration, GARCH, ARIMA, and XGBoost to identify, model, and forecast mean-reverting opportunities between Indian banking equities.
This project implements a complete statistical arbitrage (pairs trading) strategy using HDFC Bank and Kotak Mahindra Bank. Rather than predicting individual stock prices, it models the spread between two historically related assets and exploits temporary deviations from their long-run equilibrium.
The workflow combines classical econometric methods, time-series forecasting, volatility modeling, and machine learning to generate market-neutral trading signals and evaluate strategy performance.
- Identify statistically cointegrated stock pairs
- Construct a market-neutral trading spread
- Model spread volatility
- Forecast future spread values
- Generate quantitative trading signals
- Predict next-day spread direction using machine learning
- Evaluate strategy performance through backtesting
- Stocks: HDFC Bank (HDFCBANK.NS) & Kotak Mahindra Bank (KOTAKBANK.NS)
- Source: Yahoo Finance
- Period: January 2016 – 2025
- Frequency: Daily Adjusted Closing Prices
- Downloaded historical stock prices using
yfinance - Applied log-price transformation
- Performed data cleaning and preprocessing
Verified the long-run equilibrium relationship using:
- Engle-Granger Cointegration Test
- Augmented Dickey-Fuller (ADF) Test
- KPSS Test
- Estimated the hedge ratio using Ordinary Least Squares (OLS)
- Constructed the mean-reverting spread
[ Spread = \log(HDFC) - \beta \times \log(Kotak) ]
- Estimated half-life of mean reversion
- Generated rolling Z-score based trading signals
- Implemented rolling GARCH(1,1) to estimate conditional volatility
- Applied a Kalman Filter to estimate a time-varying hedge ratio
- Built an ARIMA model
- Performed one-step-ahead forecasting using walk-forward validation
- Developed an XGBoost Classifier to predict next-day spread direction using engineered statistical features
Evaluated the strategy using:
- Walk-forward validation
- Sharpe Ratio
- Win Rate
- Maximum Drawdown
- Python
- Pandas
- NumPy
- Matplotlib
- yfinance
- Statsmodels
- ARCH
- Scikit-learn
- XGBoost
The project demonstrates a complete quantitative trading workflow by integrating classical econometric methods with machine learning.
Key outcomes include:
- Identified a statistically significant cointegrated relationship between HDFC Bank and Kotak Mahindra Bank (Engle-Granger p-value = 0.0008).
- Estimated a half-life of mean reversion of ~42 trading days, providing a data-driven holding period for the strategy.
- Built a rolling GARCH(1,1) model using a 100-day estimation window, generating 2,436 one-step-ahead volatility forecasts.
- Developed an ARIMA(0,1,1) forecasting model with walk-forward validation, achieving an RMSE of 0.01596 on one-step-ahead spread prediction.
- Engineered statistical features and trained an XGBoost classifier for next-day spread direction prediction using TimeSeriesSplit cross-validation.
- Evaluated the complete strategy using walk-forward backtesting and quantitative risk metrics including Sharpe Ratio, Win Rate, and Maximum Drawdown.
- Multi-pair portfolio optimization
- Transformer/LSTM-based forecasting
- Bayesian hyperparameter optimization
- Reinforcement Learning for position sizing
- Live paper trading integration
This project was developed for academic and educational purposes.