I need to perform a validating VaR of daily stock returns. First I did the following:
library(PerformanceAnalytics) data(edhec) sample<-edhec[,1:5] var605<-rollapply(as.zoo(sample),width=60,FUN=function(x) VaR(R=x,p=.95,method="modified",invert=T),by.column=TRUE,fill=NA)
It performs a calculation and returns a zoo object, but gives a series of warnings as follows:
VaR calculation produces unreliable result (inverse risk) for column: 1 : -0.00030977098532231
Then I tried the same with my sample data as follows:
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),width=60,FUN=function(x) VaR(R=x,p=.95,method="modified",invert=T),by.column=TRUE,fill=NA)
But this does not return the zoo object and gives the following warnings and errors:
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
From an earlier publication ( Using the rollapply function to calculate VaR using R ). I understand that a rolling estimate cannot be performed if the full rolling window is missing, but there are no missing values ββin my data (sample2.dta).
sample2.dta can be downloaded from https://drive.google.com/file/d/0B8usDJAPeV85WDdDQTFEbGQwaUU/edit?usp=sharing
Can anyone help me solve and understand this problem?