使用PerformanceAnalytics滚动预期的短缺和尾部风险

时间:2017-08-24 21:45:23

标签: r rollapply performanceanalytics

由于滚动VaR在缺少完整窗口时出现错误,我已经做了以下操作来估计36个月的滚动VaR(HAM5和HAM6缺少36个月窗口):

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)
  }
})

这样可以正常工作,但在估算预期缺口和预期尾部损失时会出错:

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 in if (eval(0 > tmp)) { : missing value where TRUE/FALSE needed

非常感谢“ES”和“ETL”的更正代码。

0 个答案:

没有答案