/ Aug 15, 2021

How to Calculate Correlation Between Stocks

Investors have a long list of theories to choose from when it comes to crafting their investment strategy. One approach that remains particularly popular, however, is assessing the correlation between stocks in a portfolio.Modern Portfolio Theory, or MPT, argues you can maximize returns for a given level of risk by collecting assets based on their correlations. For instance, it proposes that collecting uncorrelated assets may protect a portfolio from fluctuations by reducing the probability of asset prices moving together. Many investors seek to diversify their portfolios for these reasons. But how do you make those calculations? In this video tutorial, JP Hwang demonstrates how to crunch the numbers and find correlation – which you can then use to inform how you construct your own portfolio and minimize risk.


0:00: Introduction and background on IEX Cloud

0:35: Background on volatility and correlation

4:45: Automation is the answer: why use Python

5:38: First example and dataset (load data, create a pivot table, calculate correlation)

8:45: Next dataset (plotting, pivot data, and calculate correlation, the Pearson r function)

10:30: Our first real-life dataset (loading, cleaning, calculating correlation)

13:45: Working with a larger dataset (importing, inspecting, calculations, plotting)

17:22: Working with a DataFrame (converting correlation coefficient, extracting a ticker)

18:55: Identifying least corelated symbols

25:10: Creating an “average” data series and comparing to individual stocks

27:22: Getting started with IEX Cloud: finding data, starting for free, and sandbox mode

30:45: Closing remarks and about the Community BlogTo see the full written tutorial step-by-step – including links to code – visit our other blog post, “Portfolio Risk Management: From Correlation to Diversification”:

Get the full tutorial code:

Disclaimer: IEX Cloud Services LLC makes no promises or guarantees herein regarding results from particular products and services, and neither the information, nor any opinion expressed here, constitutes a solicitation or offer to buy or sell any securities or provide any investment advice or service.

Similar videos