開始使用免費開始

年化平均與波動度

月報酬的平均與波動度,對應的是以月為投資期間的報酬平均值與標準差。投資人會將這些統計量年化,以呈現一年投資期間的表現。

為此,PerformanceAnalytics 套件提供 Return.annualized()StdDev.annualized() 兩個函式,幫你計算(幾何)年化的平均報酬與年化標準差。

請記得,Sharpe 比率的計算方式是:以平均超額報酬減去無風險利率後,再除以波動度! 本題已為你預先載入 PerformanceAnalytics 套件與 sp500_returns

本練習屬於課程

R 投資組合分析入門

檢視課程

練習說明

  • 使用 Return.annualized() 函式計算 sp500_returns 的年化平均。
  • 使用 StdDev.annualized() 函式計算 sp500_returns 的年化標準差。
  • 使用 PerformanceAnalytics 套件的指令計算年化 Sharpe 比率並指定給 ann_sharpe,假設無風險利率為 0。
  • 使用 table.AnnualizedReturns() 一次取得上述所有結果。

動手互動練習

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

# Compute the annualized mean


# Compute the annualized standard deviation


# Compute the annualized Sharpe ratio: ann_sharpe
ann_sharpe <- 

# Compute all of the above at once using table.AnnualizedReturns()
編輯並執行程式碼