Page 1 of 1

Using Maximize with GARCH model

Posted: Sat Sep 25, 2010 2:08 am
by ivory4
UG---GARCHUV
How to display a formula ?
Questions are in the brackets included in the code.
Thanks in advance.

Code: Select all

* Same model estimated using MAXIMIZE
*
linreg dlogdm
# constant dlogdm{1}
frml(lastreg,vector=beta) meanf
nonlin(parmset=meanparms) beta  (Without followed by a MAXIMIZE NLLS or DLM, this is [i]only[/i] for assigning parameter values (BETA(1) BETA(2) here) to MEANPARMS defined in PARMSET?)
*
set uu = %seesq
set h  = %seesq
set u  = 0.0
*
nonlin(parmset=garchparms) c a b
compute c=%seesq,a=.05,b=.05
frml varf = c+a*uu{1}+b*h{1}

frml logl = (u=dlogdm-meanf),(uu(t)=u**2),(h(t)=varf(t)),%logdensity(h,u) 
 (Q1: dlogdm-meanf  is calculated once (per individual/per evaluation) as said in RM for FRML. This means for each t, dlogdm-meanf is calculated and assigned to u(SERIES), then used to calculate each uu(t). It seems that if I remove (t), then it still functions well  "frml logl = (u=dlogdm-meanf),(uu=u**2),(h=varf),%logdensity(h,u) " So the question is that WHERE (t) is compulsory?)
(Q2: Is this the way to calculate sigma_square recursively, how the likelihood function is summed up? In RM, %logdensity is said to use h as Symmetric and u as Vector, but they seem to be series here. )

maximize(parmset=meanparms+garchparms) logl 3 *   ( It seems that MAXIMIZE function has an option called RECURSIVE, but I did not find it in RM7.0.How is that used? Like the code(From TSAY's textbook) I listed as following )


Code: Select all

all 0 792:1
open data sp500.txt
data(org=obs) / rt
set h  = 0.0

nonlin mu a0 a1 b1
frml at = rt(t)-mu
frml gvar = a0+a1*at(t-1)**2+b1*h(t-1)
frml garchln = -0.5*log(h(t)=gvar(t))-0.5*at(t)**2/h(t)
smpl 2 792
compute a0 = 0.01,a1 = 0.1,b1 = 0.5,mu = 0.1
maximize(method=bhhh,recursive,iterations=150) garchln

Re: Using Maximize with GARCH model

Posted: Mon Sep 27, 2010 3:43 pm
by TomDoan
ivory4 wrote:UG---GARCHUV
How to display a formula ?
Questions are in the brackets included in the code.
Thanks in advance.

Code: Select all

* Same model estimated using MAXIMIZE
*
linreg dlogdm
# constant dlogdm{1}
frml(lastreg,vector=beta) meanf
nonlin(parmset=meanparms) beta
(Without followed by a MAXIMIZE NLLS or DLM, this is only for assigning parameter values (BETA(1) BETA(2) here) to MEANPARMS defined in PARMSET?)
I'm not sure what you're asking. It defines a PARMSET named MEANPARMS which has the vector BETA (whatever is in it) as its members. At this point, BETA is the 2-vector of coefficients in the MEANF formula, which are initialized to the least squares estimates.
ivory4 wrote:

Code: Select all

*
set uu = %seesq
set h  = %seesq
set u  = 0.0
*
nonlin(parmset=garchparms) c a b
compute c=%seesq,a=.05,b=.05
frml varf = c+a*uu{1}+b*h{1}

frml logl = (u=dlogdm-meanf),(uu(t)=u**2),(h(t)=varf(t)),%logdensity(h,u) 
(Q1: dlogdm-meanf is calculated once (per individual/per evaluation) as said in RM for FRML. This means for each t, dlogdm-meanf is calculated and assigned to u(SERIES), then used to calculate each uu(t). It seems that if I remove (t), then it still functions well "frml logl = (u=dlogdm-meanf),(uu=u**2),(h=varf),%logdensity(h,u) " So the question is that WHERE (t) is compulsory?)
(Q2: Is this the way to calculate sigma_square recursively, then how the likelihood function is summed up? In RM, %logdensity is said to use h as Symmetric and u as Vector, but they seem to be series here. )
Q1: Whereever you have a series (of any type) or FRML (of any type) within another formula, the (t) to reference the current entry is optional. Here all the (t)'s could be removed without a problem. It sometimes helps to clarify that something is a series or formula, rather than being a "temporary" real.

Q2: %logdensity can take either a N x N symmetric for the covariance matrix and N vector for the "x", or scalars for both as 1 x 1 special cases.
ivory4 wrote:

Code: Select all

*
maximize(parmset=meanparms+garchparms) logl 3 *
( It seems that MAXIMIZE function has an option called RECURSIVE, but I did not find it in RM7.0.How is that used? Like the code(From TSAY's textbook) I listed as following )
RECURSIVE used to be an option which changed the order of calculation inside MAXIMIZE when it did numerical derivatives. The only minor advantage (in scratch memory) for the "non-recursive" calculation was removed many years ago so what the RECURSIVE option requested is what is always done now. It's still accepted, but has no effect.

Re: Using Maximize with GARCH model

Posted: Mon Sep 27, 2010 5:02 pm
by ivory4
[quote="TomDoan]

Code: Select all

*
frml varf = c+a*uu{1}+b*h{1}

frml logl = (u=dlogdm-meanf),(uu(t)=u**2),(h(t)=varf(t)),%logdensity(h,u) 
Q1: Whereever you have a series (of any type) or FRML (of any type) within another formula, the (t) to reference the current entry is optional. Here all the (t)'s could be removed without a problem. It sometimes helps to clarify that something is a series or formula, rather than being a "temporary" real.
Q2: %logdensity can take either a N x N symmetric for the covariance matrix and N vector for the "x", or scalars for both as 1 x 1 special cases.[/quote]


Q1&Q2: I see. I mixed MAXIMIZE with other cases where joint likelihood is the argument.

I think it works the same way but the results are still slightly different from using GARCH command directly

Code: Select all

linreg rt  / at
# constant rt{1 to 3}
compute beta=%beta
set h = %seesq
nonlin(parmset=garchparms) beta c a b
compute c=%seesq,a=.05,b=.05

frml varf = c+a*at{1}**2+b*h{1}
frml garchln = -0.5*log(h(t)=varf(t))-0.5*at(t)**2/h(t)
maximize(parmset=garchparms) garchln 5 792