A look at cover pairs trading for stocks, a statistical arbitrage strategy, which is based on the mean reversion principle for Algo trading.
In the previous article, you learned one of the most popular quantitative trading strategies: momentum trading . In this article, we will cover pair trading for stocks, a statistical arbitrage strategy, which is based on the mean reversion principle.In pairs trading, one financial instrument (or a basket of instruments) is traded against another financial instrument (or a basket of instruments). Pairs trading in stocks have two components:
- Identify a pair of stocks
- Determine entry and exit points
Let’s start with the first component.
How to choose stocks for pair trading?
The first step in choosing a pair is to analyse the stocks qualitatively. Generally, we select a pair of companies from the same sector, for example, Kotak Bank and HDFC Bank. It could be further refined based on other factors like companies with similar size or market capitalization such as ACC and Ambuja Cement or companies managed by the same management such as Bajaj Finance and Bajaj Finserv. After qualitative analysis, you can apply statistical and mathematical tools to finalize the pairs to trade. Stationarity is one of the properties of time series, which is a prerequisite for pairs trading.
What is a stationary time series?
A time series is said to be stationary if its statistical properties does not change over time. If the time series is stationary, you can profit from the mean-reverting strategy, buy low and sell high. For individual stocks, the time series of stock prices are generally not stationary.
You can create a portfolio of two price series such that the linear combination of these is stationary. If the linear combination of two price series is stationary, then the individual price series is said to be co-integrated with each other.
Let’s say there are two stocks A and B. Linear combination of these two stocks can be defined as
Spread = y - m *x
Here, y and x are prices of stock A and B respectively and m is the number of stocks of B you sold for each stock of A that you bought.
If the above equation is stationary, then we can say that stock A and B are co-integrated with each other, and you can implement mean reversion strategy by going long on one stock and selling the other stock.
But the question is, how do we know whether two stocks are co-integrated or not. You can use the Augmented Dickey-Fuller Test (ADF) to test the co-integration of two price series. The idea behind the ADF test is to first determine the optimal hedge ratio (the value of ‘n’ in the spread equation) by running a linear regression between two price series. Using this hedge ratio, we complete the equation of the spread and then finally run the ADF test on this to determine if the spread is stationary or not.
ADF test is a hypothesis test where the null hypothesis is that the portfolio is not stationary, and the alternative hypothesis is that the portfolio is stationary. When we run the ADF test on a portfolio, it gives the value of test statistics and critical value at a different confidence level. If the test statistic is less than the critical value at a certain confidence level, then we can reject the null hypothesis that the portfolio is not stationary which means the portfolio is stationary at the given confidence level. However, the results of ADF test are order dependent. That is, the results will vary based on which stock is set as y and which stock as x while computing the spread. If you want to get order independent results then you can use Johansen Test.
Determine entry and exit points
After finding the cointegrated pair of stocks, you need to determine the entry and exit points. You can enter and exit the position by creating bands, similar to Bollinger bands, around the spread. Bollinger bands consist of three bands. The upper band is ‘x’ standard deviations above the moving average of the spread, the middle band is the moving average of the spread, and the lower band is ‘x’ standard deviations below the moving average of the spread.
One of the entry & exit approaches can be to buy the spread whenever the spread crosses below the lower Bollinger band and exit the position when it reaches to the middle band. Similarly, if spread crosses above the upper Bollinger band, then sell the spread and exit the position when it reaches to the middle band.
Pairs trading often hedges market risk to a certain extent from adverse market movements, i.e. make the strategy market neutral. However, in some cases, spread doesn’t revert to the mean. To prevent such an unexpected event, we need to place a stop loss. For example, if we choose entry signals at 2-sigma, we are expecting that the spread will revert to the mean from this threshold. However, let’s say the spread continues to move away from the mean. In such scenarios, to prevent losses, you can place a stop loss say at 3-sigma. You can set the threshold based on your risk appetite or based on the average loss of losing trades in the backtest. Sometimes cointegration between pairs breaks for an extended period. Trading pairs during this period led to an unprofitable trade. It is recommended to exit the position in such scenarios. But you can continue paper trading these pairs to see when cointegration is turning around.
This is the basic framework for pairs trading. You can apply the same concept on a universe of stocks and generate potential stock pairs. You can even backtest pairs trading strategy on ACC and Ambuja Cements on QuantraBlueshift for free, by selecting the template Pairs Trading Strategy.
Hope this gives you a good insight into the world of pair trading & statistical arbitrage. In the next article we will be sharing domain insights into the algorithmic & quantitative trading space to help you #GoAlgo!(The author is the co-founder of QuantInsti, a Quantitative & Algorithmic trading training institute .) This article is part of a series covering various aspects of Quantitative & Algorithmic Trading, including the strategies across various asset classes, techniques, infrastructure requirements, regulations and skills required in this domain.