# How are residuals calculated in rugarch package

I have a question regarding the "rugarch" package in R. I try to fit a ARMA(1,1)+GARCH(1,1) to a time series $x$ using the following command:

spec <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1,1)), mean.model=list(c(1,1)))
fitted <- ugarchfit(spec, x)


The code above gives me the following result:

Optimal Parameters

------------------------------------

Estimate  Std. Error   t value Pr(>|t|)
mu      0.001001    0.001315  0.761040 0.446633
ar1     0.008470    0.351193  0.024118 0.980759
ma1     0.119446    0.345840  0.345379 0.729809
omega   0.000025    0.000016  1.571823 0.115992
alpha1  0.127315    0.053834  2.364961 0.018032
beta1   0.814652    0.069936 11.648563 0.000000


Now my question is the following, how are the residuals calculated? The one you obtain from the command residuals(fitted)?

I mean for me I would assume that for instance, if $r_t$ is residual at time $t$:

$r_t = x_t - \mu - AR_1x_{t-1} - MA_1r_{t-1}$

But already for their first residuals, how do you obtain it? Here are my values of $x$ :
$x_1 = 0.009888849$
$x_2 = -0.008468736$
$x_3=0.014004795$
and the residuals from command residuals(fitted):
$r_1=0.008887706$,
$r_2=-0.010606758$
$r_3=0.014350796$.

Using my method I get:
$r_1 = x_1 -\mu = 0.007927641 \neq r_1$
$r_2 = x_1 - \mu - AR_1 x_1 - MA_1 r_1 = -0.01099179$
and so on. Basically it is not far, but it is also not what they have, so I would like to know if someone could tell me what I am missing here?

Thanks!

• Example: zero-mean ARMA(1,1)+GARCH(1,1): $$x_t=\phi_1 x_{t-1}+\varepsilon_t+\theta_1 \varepsilon_{t-1}$$ where $$\varepsilon_t=\sigma_t u_t$$ and $\sigma_t$ is described as a GARCH process while $u_t$ is i.i.d. random variable. The residuals given by residuals(fitted) will be the $\varepsilon_t$'s. – Richard Hardy Apr 29 '15 at 8:11
• Hello Richard, thank you for your answer. But then my question is, what are the starting values to start the recurence? – martinscorsese101 Apr 29 '15 at 8:21
• Do you mean $\varepsilon_t$ for $t<1$? That should be noted somewhere in the documentation. But that is a different question. If you want to obtain the residuals just for $t \geqslant 1$, you do not need that. – Richard Hardy Apr 29 '15 at 8:30

I can see that you have made errors in your calculation (that you haven't shown). Please recalculate properly and you'll see that the answers are exactly matching.

For e.g. r1 = x1 −μ = 0.009888849-0.001001 = 0.008887,

which is equal to r1 that you get with the residuals functions. Secondly, in your formula of r2, the first term should be x2 instead of x1, and I believe it's a typo.

Also, note that you can obtain the optimal parameter values with higher number of significant figures using the coef(fitted)` function, which will be useful in your calculation.

• Could you expand your answer to demonstrate how OP has made in the calculations? Walking through the mechanics will make it clear to everyone how and where OP when wrong, as well as showing OP how to do it correctly in the future. – Sycorax Nov 16 '15 at 21:30
• @user777 Expanded. However, in the future, I would suggest OP to include detailed calculations in the post so that answerers can identify the mistake, instead of answerers redoing the entire calculation for him. – HasnainMamdani Nov 17 '15 at 8:07