Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pipeline for finding closely correlated stocks?

Hi,

I am looking to build a pipeline to select pairs of closely correlated stocks from the general stock market for a paired mean-reversion algorithm I have been working on, yet none of my research has found anything to assist me with this problem. Please note that I am very much a beginner, but have some experience with python prior to using Quantopian. Please answer ASAP.

Thanks,

Earlybird

2 responses

You could run a correlation matrix fairly easily on a set of .csv files using pandas: https://stackoverflow.com/questions/29432629/plot-correlation-matrix-using-pandas

You can download the .csv files from yahoo finance fairly easily and then using the correlation matrix function you could rank them by how closely they are correlated.

One thing I failed to mention, it is important to use the log returns and not absolute returns when doing the correlation study.

see:
https://www.quantopian.com/posts/correlation-between-prices-or-returns
or
https://quantivity.wordpress.com/2011/02/21/why-log-returns/