Breaking down the financial crisis
In the video you saw the efficient frontier for the portfolio of investment banks over the entire period 2005 - 2010, which includes time before, during and after the global financial crisis.
Here you'll break down this period into three sub-periods, or epochs
: 2005-2006 (before), 2007-2008 (during) and 2009-2010 (after). For each period you'll compute the efficient covariance matrix, and compare them to each other.
The portfolio's prices
for 2005 - 2010 are available in your workspace, as is the CovarianceShrinkage
object from PyPortfolioOpt.
This exercise is part of the course
Quantitative Risk Management in Python
Exercise instructions
- Create a dictionary
epochs
: its keys are the sub-periods, and its values are dictionaries of 'start' and 'end' dates. - For each of the sub-period keys in
epochs
, setsub_price
to the range ofprices
for that sub-period. - Use
sub_price
and theCovarianceShrinkage
object to find an efficient covariance matrix for each sub-period. - Print and compare the resulting efficient covariance matrices for all three sub-periods.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a dictionary of time periods (or 'epochs')
epochs = { 'before' : {'start': '1-1-2005', 'end': '31-12-2006'},
'during' : {____: '1-1-2007', 'end': '31-12-2008'},
'after' : {'start': '1-1-2009', ____: '31-12-2010'}
}
# Compute the efficient covariance for each epoch
e_cov = {}
for x in epochs.keys():
sub_price = prices.loc[epochs[x][____]:____[x]['end']]
e_cov[x] = CovarianceShrinkage(____).ledoit_wolf()
# Display the efficient covariance matrices for all epochs
print("Efficient Covariance Matrices\n", e_cov)