LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • Use the exponential weighted covariance matrix from risk_models and exponential weighted historical returns function from expected_returns to calculate Sigma and mu. Set the span to 180 and the frequency (i.e. the trading days) to 252.
  • Calculate the efficient frontier with the new mu and Sigma.
  • Calculate the weights for the maximum Sharpe ratio portfolio.
  • Get the performance report.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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)
Code bearbeiten und ausführen