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

I want to build a strategy that determines the mean spread and associated z-scores for two stocks between 2012&14. I then want the strategy to go long or short today's prices depending on whether the current spread is below or above the mean spread. It would close these positions as the spread returns to the mean spread. I understand that this is vulnerable to changes in the relationship of the two stocks over time since it is using a fixed window to calculate the mean spread and z-scores.

I looked at this algo but couldn't get it to work when calculating the z-score / mean spread over a defined period: https://www.quantopian.com/posts/$gld-slash-$iau-pairs-trading-template

1 response

Hey,

I always find the lectures super helpful. They cover pairs trading: https://www.quantopian.com/lectures have you gotten one of their basic examples working?