Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
pairs trading theory: which stock in a pairs trade do we "add_constant" to?

I've got a theory question in regards to Lecture 44: Introduction to Pairs Trading.
In the video, near the 32nd minute onward, there is a reference to adding a 'constant' to one of the data series (in the video it was for ticker AGBG).

My question is the following:
1. Should we apply the constant to the cheaper of the two stocks? ie: whichever price series is lower than the other, add the constant to that stock.
2. If Q-1 is true, then does that mean that stock 1 should always be the cheaper stock, stock 2 should be the higher stock, so that when we use methods coint and OLS they are set accordingly?
example: coint method arguments are S1, S2 whereas OLS method arguments are S2, S1

Any clarification would be great. Thank you.

7 responses

Hey Antonio,

Great question. Cointegration is not a directional relationship, it's closer to correlation in that it doesn't say anything about causation. Alternatively, OLS is usually used in circumstances where you have a hypothesis that the independent variable (X in Y = bX+a) causes variance in the dependent variable (Y). Because we generally don't have a hypothesis about which stock is causing variance in the other, I don't think it should matter too much which direction you do the regression, but it's definitely worth playing around and testing this, as I haven't actually checked that myself. All we're really checking is whether the two have a stationary residual, this lecture might be helpful in understanding everything:

https://www.quantopian.com/lectures/integration-cointegration-and-stationarity

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.

Delaney,

That makes perfect sense. Thank you for the explanation. Just a follow-up question from the link you provided.

I've noticed two methodologies for measuring cointegration:

Method 1) using statmodels.tsa.stattools.coint method, we simply use the stock prices to identify cointegration.

Method 2) using adfuller method, in these steps: (1) adding constant, (2) running OLS regresion, (3) finding beta, (4) computing spread = S2 -b*S1
and using spread to measure cointegration.

Which one of the methods is correct?

Thank you!

Both are fine, the coint method is really just doing 2) under the hood.

https://www.statsmodels.org/dev/_modules/statsmodels/tsa/stattools.html#coint

Method 2) might be better if you want more fine grained control, or have a more clever way of finding a stationary linear combination. Remember the OLS is just an attempt to estimate a parameter of a stationary linear combination, so you can definitely get more creative.

In general though you want to be finding a lot of pairs to have a well diversified algorithm, so you probably want to either design a new method that can be run quickly, or just use the built in coint method.

This is exactly what I was looking for in terms of an explanation. Thanks Delaney!

Happy to help.

Delaney,

Another follow-up question! Is there a notebook or lecture on how to build a portfolio of pairs? I'm looking for an explanation/guidance on how to build a portfolio for a pairs trading model (not just one pair, but hundreds of pairs that over time have entry signals at different dates).

Any guidance to that would be great. Thank you.

Hey Antonio,

We don't have any great content on this, the best we have right now is our multi-pair algorithm template. https://www.quantopian.com/lectures/example-pairs-trading-algorithm

The issues that you generally want to think about are:

  1. How correlated/uncorrelated are the spreads?

  2. How do you allocate capital between the pairs?

  3. How do you turn pairs on/off?

Sorry we don't have more right now.