Estimating an ARMA model of any order in general

For questions regarding programming in the EViews programming language.

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

charleung
Posts: 4
Joined: Fri Oct 16, 2015 2:17 am

Estimating an ARMA model of any order in general

Postby charleung » Fri Oct 16, 2015 2:31 am

I have seen other posts here about writing a program for estimating a particular order of ARMA model. Yet I'm interested in writing one allowing any order, i.e. the user may insert any order for AR and MA.

Let y be the dependent variable, I noticed that one may program the residuals as y - mu(1) - @nan( mu(1)+phi(1)*y(-1)+phi(2)*y(-2)+theta(1)*res(-1)+theta(2)*res(-2), 0) for an ARMA(2,2) model. Yet it doesn't allow a more general case.

I've tried something like this:

Let !AR be the AR order to be entered and phi be the coefficients and mle be the object for the MLE. So the AR part becomes,

series ARs=0
for !i=1 to !AR
ARs=ARs+phi(!i)*y(!i)
NEXT
mle.append ARs=ARs

Well, it doesn't work. Any thoughts?

My ultimate goal is to build a univariate GARCH model allowing other types of underlying distributions.

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

Re: Estimating an ARMA model of any order in general

Postby EViews Gareth » Fri Oct 16, 2015 8:05 am

I'm not sure what you're trying to do. Why not just use the built in equation object?

charleung
Posts: 4
Joined: Fri Oct 16, 2015 2:17 am

Re: Estimating an ARMA model of any order in general

Postby charleung » Fri Oct 16, 2015 9:18 am

Thanks for your reply.

I'am trying to make a program that allows me to estimate an ARMA model (later develop to GARCH) of any order. For instance, minimising "y - mu(1) -alpha(1)*y(-1) -alpha(2)*y(-2)" refers to an AR(2) model yet what if I want to estimate, say, an AR(10) model? I'm hoping to write a program in which I don't have to type "alpha(-1)*y(-1) , alpha(-2)*y(-1) , .... alpha(-n)*y(-n)".

The reason I'm not using the built-in one is that I'm trying to estimate some GARCH models whose underlying residuals are not normal, t or GED distrbuted. I'm also using R at the same time. While R is very flexible that I can easily write a function, calculation takes much longer time.

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

Re: Estimating an ARMA model of any order in general

Postby EViews Gareth » Fri Oct 16, 2015 9:21 am

ok, and how are you estimating this model?

charleung
Posts: 4
Joined: Fri Oct 16, 2015 2:17 am

Re: Estimating an ARMA model of any order in general

Postby charleung » Fri Oct 16, 2015 10:11 am

This is what I've done so far. I just started EViews programming a few days ago.

As you can see, I'm trying to make the order of the model flexible. Yet the log-likelihood part requires typing in the exact equation. It is a GARCH model but with the Johnson SU as the underlying distribution. Rather than directly using the Johnson SU PDF in the likelihood function, a transformation is used so the Gaussian PDF can be used. Unfortunately, errors persist due to the very restrictive arc cosh function (not a built-in function in EView so I used the exact form instead. That is, arccosh(x)=log(x+sqr(x+1)*sqr(x-1))).

genr y=ftse_dr

'Set model order
!AR=2
!MA=5
!ARCH=2
!GARCH=3
'Reduce the sample to the most recent 5000 observations
smpl @all
if @obs(y)>5000 then
!N1=@obs(y)-4999
!N2=@obs(y)
smpl !N1 !N2
endif
'Declare coefficients
coef(1) mu
coef(!AR) phi
coef(!MA) theta
coef(1) omega
coef(!ARCH) alpha
coef(!GARCH) beta
coef(1) lamda
coef(1) delta
'Produce random initial values
mu(1) =@runif( -2,2)
for !i=1 to !AR
phi(!i)=@runif(-2,2)
NEXT
for !i=1 to !MA
theta(!i)=@runif(-2,2)
NEXT
omega(1) =@runif(0,1)
for !i=1 to !ARCH
alpha(!i)=@runif(0,1)
NEXT
for !i=1 to !GARCH
beta(!i)=@runif(0,1)
NEXT
lamda(1)=@runif(0,0.3)
delta(1)=@runif(20,100)
'Set Pi
!PI=3.141592653589793238462643383279

'the likelihood function
logl jsu
jsu.append @logl loglike
jsu.append res = @nan(y - mu(1) -mu(1)-phi(1)*y(-1)-phi(2)*y(-2)-theta(1)*res(-1)-theta(2)*res(-2)-theta(3)*res(-3)-theta(4)*res(-4)-theta(5)*res(-5) ,0)
jsu.append sig2 = @nan(omega(1) + alpha(1) * ( res(-1) )^2 + alpha(2) * ( res(-2) )^2 + beta(1) * sig2(-1)+ beta(2) * sig2(-2)+ beta(3) * sig2(-3),omega(1))
jsu.append eps=res/sqr(sig2)
jsu.append w=exp(delta(1)^(-2))
jsu.append acosh=((2*sig2)/(lamda(1)^2*(w-1))-1)/w
jsu.append gamma=log(acosh+sqr(acosh+1)*sqr(acosh-1))*delta(1)/2
jsu.append k=sqr((2*sig2-lamda(1)^2*(w^2-1))/(2*(w-1)))
jsu.append asinh=(res-k)/lamda(1)
jsu.append z=gamma+delta(1)*log(asinh+sqr(asinh^2+1))
jsu.append loglike = log(@dnorm(z) )- log(sig2)/2
jsu.ml(showopts)

'Saving info criteria
scalar aic = bedvar.@aic
scalar bic = bedvar.@schwarz
scalar hqc = bedvar.@hq
'Display result
show jsu.output

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

Re: Estimating an ARMA model of any order in general

Postby EViews Gareth » Fri Oct 16, 2015 10:19 am

You'll have to build up a text string containing the terms you want, then substitute out that string inside the logl object with an append.

Something like:

Code: Select all

%arpart = "" for !i=1 to !ar %arpart = %arpart + " + phi(" + @str(!i) + ")*y(" + @str(!i)+")" next mle.append {%arpart}

charleung
Posts: 4
Joined: Fri Oct 16, 2015 2:17 am

Re: Estimating an ARMA model of any order in general

Postby charleung » Fri Oct 16, 2015 8:38 pm

Thank you.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests