Volatility and structural breaks
Visualizing volatility changes helps reveal possible structural break points in time series. By identifying when volatility appears to change, an informed choice of break point can be made that can, in turn, be used for further statistical analysis (such as the Chow test).
You'll examine two visualizations of volatility for the investment bank portfolio from 2008 - 2009, for two available portfolio weights: weights_with_citi
and weights_without_citi
. These correspond, respectively, to equal-weighted portfolios with and without Citibank, which exhibited (as you saw in Chapter 1) the highest volatility of the four assets over the period.
The portfolio prices for 2008 - 2009 with Citibank are available as prices_with_citi
, and without Citibank as prices_without_citi
.
This exercise is part of the course
Quantitative Risk Management in Python
Exercise instructions
- Find the returns series for the two portfolios using
weights_with_citi
andweights_without_citi
. - Compute the 30-day rolling window standard deviations for both portfolios.
- Combine both Pandas
Series
objects into a single "vol
" DataFrame object. - Plot the contents of the
vol
object to compare the two portfolio volatilities over time.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Find the time series of returns with and without Citibank
ret_with_citi = prices_with_citi.____.dot(weights_with_citi)
ret_without_citi = prices_without_citi.pct_change().____(____)
# Find the average 30-day rolling window volatility as the standard deviation
vol_with_citi = ret_with_citi.____.std().dropna().rename("With Citi")
vol_without_citi = ret_without_citi.rolling(30).____.dropna().rename("Without Citi")
# Combine two volatilities into one Pandas DataFrame
vol = pd.concat([____, ____], axis=1)
# Plot volatilities over time
vol.____().set_ylabel("Losses")
plt.show()