Exponentially weighted returns and risk
In this exercise, you're going to perform portfolio optimization with a slightly different way of estimating risk and returns; you're going to give more weight to recent data in the optimization.
This is a smart way to deal with stock data that is typically non-stationary, i.e., when the distribution changes over time. Implementation can be quickly done by changing the risk model you use to calculate Sigma, and the returns calculation you use to get mu. The stock prices dataset is available as stock_prices. Let's try!
Diese Übung ist Teil des Kurses
Introduction to Portfolio Analysis in Python
Anleitung zur Übung
- Use the exponential weighted covariance matrix from
risk_modelsand exponential weighted historical returns function fromexpected_returnsto calculateSigmaandmu. Set the span to 180 and the frequency (i.e. the trading days) to 252. - Calculate the efficient frontier with the new
muandSigma. - Calculate the weights for the maximum Sharpe ratio portfolio.
- Get the performance report.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Define exponentially weightedSigma and mu using stock_prices
Sigma = risk_models.____(____, span=____, frequency=____)
mu = expected_returns.____(____, frequency=____, span=____)
# Calculate the efficient frontier
ef = ____(____, ____)
# Calculate weights for the maximum sharpe ratio optimization
raw_weights_maxsharpe = ____.____()
# Show portfolio performance
ef.____(verbose=True)