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.
This exercise is part of the course
Quantitative Risk Management in Python
Exercise instructions
- Transform the daily
portfolio_returns
data into average quarterly data using the.resample()
and.mean()
methods. - Add a scatterplot between
mort_del
andportfolio_q_average
toplot_average
. Is there a strong correlation? - Now create minimum quarterly data using
.min()
instead of.mean()
. - Add a scatterplot between
mort_del
andportfolio_q_min
toplot_min
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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()