Visualize your index constituent correlations
To better understand the characteristics of your index constituents, you can calculate the return correlations.
Use the daily stock prices or your index companies, and show a heatmap of the daily return correlations!
Cet exercice fait partie du cours
Manipulating Time Series Data in Python
Instructions
We have already imported pandas as pd, matplotlib.pyplot as plt, and seaborn as sns. We have also loaded the historical price series of your index constituents into the variable stock_prices.
- Inspect
stock_pricesusing.info(). - Calculate the daily returns for
stock_pricesand assign the result toreturns. - Calculate the pairwise correlations for
returns, assign them tocorrelationsand print the result. - Plot a
seabornannotated heatmap of the daily return correlations with the title'Daily Return Correlations'.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Inspect stock_prices here
print(____)
# Calculate the daily returns
returns = ____
# Calculate and print the pairwise correlations
correlations = ____
print(____)
# Plot a heatmap of daily return correlations