Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
$GLD/$IAU Pairs trading template

I coded up this $GLD/$IAU pairs trading algo based on the demo from our most recent NYC Algo Trading meetup last week (http://www.meetup.com/NYC-Algorithmic-Trading/events/142412082/)

The algo computes an OLS regression between GLD and IAU based on the last 50 days' prices. It then places $500,000 (per side, long and short) bets on mean reversion every time the spread between the two instruments diverges more then 2 standard deviations from the 50-day trailing mean spread (based on the z-score, which is plotted here).

As we discussed at the meetup, the GLD/IAU pair is a good mechanical example, but is not a profitable trade. However this algo should be able to serve as a template to test other interesting pairs trades - would love to see others post suggestions!

NB: This example also gives a sneak preview of Quantopian's new 'history' API which allows you to store up trailing daily pricing data inside of a minute-level backtest. More docs on this feature will be coming, but you can play around with it now if you'd like.

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.

4 responses

Thanks Jess,

Have you tried a cointegration test on the pair? For an example, see https://www.quantopian.com/posts/augmented-dickey-fuller-adf-test-spy-and-sh-dollar-volume.

[EDIT] I'm wondering if a cointegration test should be part of the algorithm?

Grant

Hi Grant,

So this is just an example of an implementation of a pairs trade - there is an implicit assumption baked in that these stocks are cointegrated and therefore viable for pair arbitrage.

It is a whole other question (and a much harder question) to talk about how to find good candidates for pairs trading, and certainly a cointegration test can be used to validate the hypothesis that you've found a good pair.

I think many folks would argue that analysis of company fundamentals is the best place to start when looking for pairs. At the NYC meetup where this strategy was presented our speaker gave the super-simple starting point of looking at a company's peers on their Google or Yahoo finance page.

-Jess

Thanks Jessica,

It seems that there needs to be some test, as part of the algorithm, that monitors the degree of conintegration. Or is this done offline?

Grant