ComeçarComece de graça

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.

Este exercício faz parte do curso

Introduction to Portfolio Risk Management in Python

Ver curso

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Calculate the correlation matrix
correlation_matrix = ____

# Print the correlation matrix
print(correlation_matrix)
Editar e executar o código