我需要对每日股票收益进行滚动VaR估计.起初我做了以下事情:
library(PerformanceAnalytics) data(edhec) sample<-edhec[,1:5] var605<-rollapply(as.zoo(sample),modified",invert=T),by.column=TRUE,fill=NA)
它执行计算并返回一个zoo对象,但给出了一系列警告,如下所示:
VaR calculation produces unreliable result (inverse risk) for column: 1 : -0.00030977098532231
然后,我尝试了同样的数据样本,如下所示:
library(foreign) sample2 <- read.dta("sample2.dta") sample2.xts <- xts(sample2[,-1],order.by=as.Date(sample2$datadate,format= "%Y-%m-%d")) any(is.na(sample2.xts)) var605<-rollapply(as.zoo(sample2.xts),modified",invert=T),by.column=TRUE,fill=NA)
但是不会返回任何动物园对象并给出以下警告和错误:
VaR calculation produces unreliable result (inverse risk) for column: 1 : -0.0077322590200255 Error in if (eval(tmp < 0)) { : missing value where TRUE/FALSE needed Called from: top level
从之前的文章(使用rollapply函数进行使用R的VaR计算)我理解,如果缺少完整的滚动窗口,则无法执行滚动估计,但在我的数据(sample2.dta)中没有缺失值.
sample2.dta可以从https://drive.google.com/file/d/0B8usDJAPeV85WDdDQTFEbGQwaUU/edit?usp=sharing下载
有谁可以帮我解决和理解这个问题?