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: