Jonathan
Jonathan

Reputation: 230

residuals in rugarch same length as original series despite lag

I am using the rugarch package in R to fit a GARCH-model with ARMA-order (1,0) in the mean equation. Despite the lag, the residual series are somehow the same length as the original series.

library(rugarch)
set.seed(123)
x <- rnorm(1000)
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0)))
fit <- ugarchfit(spec, x)
coef <- fit@fit$coef

xhat <- fit@fit$fitted.values
myxhat <- coef["mu"] + coef["ar1"]*c(NA, x[-length(x)])
resid <- fit@fit$residuals
myresid <- x-myxhat

length(resid)==length(x)
[1] TRUE

head(cbind(x, xhat, myxhat, resid, myresid))
               x        xhat      myxhat       resid     myresid
[1,] -0.56047565  0.01615305          NA -0.57662870          NA
[2,] -0.23017749  0.03207118  0.03162527 -0.26224867 -0.26180276
[3,]  1.55870831  0.02295313  0.02250722  1.53575518  1.53620110
[4,]  0.07050839 -0.02642998 -0.02687590  0.09693838  0.09738429
[5,]  0.12928774  0.01465254  0.01420663  0.11463519  0.11508111
[6,]  1.71506499  0.01302991  0.01258399  1.70203508  1.70248099

tail(cbind(x, xhat, myxhat, resid, myresid))
                 x         xhat       myxhat       resid    myresid
[995,]   0.3132288  0.022487416  0.022041503  0.29074136  0.2911873
[996,]  -0.0899752  0.007952121  0.007506207 -0.09792732 -0.0974814
[997,]   1.0705160  0.019082774  0.018636861  1.05143326  1.0518792
[998,]  -1.3511004 -0.012953185 -0.013399098 -1.33814720 -1.3377013
[999,]  -0.5226167  0.053896785  0.053450872 -0.57651348 -0.5760676
[1000,] -0.2491907  0.031026066  0.030580152 -0.28021674 -0.2797708

Does anyone know how (or why?) rugarch computes the residual for the first observation? I see that someone has tried to ask this question before here without answer. Thankful for any help.

Upvotes: 1

Views: 786

Answers (1)

Jonathan
Jonathan

Reputation: 230

rugarch uses the intercept as the fitted value for those observations which are usually removed when estimating an equation with lagged values.

coef["mu"]
mu 
0.01615305

Upvotes: 1

Related Questions