Is my VaR calculation correct?

I want to use a ARMA-GARCH process to calculate the value at risk.

I use the rugarch package of R.

First of all, I specify my model:

mymodel<-ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(1, 1), include.mean = FALSE),
distribution.model = "norm")


Then I fit it:

modelfit<-ugarchfit(spec=mymodel,data=mydata)


Now comes the crucial point: I want to use the fitted values to calculate the VaR. The model is given by:

\begin{align} r_t=\mu_t + a_t =\mu_t+\sigma_t\epsilon_t= \alpha_1 r_{t-1}+ \beta_1a_{t-1} \\ \sigma^2_t=\gamma_0 + \gamma_1a^2_{t-1} + \delta_1\sigma^2_{t-1} \end{align}

where

$a_t=\sigma_t \epsilon_t$ and $\epsilon_t$ is iid(0,1)

The Value at Risk (as far as I know) can now be calculated via: \begin{align} \hat{VaR}_{0.99,T|T-1}&=\hat{\mu}_{T|T-1} + \hat{\sigma}_{T|T-1} * q_{0.99} \end{align} I therefore need the estimated values of the $\mu$ and $\sigma$. I am not sure how I can get them? Is one of these correct and if both are not correct, what is correct:

This here:

spec = getspec(modelfit);
setfixed(spec) <- as.list(coef(modelfit));
forecast = ugarchforecast(spec, n.ahead = 1, n.roll = 1900, data = mydata[1:1901, ,drop=FALSE], out.sample = 1900);
sigma(forecast);
fitted(forecast)


or do I have to take the fitted and sigma values of the modelfit?

fitted(modelfit)
sigma(modelfit)


I want to calculate the VaR using the fitted and sigma values and I can control them via the quantile function, which gives me the quantiles directly:

quantile(modelfit,0.99)
quantile(forecast,0.99)


Nevertheless my problem stays the same? What is correct? To use the fitted and sigma values of the modelfit or of the forecast, or if both is not correct, what is correct?

Thanks a lot for sharing your wisdom!

-

you need to use the forecast for both the mean and sigma. It should look something like this:


forecast = ugarchforecast(modelfit, n.ahead = 1, data = mydata);
sigma(forecast);
fitted(forecast)


Then plug these values into the equation: \begin{align} \hat{VaR}_{0.99,T|T-1}&=\hat{\mu}_{T|T-1} + \hat{\sigma}_{T|T-1} * q_{0.99} \end{align}

where $T$ is actually $T+1$ and denotes the last day of your sample.

-
but this is just giving me one value? I am not sure if you really got what I mean: I want to calculate the VaR for each day in the in-sample period. So the first VaR belongs to the second data point (for the first this can not be calculated) and then do this for the next day. So I need in-sample forecasts/fits and I am not sure how to generate them. – Jen Bohold May 17 at 19:56
Oh...missed that (about your needing the VaR for each day in the sample.) Then the code snippet directly after the var equation is the right one to use, i.e., the sigma, fitted methods should be applied to the forecast not the modelfit object. the former represents the VaR as you would have calculated it in real time (though you need to burn a few points in the beginning to get the models going, which mean you should lessen the n.roll parameter by, say, 50.) the latter represents fitted values over the entire data sample, and thus its coefficients at time (t<T) know about data at time t*>t. – Veeken May 17 at 22:27
I got an email of alexios ghalanos (package author) and he just shortly commented, that "quantile(fit, 0.01) will give you the model VaR at the 1% coverage rate in-sample"? – Jen Bohold May 18 at 11:55
cool. I just checked my claim against Alexios' advice. He's right. x <- fitted(modelfit) - sigma(modelfit)*2.32635; check <- quantile(modelfit,0.01) - x; max(abs(check)) [1] 2.10023e-07 – Veeken May 18 at 16:48
really? I guess that's because the forecast is fed the coefficients from the fit, which was based on the entire data sample. thanks for the double check. – Veeken 2 days ago
show 1 more comment