Running R 2.1.14 on Windows 7.

My problem is the following:

I'm using the sp500ret data, approximating the parameters using ugarchfit, and then calculating the conditional variances "by hand" and plotting on top of the 3rd graph from plot.ugarchfit.  This task may seem silly but bear with me.  All the following code is ready to run copy and paste.

The discrepancy I'm finding is consistent over different models, so let's just look at a Garch(1,1)

#start code         ****************
library(rugarch)
data(sp500ret)

#by hand functions
calcResiduals<-function(returns){
       #returns a list of the returns residuals

       #returns             :a vector or time series of floats

       returns-mean(returns)
}

standardGarch<-function(returns, alpha, beta, omega){
       #standard garch per rugarch documentation

       #returns             :a vector or time series of floats
       #alpha               :a float, estimation of the alpha parameter
       #beta                :a float, estimation of the beta parameter
       #omega               :a float, estimation of the omega parameter

       residuals<-calcResiduals(returns)
       #now we have our iterative recursive method
       sigmaVect<-rep(0, length(returns)+1)

       for(i in 1:length(returns)){
              sigmaVect[i+1]<-omega+alpha*residuals[i]^2+beta*sigmaVect[i]
       }
       sigmaVect
}

returns<-sp500ret[,1]                    #leave off the dates for now

spec<-ugarchspec(variance.model=list(model="sGARCH"))
fit<-ugarchfit(spec, sp500ret)
fit
plot(fit)     #here press 3 then enter on the console
              #then press 0 then enter to exit the graph menu

#I got the following as estimates for my parameters from ugarchfit
#these should be changed to the appropriate ones you get in output
#they should be near the same
alpha<-.087817
beta<-.904886
omega<-.000001

vals<-standardGarch(returns,alpha, beta, omega )
vals<-vals[2:(length(vals))]
vals<-as.data.frame(vals)
rownames(vals)<-rownames(sp500ret)        #attach the dates

#yes, the dates are most likely a bit off, that won't matter to much for the visual
#representation though.  My issue is a vertical shift difference

lines(sqrt(vals), col="purple")

#plot the by hand calculation on top of the ugarchfit graph.

#end code     *******************

On my machine, I see a slight discrepancy between my function's calculation of the conditional variances and the ugarchfit calculation.  To my understanding I implemented the formula used in ugarchfit for sGarch correctly, so there should be very little difference in the output.

My first thoughts as to why this difference occurs is some difference in how C and R treat numerics and the conversion back and forth (this occurs in ugarchfit but not in mine), or possibly some truncation of the parameter estimates for display purposes, leading me to use parameter values that are slightly off.

Can anyone provide an explanation as to what I am seeing here?

	[[alternative HTML version deleted]]

