Aan de slagGa gratis aan de slag

Changing the span

At the last exercise you discovered that the span of the exponentially weighted risk and return can have an impact on what the optimal portfolio looks like. In fact, the span has a very big influence! By setting the span, you can either use data for say only the most recent days, or use data from the most recent years. In the limit, when the span is as long as the full sample, it will be equal to using the normal historic mean.

Now let's get a feel for how a short and long span changes your optimal portfolio. Available is the stock_prices data.

Deze oefening maakt deel uit van de cursus

Introduction to Portfolio Analysis in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Calculate expected returns and sample covariance
mu_ema = expected_returns.ema_historical_return(stock_prices, span=____ ,frequency=252)
Sigma_ew = risk_models.exp_cov(stock_prices, span=____, frequency=252)
ef_2 = EfficientFrontier(mu_ema, Sigma_ew)

# Calculate weights for the maximum Sharpe ratio portfolio
weights = ef_2.max_sharpe()
cleaned_weights_maxsharpe_EW = ef_2.clean_weights()
perf_max_sharpe_EW = ef_2.portfolio_performance(verbose=True)
Code bewerken en uitvoeren