Get startedGet started for free

The correlation matrix

The correlation matrix can be used to estimate the linear historical relationship between the returns of multiple assets. You can use the built-in .corr() method on a pandas DataFrame to easily calculate the correlation matrix.

Correlation ranges from -1 to 1. The diagonal of the correlation matrix is always 1, because a stock always has a perfect correlation with itself. The matrix is symmetric, which means that the lower triangle and upper triangle of the matrix are simply reflections of each other since correlation is a bi-directional measurement.

In this exercise, you will use the seaborn library to generate a heatmap.

This exercise is part of the course

Introduction to Portfolio Risk Management in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the correlation matrix
correlation_matrix = ____

# Print the correlation matrix
print(correlation_matrix)
Edit and Run Code