Visualizing risk factor correlation
Investment banks heavily invested in mortgage-backed securities (MBS) before and during the financial crisis. This makes MBS a likely risk factor for the investment bank portfolio. You'll assess this using scatterplots between portfolio returns and an MBS risk measure, the 90-day mortgage delinquency rate mort_del.
mort_del is only available as quarterly data. So portfolio_returns first needs to be transformed from daily to quarterly frequency using the DataFrame .resample() method.
Your workspace contains both portfolio_returns for an equal-weighted portfolio and the delinquency rate mort_del variable. For the scatterplots, plot_average and plot_min are plot axes in your workspace--you'll add your scatterplots to them using the .scatter() method.
Cet exercice fait partie du cours
Quantitative Risk Management in Python
Instructions
- Transform the daily 
portfolio_returnsdata into average quarterly data using the.resample()and.mean()methods. - Add a scatterplot between 
mort_delandportfolio_q_averagetoplot_average. Is there a strong correlation? - Now create minimum quarterly data using 
.min()instead of.mean(). - Add a scatterplot between 
mort_delandportfolio_q_mintoplot_min. 
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Transform the daily portfolio_returns into quarterly average returns
portfolio_q_average = portfolio_returns.____('Q').____.dropna()
# Create a scatterplot between delinquency and quarterly average returns
plot_average.____(____, portfolio_q_average)
# Transform daily portfolio_returns returns into quarterly minimum returns
portfolio_q_min = ____.resample('____').____.dropna()
# Create a scatterplot between delinquency and quarterly minimum returns
plot_min.scatter(____, ____)
plt.show()