Calib_smoother smoothedvariables vs. occbin_solver simul

Hey folks,

I’m interested in the difference between calib_smoother output in SmoothedVariables and occbin_solver output in simul. Specifically, I’m conducting a counterfactual exercise as follows:

  1. Estimate a NK model with OBC on the short-term nominal interest rate
  2. Use calib_smoother to get SmoothedShocks conditional on posterior mode from step 1)
  3. Use occbin_setup then occbin_solver to get the piecewise simulation given the SmoothedShocks from step 2)
  4. Specify an alternative sequence of shocks for the counterfactual and redo step 3.

I don’t want to share the whole mod file since this is all preliminary stuff, but here’s the last part of the mod for steps 2-4 above:

calib_smoother(datafile = data_est_full,filtered_vars);

shocks_epsGamma = oo_.SmoothedShocks.epsGamma;
shocks_epstheta = oo_.SmoothedShocks.epstheta;
shocks_epsz = oo_.SmoothedShocks.epsz;
shocks_epsnu = oo_.SmoothedShocks.epsnu;
shocks_epsqe = oo_.SmoothedShocks.epsqe;
shocks_epsmp = oo_.SmoothedShocks.epsmp;

shocks(surprise,overwrite);
var epsGamma;
periods 1:240;
values (shocks_epsGamma);
var epstheta;
periods 1:240;
values (shocks_epstheta);
var epsz;
periods 1:240;
values (shocks_epsz);
var epsnu;
periods 1:240;
values (shocks_epsnu);
var epsqe;
periods 1:240;
values (shocks_epsqe);
var epsmp;
periods 1:240;
values (shocks_epsmp);
end;

occbin_setup;
occbin_solver;

for ivar = 1:M_.endo_nbr
eval([‘oo_.simqe.’,M_.endo_names{ivar},’ = oo_.occbin.simul.piecewise(:,ivar);']);
end

shocks_epsqe_cf = [oo_.SmoothedShocks.epsqe(1:194); -shock_size*ones([46,1])];

shocks(surprise,overwrite);
var epsGamma;
periods 1:240;
values (shocks_epsGamma);
var epstheta;
periods 1:240;
values (shocks_epstheta);
var epsz;
periods 1:240;
values (shocks_epsz);
var epsnu;
periods 1:240;
values (shocks_epsnu);
var epsqe;
periods 1:240;
values (shocks_epsqe_cf);
var epsmp;
periods 1:240;
values (shocks_epsmp);
end;

occbin_setup;
occbin_solver;

for ivar = 1:M_.endo_nbr
eval([‘oo_.simnoqe.’,M_.endo_names{ivar},’ = oo_.occbin.simul.piecewise(:,ivar);']);
end

What I noticed is that some observable variables in oo_.occbin.simul neither match the data nor oo_.SmoothedVariables (from calib_smoother). E.g., here is some code to plot a comparison of oo_.SmoothedVariables to oo_.occbin.simul:

figure;
subplot(3,1,1); hold on; grid on; box on;
plot(data.date,data.data_r,‘k-’)
plot(data.date,oo_.SmoothedVariables.R,‘b-.’)
plot(data.date,oo_.simqe.R,‘r–’)
title(‘R’)
legend(‘data’,‘calib smoother’,‘OccBin simul’)
subplot(3,1,2); hold on; grid on; box on;

plot(data.date,data.data_r,‘k-’)
plot(data.date,oo_.SmoothedVariables.Rn,‘b-.’)
plot(data.date,oo_.simqe.Rn,‘r–’)
title(‘Rn’)
legend(‘data’,‘calib smoother’,‘OccBin simul’)

subplot(3,1,3); hold on; grid on; box on;
plot(data.date,data.data_dshare,‘k-’)
plot(data.date,oo_.SmoothedVariables.data_dshare,‘b-.’)
plot(data.date,oo_.simqe.data_dshare,‘r–’)
title(‘data_dshare’)
legend(‘data’,‘calib smoother’,‘OccBin simul’)

generating the following figure

My final question: does anyone have any ideas what might explain the level shift between oo_.SmoothedVariables and oo_.occbin.simul across the whole sample for the last panel (and the small differences at the beginning of the sample in the first two panels)? The parameterization, steady state, model, and the sequences of shocks are all identical, so it must be something else.

Thanks in advance for any help; I appreciate you very much!

I think I found what I’m looking for here: https://forum.dynare.org/t/problem-with-zlb-implementation/20209/24. Now my question is options_.occbin.simul.endo_init the period 0/-1 initial state? i.e., if I set it to equal the period 1 smoothed variables from calib_smoother, then my simulation is off by a period (and the smooth shocks won’t line up)?

I answered my own question. My solution is to grab the smoothed variables for period 1 like this

calib_smoother(datafile = data_est_full,filtered_vars);
for ivar = 1:numel(M_.endo_names)
endo_init(ivar,1) = oo_.SmoothedVariables.(M_.endo_names{ivar})(1) - oo_.steady_state(ivar);
end

Then concatenate a 0 shock to the beginning of the smoothed shocks from period 2 on like this

shocks_epsGamma = [0;,oo_.SmoothedShocks.epsGamma(2:end)];
shocks_epstheta = [0;oo_.SmoothedShocks.epstheta(2:end)];
shocks_epsz = [0;oo_.SmoothedShocks.epsz(2:end)];
shocks_epsnu = [0;oo_.SmoothedShocks.epsnu(2:end)];
shocks_epsqe = [0;oo_.SmoothedShocks.epsqe(2:end)];
shocks_epsmp = [0;oo_.SmoothedShocks.epsmp(2:end)];

shocks(surprise,overwrite);
var epsGamma;
periods 1:240;
values (shocks_epsGamma);
var epstheta;
periods 1:240;
values (shocks_epstheta);
var epsz;
periods 1:240;
values (shocks_epsz);
var epsnu;
periods 1:240;
values (shocks_epsnu);
var epsqe;
periods 1:240;
values (shocks_epsqe);
var epsmp;
periods 1:240;
values (shocks_epsmp);
end;

Then I assign endo_init after occbin_setup but before occbin_solver

occbin_setup;
options_.occbin.simul.endo_init = endo_init;
occbin_solver;

which yields simulations nearly identical to the smoothed variables

Sorry for the delay, but I was travelling. I am glad you found the solution.