*
* RATS Programming Manual
* Example 4.3
* GARCH model with flexible mean
*
cal(q) 1960:1
all 2012:4
open data quarterly(2012).xls
data(org=obs,format=xls)
*
linreg tb1yr
# constant tb1yr{1} tb3mo{1}
equation(lastreg) meaneq
frml(lastreg,vector=beta) meanfrml
compute rstart=%regstart(),rend=%regend()
*
set h  = %seesq
set u  = %resids
set uu = %seesq
*
* Define the parameters
*
nonlin(parmset=meanparms) beta
nonlin(parmset=garchparms) c a b
*
* Define log likelihood FRML in three parts:
*
frml efrml  = tb1yr-meanfrml
frml hfrml  = c+a*uu{1}+b*h{1}
frml logl   = h=hfrml,u=efrml,uu=u^2,%logdensity(h,u)
*
* The BETA's are already done as part of FRML(LASTREG)
*
compute a=.1,b=.6,c=%seesq/(1-a-b)
*
* Estimate the GARCH model
*
maximize(parmset=meanparms+garchparms,$
   pmethod=simplex,piters=10) logl rstart+1 rend
compute aicgarch=-2.0*%logl+2.0*%nreg
*
linreg(equation=meaneq) * %regstart() %regend()
compute aicols=-2.0*%logl+2.0*(%nreg+1)
*
* Compare AIC's with proper counting of parameters
*
disp "AIC-GARCH" @15 *.### aicgarch
disp "AIC-OLS" @15 *.### aicols
*
* Test for serial correlation in the standardized residuals
*
set stdu   = u/sqrt(h)
set stdusq = stdu^2
*
@regcorrs(number=10,dfc=1,nocrits,qstat,$
  title="Standardized Residuals") stdu
@regcorrs(number=10,dfc=2,nocrits,qstat,$
  title="Standardized Squared Residuals") stdusq
*
set hstddev = sqrt(h)
graph(footer="Standard Deviations from GARCH Model")
# hstddev
