使用R估算滚动风险价值(VaR) [英] Estimation of rolling Value at Risk (VaR) using R

查看:582
本文介绍了使用R估算滚动风险价值(VaR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对每日股票收益进行滚动VaR估计.首先,我做了以下事情:

I need to perform rolling VaR estimation of daily stock returns. At 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)

它执行计算并返回一个Zoo对象,但给出一系列警告,如下所示:

It performs the computation 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 sample of my 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)

但是is不返回任何动物园对象,并给出以下警告和错误:

But is does not return any zoo object and gives the following warnings and error:

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)中没有丢失值.

From an earlier post (Using rollapply function for VaR calculation using R) I understand that rolling estimation cannot be performed if complete rolling window is missing, but in my data (sample2.dta) there are no missing values.

sample2.dta. google.com/file/d/0B8usDJAPeV85WDdDQTFEbGQwaUU/edit?usp=sharing

sample2.dta can be downloaded from https://drive.google.com/file/d/0B8usDJAPeV85WDdDQTFEbGQwaUU/edit?usp=sharing

任何人都可以帮助我解决和理解此问题吗?

Can anyone please help me to resolve and understand this issue?

推荐答案

1)我们可以仅使用VaR重现警告,如下所示:

1) We can reproduce the warning using only VaR as follows:

> VaR(R = edhec[seq(25, length=60), 5], p = .95, method = "modified", invert = TRUE)
VaR calculation produces unreliable result (inverse risk) for column: 1 : -0.000203691774704274
    Equity Market Neutral
VaR                    NA

尝试使用其他method=.

> VaR(R = edhec[seq(25, length=60), 5], p = .95, method = "gaussian", invert = TRUE)
    Equity Market Neutral
VaR          -0.001499347

2)对于"gaussian",我仍然收到有关实际数据集的警告,但没有错误.尝试尝试其他可用的其他"method"参数值.参见?VaR.

2) With "gaussian" I still got warnings on the real data set but no errors. Try experimenting with the other "method" argument values that are available as well. See ?VaR .

3)请注意,由于by.column = TRUE是默认设置,因此可以省略.

3) Note that by.column = TRUE can be omitted as it is the default.

这篇关于使用R估算滚动风险价值(VaR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆