Learn how to use Python to identify similarities in stock movements

Note from Towards Data Science’s editors:_ While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details._


Whether you are crafting a portfolio and want to incorporate diversification or trying to find stocks for a Pairs Trading strategy, the ability to calculate the correlation between the movement of two stocks is a must.

Having a portfolio of stocks that are not closely correlated allows you to tap into different performing assets that will likely not drop too much together. For example, owning a portfolio of only airline stocks during the pandemic would have you down an average of about 38% on the year. However, by diversifying the portfolio with a combination of stocks from technology, retail, or virtually any other sector, the loss would be a lot less (if any at all).

Unless you are using a Pairs Trading strategy, the best bet is to lower the amount of correlation in your portfolio to maximize the amount of diversification! And that is what we’ll be doing today — calculating and sorting the correlation between a list of stocks. The process is entirely intuitive and by the end of this article, you too should be able to recreate the program within minutes and only a few lines of code!

The entire code to the project in this article is within this GitHub Gist.

#investing #finance #data-science #python #programming

Find Highly Correlated Stocks with Python!
1.95 GEEK