Roll, roll, roll
你可以使用套件 PerformanceAnalytics 中的函式 chart.RollingPerformance() 來視覺化波動度的時間變化。一個重要的調校參數是「視窗長度」。視窗越短,滾動波動度對近期報酬的反應就越靈敏;視窗越長,曲線就會越平滑。sd.annualized 函式可在假設一年交易日數等於 scale 參數所指定的數值下,計算年化波動度。
在這個練習中,你需要補完程式碼,計算 2005 年到 2017 年期間 sp500ret 中 S&P 500 每日報酬的年化波動度滾動估計。
本練習屬於課程
R 的 GARCH 模型
練習說明
- 載入套件
PerformanceAnalytics。 - 計算「1 個月」的估計,並將 scale 參數設為一年中的交易日數。
- 計算「3 個月」的估計,並將 scale 參數設為一年中的交易日數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the package PerformanceAnalytics
___
# Showing two plots on the same figure
par(mfrow=c(2,1))
# Compute the rolling 1 month estimate of annualized volatility
chart.RollingPerformance(R = sp500ret["2000::2017"], width = ___,
FUN = "sd.annualized", scale = ___, main = "One month rolling volatility")
# Compute the rolling 3 months estimate of annualized volatility
chart.RollingPerformance(R = ___, width = ___,
FUN = ___, scale = ___, main = "Three months rolling volatility")