Back to Community
Pairs Trading - Cointegration & stationarity?

1) Are two time series cointegrated (and hence candidates for pairs trading) only if they are non-stationary AND the difference between the two are non-stationary?

2) If #1 is correct, how often do you check to see that the cointegration relationship has (or has not) broken (and thus stop the position on the two)?

4 responses

Hey TaeWoo,

Good question.

1) No, the point of cointegration is that the non-stationarity in one 'explains' the non-stationarity in the other. You can think of it as the residuals being stationary when you use a linear model with one as the independent and one as the dependent variable.

2) You still want to regularly check to make sure the cointegration relationship hasn't broken on a regular basis. The problem of course is multiple comparisons bias. If you run a test 10 times per day that has a 5% false positive rate, over 10 days you should expect 10 false positives. In general I think a good way is to re-run the test either on a regular (maybe once a month) frequency manually in research, or to run it each time before you place a trade. You can use the cointegration test we defined in the notebook, or use something like the hurst exponent.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hey Delaney.
Thanks for that answer. I ran a ton more tests since your reply. I watched the talk on coint and non-stationarity 3x more times. Now im beginning to understand.

Questions
1) Does the time duration of two time series being co-integrated almost always disintegrate?

2) If I mitigate noise (say applying kalman filter or using statsmodels.tsa.seasonal.seasonal_decompose to extract the resid) and applying coint check, is there something fundamentally wrong with that? I feel like im running into multiple comparison bias, but I wanted to check

(BTW, kalman / coint seems to fail if the price series / coin fails)

Kalman filters in Quantopian Lectures for reference, 45 has the backtest. Lectures navigation seems to have changed recently, here's the current link: https://www.quantopian.com/lectures/example-kalman-filter-pairs-trade. 23 and 24 are a couple of others with pairs trading backtest examples and there's also even a Futures example for pairs now, lecture 50.

Sorry about the late response, I was out of the office on vacation.

1) Cointegration almost always disintegrates over sufficiently long timeframes. The longer the timeframe, the greater the chance that the anomaly will be discovered by others, and the greater the chance that an event will cause the relationship to break down.

2) The more complex your model, the greater the risk of it breaking at some point. However denoising and demeaning techniques are very common, so what you're doing sounds fairly safe.