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.