Estimation of rolling Value at Risk (VaR) using R

后端 未结 2 990
耶瑟儿~
耶瑟儿~ 2021-01-12 15:44

I need to perform rolling VaR estimation of daily stock returns. At first I did the following:

library(PerformanceAnalytics)
data(edhec)
sample<-edhec[,1:         


        
2条回答
  •  半阙折子戏
    2021-01-12 16:05

    The problem is that sometimes there is no variation in your data for the 60-period window.

    R> no_var <- rollapply(sample2.xts, 60, sd, by.column=TRUE)
    R> any(no_var==0)
    [1] TRUE
    R> head(no_var[-(1:60),])
                      001034        001038 001055        001066 001109
    1984-03-26 -0.0003322471 -0.0001498238      0 -0.0111818465      0
    1984-03-27 -0.0003322471 -0.0001498238      0  0.0002076288      0
    1984-03-28 -0.0003322471 -0.0545102488      0  0.0092900768      0
    1984-03-29 -0.0199407074 -0.0565552432      0 -0.0183491390      0
    1984-03-30  0.0192762133 -0.0023488011      0  0.0000000000      0
    1984-04-02 -0.0003322471  0.0000000000      0  0.0560894683      0
    

    I've committed a patch to PerformanceAnalytics on R-Forge (r3525) to allow the NaN to pass through the reaonableness check.

提交回复
热议问题