Hi all,
To begin, I have limited knowledge in programming but I need to somehow generate a program that can enable me to find the best ARMA model (minimize AIC) starting from ARMA 0,0 to ARMA 5,5 on a rolling basis (over 4000 data points). After the best model has been selected I would like the program to perform a 1 step ahead forecast. Ideally, I would like be able to view the model selected at each point and the forecast generated.
Could you point me in the right direction?
Thank you in advance.
ARMA fitting and forecast
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
ghostwriter
- Posts: 4
- Joined: Mon Sep 02, 2013 2:34 am
Re: ARMA fitting and forecast
Good day,
I have managed to successfully run the following program on my data. This has enabled me to find the best model (minimize AIC) for the entire period. How can I modify this program to help me do the same on a rolling basis i.e. every 500 observations and store the best model at each point?
%eqname = "EQ01" 'name of equation object that will be used.
%maxAR = "5" 'maximum number of AR terms
%maxMA = "5" 'maximum number of MA terms
%dep = "SPX" 'dependent variable
%regs = "C " 'independent variables
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%eqname}
'create table for storing critical values.
%matname = "crits"
if @isobject(%matname) then
%matname = "__crits"
if @isobject(%matname) then
delete {%matname}
endif
endif
table(!maxar+2,!maxma+2) {%matname}
{%matname}(1,1) = "AR / MA"
{%matname}.setlines(1) +b
{%matname}.setlines(a) +r
'set sample
smpl @first+!maxAR @last
!mincrit = 1e12 'set the minimum to an artificially large value to begin
'estimate the models
%arstring = ""
for !i=0 to !maxar
'build up string for AR terms.
if !i>0 then
%arstring = %arstring + " ar(" + @str(!i) + ")"
endif
%mastring = ""
for !j=0 to !maxma
'build up string for MA terms
if !j>0 then
%mastring = %mastring + " ma(" + @str(!j) + ")"
endif
'estimate equation
equation {%eqname}.ls {%dep} {%regs} {%arstring} {%mastring}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%eqname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%eqname}.@hq
endif
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
!bestAR = !i
!bestMA = !j
%bestARstr = %arstring 'store the best ar string
%bestMAstr = %mastring 'store the best ma string
{%matname}.settextcolor(@all) black 'table formatting.
!ii=!i+2
!jj=!j+2
{%matname}.settextcolor(!ii,!jj) red
endif
{%matname}(!i+2,!j+2) = !crit
{%matname}(!i+2,1) = !i
{%matname}(1,!j+2) = !j
next
next
equation {%eqname}.ls {%dep} {%regs} {%bestARstr} {%bestMAstr}
show {%eqname}
show {%matname}
regards,
Ghostwriter.
I have managed to successfully run the following program on my data. This has enabled me to find the best model (minimize AIC) for the entire period. How can I modify this program to help me do the same on a rolling basis i.e. every 500 observations and store the best model at each point?
%eqname = "EQ01" 'name of equation object that will be used.
%maxAR = "5" 'maximum number of AR terms
%maxMA = "5" 'maximum number of MA terms
%dep = "SPX" 'dependent variable
%regs = "C " 'independent variables
%criterion = "@AIC" 'which criterion to use enter "@AIC" for Akaike, "@schwarz" for Schwarz, and @HQ for Hannan-Quinn
!maxAR = @val(%maxAR)
!maxMA = @val(%maxMA)
close {%eqname}
'create table for storing critical values.
%matname = "crits"
if @isobject(%matname) then
%matname = "__crits"
if @isobject(%matname) then
delete {%matname}
endif
endif
table(!maxar+2,!maxma+2) {%matname}
{%matname}(1,1) = "AR / MA"
{%matname}.setlines(1) +b
{%matname}.setlines(a) +r
'set sample
smpl @first+!maxAR @last
!mincrit = 1e12 'set the minimum to an artificially large value to begin
'estimate the models
%arstring = ""
for !i=0 to !maxar
'build up string for AR terms.
if !i>0 then
%arstring = %arstring + " ar(" + @str(!i) + ")"
endif
%mastring = ""
for !j=0 to !maxma
'build up string for MA terms
if !j>0 then
%mastring = %mastring + " ma(" + @str(!j) + ")"
endif
'estimate equation
equation {%eqname}.ls {%dep} {%regs} {%arstring} {%mastring}
'capture criterion
if @upper(%criterion) = "@AIC" then
!crit = {%eqname}.@aic
endif
if @upper(%criterion) = "@SCHWARZ" then
!crit = {%eqname}.@schwarz
endif
if @upper(%criterion) = "@HQ" then
!crit = {%eqname}.@hq
endif
'compare criterion
if !crit < !mincrit then
!mincrit = !crit
!bestAR = !i
!bestMA = !j
%bestARstr = %arstring 'store the best ar string
%bestMAstr = %mastring 'store the best ma string
{%matname}.settextcolor(@all) black 'table formatting.
!ii=!i+2
!jj=!j+2
{%matname}.settextcolor(!ii,!jj) red
endif
{%matname}(!i+2,!j+2) = !crit
{%matname}(!i+2,1) = !i
{%matname}(1,!j+2) = !j
next
next
equation {%eqname}.ls {%dep} {%regs} {%bestARstr} {%bestMAstr}
show {%eqname}
show {%matname}
regards,
Ghostwriter.
Who is online
Users browsing this forum: No registered users and 1 guest
