Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Quantitative Risk Management in Python

Cursus bekijken

Oefeninstructies

  • 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, set sub_price to the range of prices for that sub-period.
  • Use sub_price and the CovarianceShrinkage object to find an efficient covariance matrix for each sub-period.
  • Print and compare the resulting efficient covariance matrices for all three sub-periods.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren