Page 1 of 1
Recursive dynamic forecasts
Posted: Mon Nov 03, 2014 8:39 am
by ylijohtaja
Hi all
I would need to derive forecasts from ARMA-GARCH and VAR models in a manner that does not seem to be illustrated by any of the examples I have found the RATS manuals (RATS 7.3, version 9 to be ordered soon):
1. I have estimated a 3-variable VAR model, using data for the whole existing sample period 1975Q1-2012Q4. I would like to use the estimated VAR coefficients (based on the full sample period) to compute dynamic forecasts for the period t+1 – 2019Q4 for each variable for each time point t between 1976Q1-2012Q4. That is, I would need 37*4=148 dynamic forecast series using the ‘fixed’ VAR coefficients – first dynamic forecast series for the period 1976Q2-2019Q4, then for 1976Q3-2019Q4 and so forth.
2. I would need the same kind of dynamic forecast series for conditional variance from an ARMA-GARCH model.
I wonder whether there are codes available to derive such multiple dynamic forecast series. It would be preferable to get the forecast series in the same ‘window’ so to be able to copy paste them easily to excel (not to have to the copy paste 148 times…).
Best wishes,
Re: Recursive dynamic forecasts
Posted: Thu Nov 06, 2014 1:16 pm
by TomDoan
This is based upon CANMODEL.RPF and would need to be adjusted to match your model and range, but it shows the general idea. You set up a RECT[SERIES] with dimensions of the number of series x the number of start periods for the forecasts. Do a FORECAST instruction and copy to the forecasts generated into the proper slots in the TARGET array of series.
Code: Select all
open data oecdsample.rat
calendar(q) 1981
data(format=rats) 1981:1 2006:4 can3mthpcp canexpgdpchs canexpgdpds canm1s canusxsr usaexpgdpch
*
set logcangdp = log(canexpgdpchs)
set logcandefl = log(canexpgdpds)
set logcanm1 = log(canm1s)
set logusagdp = log(usaexpgdpch)
set logexrate = log(canusxsr)
*
system(model=canmodel) ;*<<<<<<<
variables logcangdp logcandefl logcanm1 logexrate can3mthpcp logusagdp ;*<<<<<<<<
lags 1 to 4 ;*<<<<<<<
det constant
specify(tightness=.1) .5
end(system)
*
estimate(noprint)
*
compute nbase=2006:4-1995:1+1
dec rect[series] target(6,nbase)
do time=1995:1,2006:4
forecast(from=time,to=2012:4,model=canmodel,results=temp)
do i=1,6
set target(i,time-1995:1+1) time 2012:4 = temp(i)
end do i
end do time
copy(format=xls,org=columns,dates) 1995:1 2012:4 target
Re: Recursive dynamic forecasts
Posted: Tue Nov 11, 2014 9:16 am
by ylijohtaja
Many thanks Tom, once again!
Just to make sure: I just need to download my own data, change the dates, variable names and the VAR model 'structure', and the created excel file provides the set of forecasts that I wish to have - that is, there is nothing else I need to alter in the code?
This might be trivial, but how could I get the forecasts for one series separately (in the current form, the code yields an excel sheet that provides the forecast for each of the series side by side)?
Cheers,
Re: Recursive dynamic forecasts
Posted: Tue Nov 11, 2014 2:10 pm
by TomDoan
This will save the forecasts for each series to a separate file:
do i=1,6
compute fname="c:\temp\"+%modellabel(canmodel,i)+".xls"
open copy &fname
copy(format=xls,org=columns,dates) 1995:1 2012:4 %srow(target,i)
end do i
Re: Recursive dynamic forecasts
Posted: Wed Nov 12, 2014 3:53 am
by ylijohtaja
This yields the following error message:
## SX11. Identifier %SROW is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>975:3 2049:4 %srow(<<<<
I wonder whether this is because I am using RATS 7.3 (9 should be coming soon)?
Re: Recursive dynamic forecasts
Posted: Wed Nov 12, 2014 8:18 am
by TomDoan
Yes. Without that, you would need to switch the order of the subscripts in target so you can use
copy(format=xls,org=columns,dates) 1995:1 2012:4 target(1,i) to target(nbase,i)
(RECT's are stored by columns, so you can use "TO" to list a column, but not a row).
Re: Recursive dynamic forecasts
Posted: Thu Nov 13, 2014 11:24 am
by ylijohtaja
Unfortunately, I get "## SR8. Badly Formed TO triple" in the last stage (i.e. in the "copy" stage) :-/
Re: Recursive dynamic forecasts
Posted: Thu Nov 13, 2014 11:50 am
by TomDoan
Works fine for me (on 9.0 or 7.3):
Code: Select all
compute nbase=2006:4-1995:1+1
dec rect[series] target(nbase,6)
do time=1995:1,2006:4
forecast(from=time,to=2012:4,model=canmodel,results=temp)
do i=1,6
set target(time-1995:1+1,i) time 2012:4 = temp(i)
end do i
end do time
do i=1,6
compute fname="c:\temp\"+%modellabel(canmodel,i)+".xls"
open copy &fname
copy(format=xls,org=columns,dates) 1995:1 2012:4 target(1,i) to target(nbase,i)
end do i
Re: Recursive dynamic forecasts
Posted: Thu Nov 13, 2014 12:52 pm
by ylijohtaja
True (= works well), my mistake - apologies...
Re: Recursive dynamic forecasts
Posted: Tue Dec 02, 2014 10:01 am
by ylijohtaja
Earlier on, I was able to use the above presented codes as desired - thanks again for the help!
I would need to estimate and capture to excel similar forecasts now, but using rolling coefficient estimates for the VAR model (starting from 2000:1, i.e. first using sample period 1975:1-1999:4 to get forecasts for 2000:1 - 2019:4 etc., then sample period 1975:1-2000:1 to forecast 2000:2 - 2019:4 etc.). It appears that similar logic as with the previous problem (with no rolling coefficients) cannot be used to get what I need (or maybe it can, but I have been unable to find a way to do that). I wonder what would be the correct way to code this?
Re: Recursive dynamic forecasts
Posted: Tue Dec 02, 2014 4:32 pm
by TomDoan
ESTIMATE through the initial period with KALMAN inside the loop (after the FORECAST) would do the sequential estimates.