Faster Way of Calculating Rolling Realized Volatility in R

后端 未结 1 1701
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 11:35

I want to calculate the rolling 20 day realized volatility for a collection of indices. Here is the code I use to download the index prices, calculate the daily returns and the

相关标签:
1条回答
  • 2021-02-03 11:47

    You can use runSD in the TTR package (which is loaded by quantmod), but you will need to apply runSD to each column, convert the result of apply back to an xts object, and manually annualize the result.

    realized.vol <- xts(apply(index.ret,2,runSD,n=20), index(index.ret))*sqrt(252)
    
    0 讨论(0)
提交回复
热议问题