Page 1 of 1

Garch Selection

Posted: Thu Jul 14, 2011 8:03 pm
by fitria
Hello

I am working on univariate forecasting. in another post, i found program for ARIMA selection, i do it, and then i want to build this ARIMA selection program for GARCH selection. So in defining equation, i changed
from
equation eq_dln{%dep}.ls d(log({%dep})) {%regs} {%arstring} {%mastring}
to
equation eq_dln{%dep}.arch({%archstring}, {%garchstring}) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)
(asumpsion: the ARIMA model is ARIMA(4,1,4))

or its the full version of GARCH selection Program

load "D:\PROGRAM\Forecast Saham\Saham Individual\elty_bumi.wf1"

for %index elty bumi
'%eqname = EQ_{%index} 'name of equation object that will be used.
%dep = %index 'dependent variable
%regs = "C " 'independent variables
%maxgarch = "4" 'maximum number of GARCH terms
%maxarch = "4" 'maximum number of ARCH terms
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, @HQ for Hannan-Quinn

!maxgarch = @val(%maxgarch)
!maxarch= @val(%maxarch)

close {%eqname}

'--> Mean Equation
equation dln{%dep}.ls d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)

'--> heteroskedasticity mean equation
freeze(het_dln{%dep}) dln{%dep}.hettest(type=white)

' 2 - GARCH Estimation
'create table for storing critical values.
table(!maxgarch+2,!maxarch+2) crits_{%dep}
crits_{%dep}(1,1) = "GARCH / ARCH"
crits_{%dep}.setlines(1) +b
crits_{%dep}.setlines(a) +r


'set sample
smpl @all

!mincrit = 1e12 'set the minimum to an artificially large value to begin

'estimate the models
%garchstring = ""
for !i=0 to !maxgarch
'build up string for GARCH terms.
if !i>0 then
%garchstring = %garchstring + " garch(" + @str(!i) + ")"
endif
%archstring = ""
for !j=0 to !maxarch
'build up string for ARCH terms
if !j>0 then
%archstring = %archstring + " arch(" + @str(!j) + ")"
endif
'estimate equation
equation eq_grc_dln{%dep}.arch({%archstring}, {%garchstring}) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)

'capture criterion
if @upper(%criterion) = "@AIC" then
' !crit = {%eqname}.@aic
!crit = eq_grc_dln{%dep}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
' !crit = {%eqname}.@schwarz
!crit = eq_grc_dln{%dep}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
' !crit = {%eqname}.@hq
!crit = eq_grc_dln{%dep}.@hq
endif

'compare criterion
if !crit < !mincrit then
!mincrit = !crit
!bestGARCH = !i
!bestARCH = !j
%bestGARCHstr = %garchstring 'store the best ar string
%bestARCHstr = %archstring 'store the best ma string
crits_{%dep}.settextcolor(@all) black 'table formatting.
!ii=!i+1
!jj=!j+1
crits_{%dep}.settextcolor(!ii,!jj) red
endif

crits_{%dep}(!i+2,!j+2) = !crit
crits_{%dep}(!i+2,1) = !i
crits_{%dep}(1,!j+2) = !j

next
next

equation eq_grc_dln{%dep}.arch({!bestARCH}, {%!bestGARCH}) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)

' 3 - forecast

eq_grc_dln{%dep}.fit {%dep}_f

next


but it didn't worked up. table for criterion model showed the same number for all of possibility model. is there anything wrong?
Thank you.

Re: Garch Selection

Posted: Fri Jul 15, 2011 8:00 am
by EViews Gareth
Nice program - appreciate the attempt.

The problem you've got is the bit when you're building up the ARCH and GARCH strings. You're building them up in the same way that that ARIMA one did, so that you end up with an ARCH string that looks like this:

Code: Select all

ARCH(1) ARCH(2) ARCH(3) ARCH(4)
However, the ARCH command doesn't expect the ARCH specification to look like that. Rather, it just wants a single number. Thus you're ending up with an equation specified like this:

Code: Select all

equation eq_grc_dln{%dep}.arch(ARCH(1) ARCH(2) ARCH(3) ARCH(4),GARCH(1) GARCH(2) GARCH(3) GARCH(4)) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)
When you want to have an equation specified like this:

Code: Select all

equation eq_grc_dln{%dep}.arch(4, 4) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)

Re: Garch Selection

Posted: Tue Jul 19, 2011 3:29 am
by fitria
i changed this part of program

Code: Select all

'estimate the models %garchstring = "" for !i=0 to !maxgarch 'build up string for GARCH terms. if !i>0 then %garchstring = %garchstring + " garch(" + @str(!i) + ")" endif %archstring = "" for !j=0 to !maxarch 'build up string for ARCH terms if !j>0 then %archstring = %archstring + " arch(" + @str(!j) + ")" endif 'estimate equation equation eq_grc_dln{%dep}.arch({%archstring}, {%garchstring}) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4) 'capture criterion if @upper(%criterion) = "@AIC" then ' !crit = {%eqname}.@aic !crit = eq_grc_dln{%dep}.@aic endif if @upper(%criterion) = "@SCHWARZ" then ' !crit = {%eqname}.@schwarz !crit = eq_grc_dln{%dep}.@schwarz endif if @upper(%criterion) = "@HQ" then ' !crit = {%eqname}.@hq !crit = eq_grc_dln{%dep}.@hq endif 'compare criterion if !crit < !mincrit then !mincrit = !crit !bestGARCH = !i !bestARCH = !j %bestGARCHstr = %garchstring 'store the best ar string %bestARCHstr = %archstring 'store the best ma string crits_{%dep}.settextcolor(@all) black 'table formatting. !ii=!i+1 !jj=!j+1 crits_{%dep}.settextcolor(!ii,!jj) red endif crits_{%dep}(!i+2,!j+2) = !crit crits_{%dep}(!i+2,1) = !i crits_{%dep}(1,!j+2) = !j next next equation eq_grc_dln{%dep}.arch({!bestARCH}, {%!bestGARCH}) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)
with

Code: Select all

'estimate the models for !i=1 to !maxgarch %garchstring = "@str(!i)" for !j=0 to !maxarch %archstring = "@str(!j)" 'estimate equation equation eq_grc_dln{%dep}.arch(!j, !i) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4) 'capture criterion if @upper(%criterion) = "@AIC" then ' !crit = {%eqname}.@aic !crit = eq_grc_dln{%dep}.@aic endif if @upper(%criterion) = "@SCHWARZ" then ' !crit = {%eqname}.@schwarz !crit = eq_grc_dln{%dep}.@schwarz endif 'compare criterion if !crit < !mincrit then !mincrit = !crit !bestGARCH = !i !bestARCH = !j %bestGARCHstr = %garchstring 'store the best ar string %bestARCHstr = %archstring 'store the best ma string crits_{%dep}.settextcolor(@all) black 'table formatting. !ii=!i+2 !jj=!j+2 crits_{%dep}.settextcolor(!ii,!jj) red endif crits_{%dep}(!i+2,!j+2) = !crit crits_{%dep}(!i+2,1) = !i crits_{%dep}(1,!j+2) = !j next next equation eq_grc_dln{%dep}.arch(!bestARCH, !bestGARCH) d(log({%dep})) ar(1) ar(2) ar(3) ar(4) ma(1) ma(2) ma(3) ma(4)
it worked so far. is there anything wrong?
Thank You.

Re: Garch Selection

Posted: Tue Jul 19, 2011 7:47 am
by EViews Gareth
Not that I can see.

Re: Garch Selection

Posted: Mon Dec 08, 2014 10:03 am
by cihan
Hi,

I'm using the above code to select the best GARCH. The problem is it picks the one with the lowest AIC which may sometimes have negative coefficients for arch and garch terms. For example garch(2,2) has the lowest AIC but a negative coefficient for the garch term, while garch(1,1) has higher AIC but at least positive coefficients. Is there a way to make the program pick the best garch with lowest AIC and positive coefficients?

Thanks

Re: Garch Selection

Posted: Mon Dec 15, 2014 10:31 am
by CharlieEVIEWS
Modify the code so that if c(x)>=0 then re-store ic, change string, endif, loop again for new specification.