MY R CODE:
library(PerformanceAnalytics)
prices <- c(10.4, 11, 10.11, 9.19, 10.63, 9.68, 12.89, 9.8, 12.57, 8.23, 9.27,
9.51, 10.51, 9.66, 9.52, 10.78, 9.47, 11.87, 11.33, 11.38, 11.16,
8.94)
returns <- diff(prices)
print(returns)
VaR(returns, p=.95, method="historical")
VaR(returns, p=.95, method="gaussian")
VaR(returns, p=.95, method="modified")
THE OUTPUT:
print(returns)
[1] 0.60 -0.89 -0.92 1.44 -0.95 3.21 -3.09 2.77 -4.34 1.04 0.24 1.00 -0.85 -0.14 1.26
[16] -1.31 2.40 -0.54 0.05 -0.22 -2.22
VaR(returns, p=.95, method="historical")
VaR calculation produces unreliable result (risk over 100%) for column: 1 : 3.09
[,1]
VaR -1
VaR(returns, p=.95, method="gaussian")
VaR calculation produces unreliable result (risk over 100%) for column: 1 : 3.03916083148501
[,1]
VaR -1
VaR(returns, p=.95, method="modified")
VaR calculation produces unreliable result (risk over 100%) for column: 1 : 3.1926697487747
[,1]
VaR -1
The first argument is described in help as "an xts, VECTOR, matrix, data frame, timeSeries or zoo object of asset RETURNS"
What is the problem? Where is the error?
Try calculating log returns and then VaR
Also check the ES (Expected Shortfall) function from PerformanceAnalytics lib. From my personal opinion is way better than VaR.