Since rolling VaR gives error when complete window is missing, I have done the following to estimate 36 months rolling VaR (36 months window missing for HAM5 and HAM6):
library(PerformanceAnalytics)
data(managers)
var<-rollapply(managers,36,function(x){
if(!all(is.na(x))){
return(VaR(x, p=.95, method="modified",align = "right", fill = NA))
} else {
return(NA)
}
})
This is working fine, but gives error while estimating expected shortfall and expected tail loss:
ES<-rollapply(managers,36,function(x){
if(!all(is.na(x))){
return(ES(x, p=.95, method="modified",align = "right", fill = NA,))
} else {
return(NA)
}
})
ETL<-rollapply(managers,36,function(x){
if(!all(is.na(x))){
return(ETL(x, p=.95, method="modified",align = "right", fill = NA,))
} else {
return(NA)
}
})
Error:
Error in if (eval(0 > tmp)) { : missing value where TRUE/FALSE needed
Corrected code for "ES" and "ETL" is much appreciated.