Skip to content

About

Statistical arbitrage pipeline using Cointegration, GARCH, ARIMA, and XGBoost for spread prediction and pairs trading on Indian banking equities.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Statistical Arbitrage on Indian Banking Equities

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.


Overview

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.


Objectives

  • 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

Dataset

  • Stocks: HDFC Bank (HDFCBANK.NS) & Kotak Mahindra Bank (KOTAKBANK.NS)
  • Source: Yahoo Finance
  • Period: January 2016 – 2025
  • Frequency: Daily Adjusted Closing Prices

Methodology

1. Data Collection & Preprocessing

  • Downloaded historical stock prices using yfinance
  • Applied log-price transformation
  • Performed data cleaning and preprocessing

2. Cointegration Analysis

Verified the long-run equilibrium relationship using:

  • Engle-Granger Cointegration Test
  • Augmented Dickey-Fuller (ADF) Test
  • KPSS Test

3. Spread Construction

  • Estimated the hedge ratio using Ordinary Least Squares (OLS)
  • Constructed the mean-reverting spread

[ Spread = \log(HDFC) - \beta \times \log(Kotak) ]

4. Mean Reversion Analysis

  • Estimated half-life of mean reversion
  • Generated rolling Z-score based trading signals

5. Volatility Modeling

  • Implemented rolling GARCH(1,1) to estimate conditional volatility

6. Dynamic Hedge Ratio

  • Applied a Kalman Filter to estimate a time-varying hedge ratio

7. Time Series Forecasting

  • Built an ARIMA model
  • Performed one-step-ahead forecasting using walk-forward validation

8. Machine Learning

  • Developed an XGBoost Classifier to predict next-day spread direction using engineered statistical features

9. Backtesting

Evaluated the strategy using:

  • Walk-forward validation
  • Sharpe Ratio
  • Win Rate
  • Maximum Drawdown

Technologies Used

  • Python
  • Pandas
  • NumPy
  • Matplotlib
  • yfinance
  • Statsmodels
  • ARCH
  • Scikit-learn
  • XGBoost

Results

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.

Future Improvements

  • Multi-pair portfolio optimization
  • Transformer/LSTM-based forecasting
  • Bayesian hyperparameter optimization
  • Reinforcement Learning for position sizing
  • Live paper trading integration

License

This project was developed for academic and educational purposes.

About

Statistical arbitrage pipeline using Cointegration, GARCH, ARIMA, and XGBoost for spread prediction and pairs trading on Indian banking equities.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages