開始使用免費開始

投資組合 Sharpe 比率

在這個練習中,你要計算「投資組合的 Sharpe 比率」。你覺得投資組合的 Sharpe 比率會和 S&P500 的 Sharpe 比率有什麼不同?在這題中你就能找到答案。

你手上有投資組合隨時間的資產規模 pf_AUM,以及其對應的月份數 months。最後,無風險利率 rfr 也已提供,且仍為 0。

本練習屬於課程

Python 投資組合分析入門

檢視課程

練習說明

  • pf_AUM 計算總報酬,並根據 months 所定義的期間計算年化報酬。
  • 使用報酬的標準差計算年化波動度 vol_pf。請使用 250 個交易日。
  • 計算 Sharpe 比率。別忘了從年化報酬中扣除無風險利率 rfr

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)
編輯並執行程式碼