Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Portfolio Risk Management in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Calculate the correlation matrix
correlation_matrix = ____

# Print the correlation matrix
print(correlation_matrix)
Code bewerken en uitvoeren