[Gretl-users] Rolling forecasting
Allin Cottrell
cottrell at wfu.edu
Sun Mar 18 20:07:44 EDT 2012
On Sat, 17 Mar 2012, Dan Běsoň wrote:
> I am finishing my thesis on volatility prediction and I would like
> to compare 1-step-ahead forecasts of various models. I tried to
> use the following code
>
> open D:\Thesis\VECM\all_data.gdt
>
> smpl full
>
> scalar DataLen = $nobs
> scalar WindowLen = 400
> scalar FirstObs = 1
> scalar LastObs = WindowLen
>
> matrix Forecasts = zeros( DataLen, 1)
> matrix StdErrors = zeros( DataLen, 1)
>
> matrix FCDest = zeros(DataLen, 1 )
> matrix ErrDest = zeros(DataLen, 1 )
> scalar FDestVal= 0
> scalar EddDestVal= 0
>
> loop ForecastPeriod = LastObs + 1..DataLen - 1
> smpl FirstObs LastObs
> ols allRR allRR(-1) allRR(-2) allRR(-3) --robust --quiet
> fcast FDestVal
> FCDest[$ForecastPeriod,1] = FDestVal
>
> FirstObs = FirstObs + 1;
> LastObs = LastObs + 1;
> endloop
>
> but when trying to save FDestVal after fcasting I receive an error
> message.
You need to pay attention to the error message, namely
"Matrices not conformable for operation"
In your assignment
FCDest[$ForecastPeriod,1] = FDestVal
you are attempting to assign a series (FDestVal, which gretl is
willing to convert to a vector on demand) to a single element of a
vector (FCDest[$ForecastPeriod,1]) and there's no way that can work.
More generally, you need to figure out your logic: How, exactly, do
you want to make use of the results of the successive forecasts
generated by the "rolling" estimation-and-forecast loop? Each such
forecast comprises a series of values, not just a scalar. So what do
you want to do with these values? Perhaps you need a matrix with a
number of columns equal to the number of iterations in your loop?
On a relatively small point, you need to lose the trailing ";" on
some of the script lines -- that's not admissible gretl syntax.
Here's a sample script that does what one might want to do, on one
interpretation of your objective. That is, it fills out a matrix of
forecasts using one column per estimated model ("hansl" is gretl's
scripting language.)
<hansl>
open denmark.gdt
series allRR = LRM
scalar DataLen = $nobs
scalar WindowLen = 50
scalar FirstObs = 1
scalar LastObs = WindowLen
matrix FCMat = zeros(DataLen, DataLen - LastObs)
scalar j = 1
loop t = LastObs + 1..DataLen - 1
smpl FirstObs LastObs
ols allRR allRR(-1) allRR(-2) allRR(-3) --robust --quiet
smpl --full
fcast FSeries
FCMat[,j] = FSeries
FirstObs = FirstObs + 1
LastObs = LastObs + 1
j++
endloop
# drop missing values and print
FCMat = FCMat[4:,]
print FCMat
</hansl>
Allin Cottrell
More information about the Gretl-users
mailing list