2
$\begingroup$

I'm trying to obtain the same vector of volatility by myself $\sqrt{h_{t|t-1}}$ of a Garch Model, that I obtained "automatically" using the function "ugarchfit" from the package "rugarch".

So after obtaining the Maximum Likelihood Estimates of $\alpha_0,\alpha_1,\beta_1$ i'm going to use the formula of the conditional variance $h_{t|t-1}=\alpha_0+\alpha_1y^2_{t-1}+\beta_1h_{t-1|t-2}$

so that the conditional variance is dependent from its past values..

the crucial point for me is that when we start this process we have $h_{1|0}$ we don't have the past value of the conditional variance, and the conditional variance obtained using the formula is different from the one obtained as output of the "ugarchfit" function.

here's my code: where Garch11_h is the volatility obtained from "ugarchfit"

   #StackOverflow: 
rm(x)
rm(t)
rm(specGarch11)
rm(Garch11)
rm(Garch11_h)
rm(coefs)


set.seed(10)
x<-rnorm(1000,0,3)
#x<-as.data.frame(x)
#x<-t(x)
t=seq(1:length(x))
plot(t,x,type="lines")

#fitting a Garch: #ugarchfit
library(rugarch)

specGarch11 <- ugarchspec(variance.model=list(garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0),include.mean=F))
Garch11 = ugarchfit(specGarch11, data=x)
Garch11_h = sigma(Garch11)
Garch11_h<-as.data.frame(Garch11_h)
Garch11_h<-Garch11_h$V1
Garch11_h=as.numeric(Garch11_h)
x11()
plot(t,Garch11_h,type="lines")
Garch11_for = ugarchforecast(Garch11, n.ahead = 1, plot=TRUE)
#using  ugarchforecast
coefs<-coef(Garch11)
coefs
alpha0=coefs[1]
alpha0=as.numeric(alpha0)
alpha1=coefs[2]
alpha1=as.numeric(alpha1)
beta1=coefs[3]
beta1=as.numeric(beta1)

x2=x^2

#let’s try to obtain the same values for conditional variance:

h0=alpha0+alpha1*x2[1]
#this obtained using the classic formula is different from the one coming form ugarchfit


h900=alpha0+alpha1*x2[899]+beta1*Garch11_h[899] 
#this one is similar but I used the volatility from ugarchfit

here's the volatility that i obtain from the function "ugarchfit" enter image description here

How can I do this? Thank You

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.