最小變異與最大 Sharpe 比率的投資組合
在前面的練習中,你用一組目標報酬率格點來計算有效邊界。計算結果包含兩個向量:vpm(投資組合平均報酬的向量)與 vpsd(標準差或波動度的向量),以及一個名為 mweights 的權重矩陣。你將使用這些結果找出波動度最低與 Sharpe 比率最高的投資組合,並繪製其權重配置。
提醒一下,Sharpe 比率是用超額報酬(投資組合報酬減去無風險利率)除以投資組合的波動度所得到。
本練習屬於課程
R 投資組合分析入門
練習說明
- 建立
weights_minvar,也就是在mweights中對應到標準差最小那一列的權重(vpsd == min(vpsd))。 - 當無風險利率為 0.75% 時,計算投資組合報酬的 Sharpe 比率,命名為
vsr。 - 以與第一個步驟類似的方式,建立
weights_max_sr,也就是在mweights中對應到vsr中 Sharpe 比率最大的投資組合那一列的權重。 - 對
weights_minvar中大於 1% 的權重繪製長條圖,並對weights_max_sr中大於 1% 的權重也繪製長條圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create weights_minvar as the portfolio with the least risk
weights_minvar <- mweights[___ == min(___), ]
# Calculate the Sharpe ratio
vsr <- (___ - ___) / vpsd
# Create weights_max_sr as the portfolio with the maximum Sharpe ratio
weights_max_sr <- mweights[___ == max(___)]
# Create bar plot of weights_minvar and weights_max_sr
par(mfrow = c(2, 1), mar = c(3, 2, 2, 1))
barplot(weights_minvar[weights_minvar > 0.01])
barplot(___[___ > 0.01])