Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
First algo: pair trading a portfolio with a test for cointegration via Engle-Granger and Augmented Dickey Fuller

The algorithm takes as input a set of pairs and trades them in a portfolio. I conducted an off line analysis for the time period 1/1/2011-12/31/2011 to find a list of pairs that may be cointegrated and traded them during the periods 1/1/2012-12/31/2012. The signals are: If the pairs is cointegrated and the difference in normalized price is > 2 x historical standard deviation then enter the trade; sell when the difference in normalized prices cross the historical average.

The algorithm is picky and rarely enters trades but my results fall in line with how a pair trade should perform. Let me know if you see any errors!

4 responses

I cloned your algorithm which could not generate any trade.

Hello David,

I think you need to turn off date checking but there seems to be a new bug where this doesn't work. I've tried Chrome and Firefox.

P.

It's an incredibly picky algorithm. I wish there were a better way to test for cointegration where I was able to use minute data for a year and store a list of pairs that I could trade in any year. Currently, before placing a trade it checks for cointegratgion using daily data for the last 250 days -- which is an incredibly sensitive signal.

@Peter,

The security GAS stopped trading on 12/09/2011, so when you cloned the algo and tried build a quick backtest you saw the auto-adjusted end date. If you run a full backtest, the end dates are not auto-adjusted, so Zachary was able to run the algo until 12/31/2013.

To share an algo in the forums, you need to run it with a full backtest. This does indeed sound like a bug and we'll get it fixed!

Alisa

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.