Forecasting using a loop

Hello to all,

I am working on an out-of-sample expanding window routine for forecasting using a simple DSGE model. The dataset is updating fine with every iteration but after I run the calib_smoother function for the first time it does not update with every iteration of the loop, therefore I always get the same forecast. Does anyone know what can be done to solve this? I uploaded both the .xlsx and the .mod files.
knm_1.xlsx (94.8 KB)
F_evaluation.mod (1.4 KB)

Thank you,

Try

% Simple NKM Model
  var y, i, r, pi, g, u,v;
  varexo eps_g, eps_u, eps_v;

% Parameters

parameters beta, sigma, eta, omega, kappa, rhog,rhou,rhov ,phipi, phiy;

  beta = 0.99;
  sigma = 1;
  eta  = 1;
  omega= 0.8;
  kappa= (sigma+eta)*(1-omega)*(1-beta*omega)/omega;
  rhog = 0.8;
  rhou = 0.5;
  rhov = 0.5;
  phipi= 1.5;
  phiy = 0;


% Model equations

 model (linear);

  y=y(+1)-(1/sigma)*(i-pi(+1))+g;
  pi= beta*pi(+1)+kappa*y+u;
  i=phipi*pi+phiy*y+v;
  r=i-pi(+1);
  g = rhog * g(-1) + eps_g;
  u = rhou * u(-1) + eps_u;
  v = rhov * v(-1) + eps_v;

 end;


 shocks;
  var eps_g; stderr 1;
  var eps_u; stderr 1;
  var eps_v; stderr 1;
 end;


m=3
h=1
forecasts_y = zeros(m, h);
varobs y pi i;
 column_names = {'y','i','r','pi','g','u','v'};

for i= 1:m
 Y_matrix=xlsread("knm_1.xlsx");
 relevant=Y_matrix(1:(size(Y_matrix,1)-m-h+i),:);
 xlswrite("y_fe.xlsx", relevant, 'Sheet1', "A2");
 xlswrite("y_fe.xlsx", column_names, 'Sheet1', "A1");
 calib_smoother(datafile='y_fe.xlsx',xls_sheet='Sheet1');
 smoother2histval;
 forecast (periods=1,nograph) y;
 forecasts_y(i,:) = oo_.forecast.Mean.y(h);
 delete("y_fe.xlsx");
 options_.nobs=NaN;
end

It worked perfectly, thank you.