Skip to content

Slight Discrepancy between ugarchfit and by hand calculation

2 messages · Tevlin, Dylan, Alexios Ghalanos

#
The reason you are getting a discrepancy is because you have not been diligent in either reading the documentation or the c-code which show the GARCH recursion:

1. The specification you use is the default one ARMA(1,1)-GARCH(1,1) but you filter the returns ONLY for a constant.
2. Your code does not include start-up recursion conditions.

Here is the correct way to do it:

#################################
library(rugarch)
data(sp500ret)
calcResiduals<-function(returns, mu){
# pass the correct mu which is estimated jointly in the ML procedure
 returns-mu
}

standardGarch<-function(returns, alpha, beta, omega, mu){
residuals<-calcResiduals(returns, mu)
sigmaVect<-rep(0, length(returns))
# recursion initialisation value h0
h0 = mean(residuals^2)
 for(i in 1:length(returns)){
   if(i==1){
     sigmaVect[i]<-h0  
   } else{
     sigmaVect[i]<-omega+alpha*residuals[i-1]^2+beta*sigmaVect[i-1]
   }
 }
 return(sigmaVect)
}

returns<-sp500ret[,1]                    #leave off the dates for now
# armaOrder=c(0,0) since default is (1,1)
spec<-ugarchspec(mean.model=list(armaOrder=c(0,0)),variance.model=list(model="sGARCH"))
fit<-ugarchfit(spec, sp500ret)
alpha<-coef(fit)["alpha1"]
beta<-coef(fit)["beta1"]
omega<-coef(fit)["omega"]
mu<-coef(fit)["mu"]
vals<-standardGarch(returns,alpha, beta, omega, mu)
# all.equal is the way to compare, NOT visually if you want exact results:
all.equal(as.numeric(sigma(fit)), sqrt(as.numeric(vals)))
################################


-Alexios
On 14 Jul 2014, at 20:02, Tevlin, Dylan <Dylan.Tevlin at kochind.com> wrote: