'length of the workfile (Total sample)
!length=@obsrange

'set window size 
!window=1388

'set step size (re-estimate every 1 observation)
!step=1

' declare equation for estimation
equation eq01
%cmnd = _this.@command 'EDIT: get the equation specification

'matrix to store coefficient estimates
matrix(((!length-!window)/!step),6) coefmat 'where the number of coefficients is 6. 

'declare the series for the mean, volatility and return quantile forecasts
series mean_f
series vol_f

'indexing of matrix
!j=1

'move the samples by 1 observations at a time
for !i=1 to !length-!window+1-!step step !step
    
    'set sample to estimation period
    smpl @first+!i-1 @first+!i+!window-2
    
    'store the estimated coefficients in the matrix
    coefmat(!j,1)=eq01.@coefs(1)
    coefmat(!j,2)=eq01.@coefs(2)
    coefmat(!j,3)=eq01.@coefs(3)
    coefmat(!j,4)=eq01.@coefs(4)
    coefmat(!j,4)=eq01.@coefs(5)
    coefmat(!j,4)=eq01.@coefs(6)
    !j=!j+1 

    ' reset sample to forecast period, 8/31/2012 is the final day of the out of sample period
    smpl @first+!i+!window-1 8/31/2012

    'forecast mean, volatility and quantiles using static forecast (one-step-ahead)
   eq01.fit(f=na) temp_mu temp_vol

    'copy data from current forecast sample to the storage series
    mean_f=temp_mu
    vol_f=temp_vol

next
