Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Identifying cointegrated pairs in a Sector

Guys,

I was playing around with identifying cointegrated pairs in MatLab with a large Algo that screened all potential combinations of pairs in the NYSE. However, I couldn't replicate the results in Q. Probably because my data source (Yahoo!) was not as accurate or my MatLab and/or Python skills were poor.

So I turned my attention to see if I could dynamically identify pairs in a Sector using Q. After playing around for a few months I came across Pravin's algo here: https://www.quantopian.com/posts/questions-on-trading-cointegrated-pairs

I am taking the concepts from that Algo and am trying to make it generic to cover all sectors. However, the algorithm seems to take too long to screen and is exiting as it is taking up too much time in the handle_data() method. I have currently set it up to use only one Sector (Energies) as per Pravin's implementation and am using the same search Query and Combination logic.

What am I doing wrong/different to Pravin's implementation?

In order to replicate the behaviour that I am seeing you have to change the following on line 21 from...

   context.fetch_prices = False  

to...

   context.fetch_prices = True