Mean-Reversion Trading with Statistical Arbitrage Pair Trading Strategy Across Different Sectors in the Indian Markets | EPAT Project

5 min read

By Vivek Jain

This project aims to develop and evaluate a statistical arbitrage pair trading strategy applied across various sectors of the Indian stock market. Using historical price data, this statistical arbitrage trading strategy identifies cointegrated pairs within sectors and generates trading signals based on their spread. The project is designed to explore the mean-reverting behaviour of stock pairs, leveraging statistical techniques to create a market-neutral portfolio and achieve diversification.

Key Objectives:

  • Identify cointegrated stock pairs within specific sectors of the Indian stock market.
  • Utilize advanced statistical testing, such as the Augmented Dickey-Fuller (ADF) test, to validate the stationarity of the spread.
  • Design and implement a trading strategy based on the mean-reverting characteristics of the identified pairs.

Why Statistical Arbitrage?

Statistical arbitrage in pair trading is a popular technique for exploiting temporary price deviations between related securities. This method is widely favoured for its ability to reduce market risk by focusing on relative performance rather than absolute market trends. The hedge ratio, calculated through regression, helps create balanced positions in pairs, enhancing the strategy's robustness.

This approach is particularly useful for:

  • Market-Neutral Trading: Mitigating exposure to broader market movements.
  • Risk Diversification: Distributing investments across sectors.
  • Quantitative Precision: Leveraging statistical tests to refine trading decisions.

Project Methodology Overview

The project involves identifying and analysing cointegrated stock pairs across sectors, calculating spreads, and applying Bollinger Band and Z-score strategies for signal generation. The strategy is backtested using Python libraries such as pandas, numpy, and statsmodels to validate its performance.


Who is this blog for?

This project is ideal for:

  • Traders and Investors looking to incorporate quantitative techniques into their strategies.
  • Quantitative Analysts seeking hands-on exposure to statistical arbitrage.
  • Students and Researchers interested in practical applications of market-neutral strategies.

By focusing on market-neutral strategies, this project provides a practical framework for those looking to deepen their understanding of statistical arbitrage.


Prerequisites

To fully benefit from this project and understand its methodologies, you should:

  1. Have a basic understanding of pair trading and statistical arbitrage concepts, as outlined in Pair Trading – Statistical Arbitrage On Cash Stocks.
  2. Be familiar with the application of statistical arbitrage in diverse markets, such as:
  1. Understand advanced techniques like the Kalman Filter for market analysis, as demonstrated in Statistical Arbitrage using Kalman Filter Techniques.
  2. Have explored the steps for selecting statistically cointegrated pairs in the context of arbitrage, as detailed in Selection of Pairs for Statistical Arbitrage.
  3. Be aware of practical project examples from the EPAT program, including Jacques’s Statistical Arbitrage Project.

For additional background on statistical arbitrage and mean reversion, browse blogs on Mean Reversion and Statistical Arbitrage.


Project Motivation

Statistical arbitrage pair trading involves identifying pairs of stocks that exhibit mean-reverting behavior. This strategy is widely used to exploit temporary deviations in the relative prices of the pairs. This project explores the application of statistical arbitrage in different sectors of the Indian market, motivated by the potential for market-neutral profits and risk diversification.


Project Summary

This “Statistical Arbitrage Pairs Trading” strategy in NSE-listed stocks of different sectors leverages quantitative precision and risk hedging to make data-driven trading decisions. By identifying cointegrated stocks from various sectors, the strategy focuses on the statistical relationship between asset pairs, specifically their spread or hedge ratio, to minimize market-wide risk.

The hedge ratio is determined using Ordinary Least Squares (OLS) regression, which helps balance positions between the two assets. Spreads are calculated and tested for stationarity using the Augmented Dickey-Fuller (ADF) test, selecting pairs with atleast 90% statistical significance.

The strategy is executed by going long when the spread falls below a predefined threshold and closing the position when it reverts to the mean. Conversely, short positions are opened when the spread exceeds the threshold and closed once the spread returns to the mean. This method enhances discipline, reduces emotional bias, and provides a more robust and reliable approach to market-neutral trading.


Data Mining

Historical price data for stocks in different sectors of the Indian market is sourced from Yahoo Finance.  The data includes adjusted closing prices for selected pairs of stocks spanning from January 1, 2008, to  December 31, 2014. The data is downloaded and processed using the yfinance Python library.


Data Analysis

The project involves the following steps:

1. Pair Selection: Identifying pairs of stocks within the same sector that are likely to be  cointegrated.

2. Cointegration Testing: Applying the Augmented Dickey-Fuller (ADF) test on the spread to  verify the cointegration of pairs.

3. Spread Calculation: Calculating the spread between the cointegrated pairs.

4. Trading Signals: Generating trading signals based on the spread's mean-reverting behavior.


Key Findings

• Certain pairs within sectors demonstrate significant cointegration, validating the potential for  pair trading. The spread between cointegrated pairs tends to revert to the mean, creating  profitable trading opportunities.

• In some stocks, even when the p-value is significant, the overall strategy is not profitable.

During our testing period, the Bollinger Band strategy was found to be more effective than the  Z-score strategy.


Challenges/Limitations

• The accuracy of cointegration tests and trading signals is influenced by market volatility and  external factors.

• Execution risk and transaction costs may affect the real-world profitability of the strategy.

• Fundamental differences among stocks within certain sectors, such as Pharma, may hinder the  identification of profitable pairs.


Implementation Methodology (if live/practical project)

The project is implemented using Python, leveraging libraries such as pandas for data manipulation,  numpy for numerical operations, statsmodels for statistical testing, and yfinance for data retrieval. The  methodology involves:

1. Downloading Data: Retrieving historical price data for selected stocks.

2. Calculating Cointegration: Using the ADF test to identify cointegrated pairs.

3. Calculating Spreads: Computing the spread between cointegrated pairs.

4. Generating Signals: Implementing the Bollinger Band and Z-score strategies to generate buy and sell signals.

5. Calculating Returns: Computing log returns for the strategy and evaluating performance.


Annexure/Codes

The complete Python code for implementing the strategy is provided, including data download,  cointegration testing, spread calculation, signal generation, and performance analysis.


Conclusion

The statistical arbitrage pair trading strategy offers a systematic approach to trading pairs of stocks within the Indian market. While it shows potential, the strategy's effectiveness varies across sectors and individual pairs. Further refinement and testing are required to enhance its robustness and applicability in real-world trading scenarios.

Learn more with the course on Statistical Arbitrage Trading. The course will help you learn to use statistical concepts such as co-integration and ADF test to identify trading opportunities. You will also learn to create trading models using spreadsheets and Python and backtest the strategy on commodities market data.

Here is the link to the Quantra course: https://quantra.quantinsti.com/course/statistical-arbitrage-trading?



File in the download

  • Pairs Trading - Bollinger Band Strategy - Python notebook


About the Author

Author - mean reversion trading with statistical arbitrage | Vivek Jain
Author of the EPAT Project | Vivek Jain

About the Author

Vivek Jain is a Certified Financial Technician (CFTe) and has completed all levels of the Chartered Market Technician (CMT, USA) program. With over four years of full-time experience in trading equities and futures. He applies advanced Technical Analysis and Quantitative methods to drive superior performance.

He participated in the CMT Association’s Global Investment Challenge in August 2023 and September 2022, where he successfully qualified out of more than 1,000 registrants from 47 countries and 45 universities by trading S&P 500 stocks.

Specializing in designing and implementing systematic portfolio trading systems, he is currently focused on developing advanced mean reversion strategies and quantitative long/short strategies, utilizing sophisticated statistical techniques to enhance returns and optimize risk management.

In a recent project for a multinational corporation, Vivek built a Mutual Fund ranking system in Python, integrating historical NAVs and multiple performance metrics. His deep market knowledge and technical expertise enable him to excel in complex, data-driven environments.

He aspires to secure a Quantitative Strategist role, where he can harness his domain knowledge and trading experience to create resilient, alpha-seeking algorithmic models for multiple asset classes.


Disclaimer:The information in this project is true and complete to the best of our Student’s knowledge. All recommendations are made without guarantee on the part of the student or QuantInsti®. The student and QuantInsti® disclaim any liability in connection with the use of this information. All content provided in this project is for informational purposes only and we do not guarantee that by using the guidance you will derive a certain profit.

Live Q&A | Skills to Get Quant Jobs