简体   繁体   中英

Calculating Value at Risk with performanceanalytics package

I tried to calculate the Value at Risk for a list auf Stock Returns. There are 1000 observations, but i wanted to calculate like the following:

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.

To solve the problem I tried to use a if condition with a for loop.

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:

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. 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). 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. So, maybe you can try to change your confidence level and see.

Also see this and this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM