Dear all,
I've got a problem with fcast() using it within a bundle context. In the
example script below, I want to set up a rolling (both sample start and
sample end are moving forward at each iteration) forecast exercise.
However, I obtain an issue with the "--dynamic" option.
It is about the line "fcast ($t2+1) ($t2+b.k) --dynamic". You could even
try "fcast --dynamic". Surprisingly, the rolling option works: "fcast
($t2+1) ($t2+b.k) b.k --rolling".
I also set up an alternative function which doesn't make use of a
bundle, and there it works fine (see the attached file please).
Any ideas what's wrong here?
Best,
Artur
<hansl>
set verbose off
function bundle setCV ( const series y "endogenous",
const list xlist "List of exogenous",
int R[2::] "Length of training set")
bundle b
matrix b.my = {y}
matrix b.mx = xlist
b.nx = nelem(xlist)
b.R = R
return b
end function
function void tscvrol (bundle *b)
series y = b.my
list xlist = b.mx
list lall = y xlist
smpl --no-missing lall
scalar t1 = $t1
scalar n = nobs(y)
scalar nsel = t1+(b.R-2)
string st = obslabel(nsel)
scalar nstep = (n-b.R-b.k+1)
loop i=1..nstep -q
# Trainig set
string trainend = obslabel(obsnum(st)+$i)
smpl t1 @trainend
ols y xlist
fcast ($t2+1) ($t2+b.k) --dynamic # doesn't work
fcast ($t2+1) ($t2+b.k) b.k --rolling # works
# Test set
string teststart = obslabel(obsnum(trainend)+1)
string testend = obslabel(obsnum(teststart) + b.k-1)
smpl @teststart @testend
endloop
end function
#---------
# EXAMPLE
#---------
open denmark.gdt -q
#------------------------
# Set up the base bundle
#------------------------
series x = diff(LRY)
list xlist = 0 x(-1 to -2)
scalar R = 10 # length training set
bundle b = setCV(x, xlist, R)
# Conduct rolling foreecast
scalar b.k = 1 # forecast horizon
tscvrol(&b)
</hansl>