简体   繁体   English

使用PerformanceAnalytics套件计算风险价值

[英]Calculating Value at Risk with performanceanalytics package

I tried to calculate the Value at Risk for a list auf Stock Returns. 我试图计算auf股票收益清单的风险价值。 There are 1000 observations, but i wanted to calculate like the following: 有1000个观测值,但我想计算如下:

VaR for observation:

1 to 500
2 to 501
3 to 502
4 to 503 
and 500 to 999

as you can see the result would be 500 calculations. 如您所见,结果将是500次计算。

To solve the problem I tried to use a if condition with a for loop. 为了解决该问题,我尝试将if条件与for循环一起使用。

like this: 像这样:

if(x < 501 & y < 1000){for(i in KO.Returns){VaR(KO.Returns[x: y], p = 0.95, method = "historical")}}

If I use the mentioned code I get the following error code: 如果使用上述代码,则会得到以下错误代码:

VaR calculation produces unreliable result (inverse risk) for column 1: VaR计算得出第1列的结果不可靠(逆风险):

I think the problem is in your data. 我认为问题出在您的数据中。 When you specify your window, the calculation of historical VaR sorts the data and picks out 95th percentile. 当您指定窗口时,历史VaR的计算将对数据进行排序,并选择第95个百分点。 Sometimes your data will not have a negative value in that percentile, thus historical VaR is meaningless (your losses cannot be a positive value, loss is always negative). 有时,您的数据在该百分比中不会具有负值,因此历史VaR毫无意义(您的损失不能为正值,损失始终为负)。 Hence the error. 因此,错误。

I have been trying to reproduce similar errors using the following code: 我一直在尝试使用以下代码重现类似的错误:

library(PerformanceAnalytics)

data("edhec")
data = edhec[, 5]

valat = rollapply(data = data, width = 20,
                  FUN = function(x) VaR(x, p = 0.95, method = "historical"),
                  by.column = TRUE)
valat 

But when I change the confidence level to p = 0.99 , I stop getting the error. 但是,当我将置信度级别更改为p = 0.99 ,我停止得到该错误。 So, maybe you can try to change your confidence level and see. 因此,也许您可​​以尝试更改您的置信度并查看。

Also see this and this . 也看到这个这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修改PerformanceAnalytics程序包中的提取函数以获得价值 - How to modify drawdown functions in PerformanceAnalytics package for value 使用textplot()进行文本对齐(PerformanceAnalytics软件包) - text alignment with textplot() (PerformanceAnalytics package) 从PerformanceAnalytics包中保存图表对象 - Save chart object from performanceanalytics package 使用“PerformanceAnalytics”包来计算性能度量 - Using 'PerformanceAnalytics' package to calculate Performance Measures 使用PerformanceAnalytics包下标超出范围 - Subscript out of bound using the PerformanceAnalytics package 将 tibble 转换为 xts 以使用 performanceanalytics 进行分析 package - Convert tibble to xts for analysis with performanceanalytics package R包'performanceanalytics'优化器中的最大资产数量 - Maximum number of assets in R package 'performanceanalytics' optimizer PerformanceAnalytics + data.frame:使用包函数时的格式问题 - PerformanceAnalytics + data.frame: Formatting issue when using package functions 如何更改 RStudio 中 PerformanceAnalytics 包生成的绘图的大小(宽度和高度)? - How to change size (width & height) of a plot produced by PerformanceAnalytics package in RStudio? PerformanceAnalytics 包中的某些函数在与 zoo::rollapply 一起使用时失败 - Some functions in PerformanceAnalytics package are failing when use with zoo::rollapply
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM