LoslegenKostenlos loslegen

Portfolio Sharpe ratio

In this exercise you are now going to calculate the Sharpe ratio of the portfolio. How do you think the portfolio Sharpe ratio will be different to the S&P500 Sharpe ratio? You'll find out in this exercise.

You have the portfolio value over time under pf_AUM and the number of months for that data under months. Last, the risk-free rate is available under rfr, which is still set to zero.

Diese Übung ist Teil des Kurses

Introduction to Portfolio Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Calculate the total return from pf_AUM and annualized return for the period defined under months
  • Calculate the annualized volatility, vol_pf, using the standard deviation of the returns. Use 250 trading days
  • Calculate the Sharpe ratio. Don't forget to subtract the risk-free rate rfr from the annualized return.

Interaktive Übung

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

# Calculate total return and annualized return from price data 
total_return = (____[____] - ____[____]) / ____[____]

# Annualize the total return over 4 year 
annualized_return = ((1 + total_return)**(____/months))-1

# Create the returns data 
pf_returns = pf_AUM.pct_change()

# Calculate annualized volatility from the standard deviation
vol_pf = pf_returns.____()*____.____(____)

# Calculate the Sharpe ratio 
sharpe_ratio = ((____ - ____) /____)
print (sharpe_ratio)
Code bearbeiten und ausführen