Skip to content
All library documents

Cointegration Tests, Pairs Trading, and the Gap Between Statistical Fit and Profit

Article Quant Q&A · Author: TryingHardToBecomeAGoodPrSlvr

Summary

The author describes searching many stock pairs for cointegration using daily prices, estimating an ordinary least squares relationship from an initial sample, then testing a spread over later years. One apparently unrelated pair passed an augmented Dickey–Fuller test despite a spread chart that showed pronounced trends. A Bollinger Band strategy looked profitable before transaction costs, but adding a small assumed cost changed the outcome. The reported Sharpe ratio was modest.

The post raises practical and statistical questions: how to reduce trading costs, incorporate influences such as volatility or bond markets, and interpret cointegration when pairs may be unprofitable or non-cointegrated pairs may still trade well. In an edit, the author clarifies that the strategy trades deviations of the spread from a 15-day moving average; that deviation appears to have a more stable mean, though its variance changes. The post offers an exploratory example, not a validated strategy, and requests learning resources rather than establishing causal explanations or robust out-of-sample performance.

Key ideas

  • A pair can pass a cointegration test even when its plotted spread appears to trend over time.
  • Statistical cointegration alone does not establish that a pair is profitable to trade.
  • Transaction costs can materially change the apparent performance of a spread strategy.
  • The author’s Bollinger Band signals use deviations of the spread from a 15-day moving average.
  • The edited example suggests that the deviation may have a steadier mean while its variance varies.

Tags

Full text
# Research papers and other resources to learn about useful statistical tools for pairs trading


# Research papers and other resources to learn about useful statistical tools for pairs trading












Brief background: I recently started writing a Python code to find stocks which might be cointegrated. I iterated over a really long list of stocks trying to find a pair which might be cointegrated. To my surprise, I found many unrelated companies whose stocks were cointegrated.

I used daily data from yahoo finance, and I used just the first 90 days to find the OLS coefficients (OLS from statsmodels). The spread was found for years starting from 2015 till present. One of the strange pairs I found was that of Facebook and Sherwin Williams. The spread obtained is given below.

Now as you can see, this looks nothing like a stationary process. It shows very clear signs of trends during different periods. However, this passes ADF test with a very good confidence level.

A simple Bollinger Band strategy optimized for the best returns gives the following result.

Of course, just adding transaction cost of 5bps changes everything. After all, if it was this easy to make money, everyone one earth would have been rich!

I immediately had a few questions and also made a few observations.

- How can I minimize the effect of transaction costs?

- How can I use data that can potentially help with pairs trading? For instance, can I modulate the spread using data from VIX, and may be from bond ETF prices like HYG, to improve returns?

- Two seemingly unrelated stocks are cointegrated. What possible economic reason could result in such unrelated stocks to be cointegrated? Perhaps some big investment firm like Blackrock keeps rebalancing constantly, letting small traders pick up the "leaks"?

- There were certain pairs whose spread was not cointegrated. Nevertheless, the gain from pairs trading was significant. So just because a pair is not cointegrated does not mean they are not a profitable pair.

- Conversely, there were many cointegrated pairs which were not profitable no matter how I traded the spread. So just because I found a cointegrated pair does not mean the pair that they are profitable as a pair used in pairs trading.

- The so called Sharpe ratio was medicore (1 to 1.5 depending on certain factors).

- Most importantly, the spread looks nothing like a stationary process. Why then is it passing ADF test?

What I am looking for: There are books written on Statistics for finance. Tsay's book is highly recommended and I am yet to actually look at it.

However, I thought of asking the members of this forum if there is a good source to get answers to my questions above, and for learning about

- Statistics of cointegration and how it can be best used in trading

- Ways to include influencing factors, mostly interest rates, bond yields etc, in the process of pairs trading.

- How to minimize transaction costs?

It would be great to have some kind of undergraduate level reference which talks about the above points and perhaps more. Please let me know if there are such references available.

Edit 1 (Nov 2nd 2021, IST):

As I mentioned above, what we are actually doing is to trade the spread by buying one and shorting scaled version of the other stock, based on the relative position of the spread to its 15-day moving average. Hence the spread itself is not what we need to look at. It got me thinking that I should look at how the difference between the spread and the 15-day moving average, used by my Bollinger Band code, looks like. I have included that graph below.

Now this is beautiful. It is still not really stationary because it's variance seems to change quite a bit (and hence, the Bollinger band strategy actually adaptively keeps changing the "Band-Width"). But the mean is for sure constant. Also, the ADF test showed a really good number for the confidence that the unit-root null to be rejected. So all of this makes sense.

However, I would still like to know of resources (preferably undergrad level statistics book on cointegration for pairs trading, or maybe papers) which perhaps also includes some ideas on ways to reduce transaction costs.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.