Programming threshold model with GARCH

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

wxhdiy01
Posts: 21
Joined: Wed Apr 13, 2016 7:07 am

Programming threshold model with GARCH

Postby wxhdiy01 » Mon Jun 12, 2017 2:37 pm

Hi there,

I'm using Eviews to optimize a threshold autoregressive model with a GARCH structure in the error term. The threshold effect is only in the mean equation; the variance equation doesn't have the threshold effect and is just a normal GARCH. The equation (simplified) is as follows:

yt = a0 + b1 * yt-1 + b2 * yt-2 + et for yt-1<thresh
and yt = a1 + b3 * yt-1 + b4 * yt-2 + et for yt-1>thresh

ht = a3 + b5 * et^2 + b6 * ht-1, where ht is the variance of et.

The problem is, when "thresh" is a given value, I can get convergence from MLE optimization; if I let "thresh" be a parameter to be estimated within the system, the system doesn't converge (Failure to improve objective (non-zero gradients)...). Currently, I'm estimating "thresh" using the Eviews built-in threshold regression without the GARCH effect, and feeding the estimated "thresh" value to the system mentioned above. I wonder whether this will greatly bias the estimation results. Moreover, whether it is possible in principle to have "thresh" estimated simultaneously with other parameters in the above-mentioned equations.

My optimization codes are as follows:

Code: Select all

subroutine dtarch(series logl, vector beta, series dep, group regs, series thresh,  scalar sigma0)
   series et = dep - (beta(1) + beta(2)*regs(1) + beta(3)*regs(2))*(thresh<beta(10))-(beta(4)+beta(5)*regs(1)+beta(6)*regs(2))*(thresh>=beta(10)) 'residual from SETAR
   series ht=sigma0^2 'define the initial residual variance value
   for !n=1 to 172  'forecast residual variance for GARCH
      series ht(!n)=(beta(7)+beta(8)*et(!n-1)^2+beta(9)*ht(!n-1))
   next
   logl = @log((1/ht^0.5)*@dnorm(et/ht^0.5)) 'construct logliklihood equation
endsub

series LL_1
vector(10) coef_1
group xs_1 d_total_in_gdp(-1) d_total_in_gdp(-2)  'Group the autoregressive right hand variables
scalar sigma0_1=@stdev(setar_resid1) 'define the inital residual variance as the unconditonal variance of the SETAR residual
series d_total_in_gdp_lag=d_total_in_gdp(-1) 'threshold variable
optimize(ml=1, hess=bfgs,finalh=mlhess, trust=2, noerr) dtarch(LL_1, coef_1, d_total_in_gdp, xs_1, d_total_in_gdp_lag, sigma0_1) 'optimization using ML
vector MLSE = @sqrt(@getmaindiagonal(-@inverse(mlhess)))


Looking forward to your suggestions. Many thanks!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13312
Joined: Tue Sep 16, 2008 5:38 pm

Re: Programming threshold model with GARCH

Postby EViews Gareth » Mon Jun 12, 2017 2:43 pm

Have you tried using the logl object rather than the optimize command?

Also, something about this bit:

Code: Select all

   for !n=1 to 172  'forecast residual variance for GARCH
      series ht(!n)=(beta(7)+beta(8)*et(!n-1)^2+beta(9)*ht(!n-1))
   next

seems inefficient or incorrect, but I can't visualise it in my head to see precisely.
Follow us on Twitter @IHSEViews

wxhdiy01
Posts: 21
Joined: Wed Apr 13, 2016 7:07 am

Re: Programming threshold model with GARCH

Postby wxhdiy01 » Tue Jun 13, 2017 10:35 am

Many thanks for the suggestion! I tried the logl object and it's way faster than the optimize command!

But I still get the "fail to improve the likelihood" message, and now even if I specify a threshold value instead of letting the system estimate it, I still don't get the convergence :(

My code is as follows

Code: Select all

'Define samples
sample s0  1972q2 1972q2
sample s1 1972q3 2015q2
smpl s1

'Create parameter vector with initial values
coef(3) beta0=0.1
coef(3) beta1=0.5
coef(1) thresh=0.188
coef(3) alpha=0.1

'Set starting value for the residual and variance series
smpl s0
series res=0
series var=0.04

'Define logl object
logl ll1
ll1.append @logl logl
'Calculate the residual from the mean equation
ll1.append res = d_total_in_gdp - (beta0(1) + beta0(2)*d_total_in_gdp(-1) + beta0(3)*d_total_in_gdp(-2))*(d_total_in_gdp(-1)<thresh(1))-(beta1(1) + beta1(2)*d_total_in_gdp(-1) + beta1(3)*d_total_in_gdp(-2))*(d_total_in_gdp(-1)>=thresh(1))
'Specify the variance equation and restrict parameters between 0 and 1
ll1.append var=alpha(1)+@logit(alpha(2))*res(-1)^2+@logit(alpha(3))*var(-1)
'Construct the log likelihood
ll1.append logl = log(@dnorm(res/@sqrt(var))) - log(var)/2

'Estimate and output
smpl s1
ll1.ml(showopts, m=1000, c=1e-5)
show ll1.output


Does it look right? Is changing starting values the only way to go? Thanks in advance!

wxhdiy01
Posts: 21
Joined: Wed Apr 13, 2016 7:07 am

Re: Programming threshold model with GARCH

Postby wxhdiy01 » Wed Jun 14, 2017 10:08 am

Now convergence can be achieved when the threshold value is given. I only added @byeqn. It's unclear to me though if it has to be estimated by equation instead of by observations.


Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 21 guests