Cointegration based predictive model
We will discuss an important strategy that traders can deploy on cointegrated data.
Cointegration is the basis of statistical arbitrage and can be considered a form of market inefficiency. Today, you will learn how to build a predictive model based on cointegration. You will also learn how to backtest a trading strategy built around the concept of cointegration.
How well does this strategy perform?
We have picked two possibly cointegrated assets: the S&P500 ETF "SPY" and an equal-weighted version of the SPY, the "RSP". The backtested results of applying this strategy on the daily returns data of the S&P500 index and RSP (during the period 1993 to 2022) are shown below:
The Python code for this strategy can be accessed here. You can access the code by taking a free preview of Section 5, Unit 1 of the “Trading Alphas: Mining, Optimisation, and System Design” course. It is important to note that backtesting results do not guarantee future performance. The presented strategy results are intended solely for educational purposes and should not be interpreted as investment advice. A comprehensive evaluation of the strategy across multiple parameters is necessary to assess its effectiveness.
Market inefficiencies occur when the price of a security does not accurately reflect its true value, resulting in trading opportunities.
Cointegration as a Market Inefficiency
Ideally, two assets that are cointegrated tend to move in the same direction. In other words, even if these two assets move away from the same path, they are bound to come back to the same path. Therefore, by going long on one asset and shorting the other, in the right proportion, which is also known as the hedge ratio, we can generate a predictive model of the movement of the two assets.
We plotted the cumulative returns of the two assets RSP and SPY and this is what it looks like:
Visually, our hypothesis has been confirmed. Even if both assets deviate from the same path they are reverting back to it.
What is a hedge ratio and how do we calculate it?
The hedge ratio will tell us the long/short proportion for one asset (RSP) against every unit of the other asset (SPY). It is calculated by fitting a line on the correlated data, usually, this is the returns data but in this case, we have used the cumulative returns data. If the data for the two assets is not correlated, then it may not be possible to calculate a meaningful hedge ratio. The hedge ratio is a measure of the sensitivity of one asset to changes in another asset, and it is only relevant when there is a strong relationship between the two assets. Further, it looks something like this:
Here, the hedge ratio is 0.88.
Before we get to the trading rules, you need to first calculate the spread:
The hedge ratio will help us create a spread between SPY and RSP. To calculate the spread, we multiply the hedge ratio by the price of RSP. Then, deduct the price of SPY from it, and finally, add the constant 0.0535.
How do we trade the spread?
Buy the spread: Go long on RSP and short SPY whenever the price drops below -0.05.
Sell the spread: Go short on RSP and long SPY whenever the price rises above 0.05.
The 0.05 threshold was selected arbitrarily, and one could also express it in standard deviations from the mean rather than a fixed value. We exit our trades when the spread crosses the zero line.
Backtested Results
If we backtest our strategy on this cointegrated data, the results look like this:
The strategy has not generated any signals after July 2021; this is because the two assets have not drifted apart since then. Over the backtested duration, i.e. in 12 years, the strategy has generated a cumulative PnL of nearly 16%. The returns are not very impressive when we compare them to the market prices of the two assets. You can backtest this strategy on a number of cointegrated assets, but keep in mind that the returns will completely depend on the level of cointegration between the two assets.
Conclusion
Statistical arbitrage strategies such as these can be useful tools for investors to exploit market inefficiencies and generate profits by simultaneously buying and selling two correlated assets, but it requires careful research and risk management to be successful. Learn more about such strategies and how you can create and backtest them with the Mean Reversion Strategies in Python course on Quantra.
IMPORTANT DISCLAIMER: This email is for educational purposes only and is not a solicitation or recommendation to buy or sell any securities. Investing in financial markets involves risks and you should seek the advice of a licensed financial advisor before making any investment decisions. Your investment decisions are solely your responsibility. The information provided is based on publicly available data and our own analysis, and we do not guarantee its accuracy or completeness. By no means is this communication sent as the licensed equity analysts or financial advisors and it should not be construed as professional advice or a recommendation to buy or sell any securities or any other kind of asset.