*
******************************************************************
* This procedure implements multi-period-ahead dynamic forecasts from
* a fractionally differenced series.
* The series is observed over range n1 to n2, and forecast for range
* n2+1 to n3
*
* series: the series to be forecast
* fcser : series for forecast series
* d     : fractional differencing parameter
* n1    : first observation of observed series
* n2    : last observation of observed series; first obs in forecast
*         horizon is (n2+1)
* n3    : last observation in forecast horizon
*
* cfb/jb 6728
******************************************************************
procedure fdfc series fcser d n1 n2 n3
type series series *fcser
type real d
type integer n1 n2 n3

option switch print 1

local series temp
local vector weightxx
local integer ii kk

dim weightxx(n3)

*** Calculates binomial expansion terms ****
comp weightxx(1) = d

do ii=2,n3
comp weightxx(ii) = weightxx(ii-1)*(ii-1-d) / float(ii)
end do ii

*** Place series into temp to facilitate dynamic forecasts ***
set temp n1 n2 = %if(%valid(series),series,0)

*** Calculate forecast series ***
set fcser n2+1 n3 = 0.0
do ii=n2+1,n3
do kk=1,ii-n1
set fcser ii ii = fcser(ii) + temp(ii-kk)*weightxx(kk)
end do kk
set temp ii ii = fcser
end do ii

if print
{
dis 'forecast series is defined over' n2+1 n3
dis ' '
pri n2+1 n3 fcser
}

end
