Conditional forecast using extended path with perfect foresight


I’m trying to do conditional forecast with perfect foresight after estimation. From the manual, I understand that I need to use det_cond_forecast. I follow the example in the manual and define init_plan and flip_plan. However, I couldn’t figure out how to give smoothed variables from the estimation to det_cond_forecast. The example is referring to a csv file. Is the file containing oo_.SmoothedVariables and oo_.SmoothedShocks results?


Can you provide more information? Which example are you referring to?

Sure, thank you. Here is the example from the manual:

% conditional forecast using extended path method
% with perfect foresight on r path
var y r;
varexo e u;

smoothed = dseries(‘smoothed_variables.csv’);
fplan = init_plan(2013Q4:2029Q4);
fplan = flip_plan(fplan, ‘y’, ‘u’, ‘surprise’, 2013Q4:2014Q4, [1 1.1 1.2
˓→1.1 ]);
fplan = flip_plan(fplan, ‘r’, ‘e’, ‘perfect_foresight’, 2013Q4:2014Q4,
˓→[2 1.9 1.9 1.9 ]);
dset_forecast = det_cond_forecast(fplan, smoothed);


I wanted to follow up on this. Does anyone know which smoothed variables we need to give to det_cond_forecast?


@stepan-a may know the answer. An example file is at tests/conditional_forecasts/5/fs2000_cal.mod · master · Dynare / dynare · GitLab
My guess is that you should create a dseries from the smoothed shocks and variables. It should contain all of them.

This is great! Thank you very much.

I have another question now. I was expecting to get the same results when I use conditional_forecast and flip_plan with the ‘surprise’ shock. I give the same constrained path to the same endogenous variable and specify the same exogenous variable as control. However, conditional_forecast.cond.Mean results are different than det_cond_forecast results. Do you know why this is the case?

Best and thanks again,

Could you please provide me with the files to replicate the issue?

I was working on the file example file you shared yesterday. I added conditional_forecast before the extended path simulation.

simulation.mod (2.7 KB)


I wanted to follow up on this and add another question. When I create the dseries from steady state values, det_cond_forecast runs smoothly. However, when I give smoothed variables and shocks to dseries after estimation, I get the following error:

Error using bytecode
Fatal error in bytecode: in Simulate_Newton_Two_Boundaries, the initial values of endogenous variables are
too far from the solution.
Change them!

Error in det_cond_forecast (line 164)
[endo, exo] = bytecode(‘extended_path’, plan, oo_.endo_simul, oo_.exo_simul, M_.params, oo_.steady_state, options_.periods);

Error in estimation.driver (line 3273)
f = det_cond_forecast(fplan, f, frng);

Error in dynare (line 281)
evalin(‘base’,[fname ‘.driver’]);

Is there a way to start conditional forecast under perfect_foresight from last smoothed variable?


Dear all,

For some reason the shock types “perfect_foresight” and “surprise” yield the same results for the basic_plan and the flip_plan simulations using det_cond_foresight.

In particular, it seems that det_cond_foresight always computes the “surprise” forecast regardless of what is specified in basic_plan or flip_plan. Please see the file attached.

Is this a bug or did we miss something?

Thank you so much!
simulation.mod (2.5 KB)

That sounds like a bug we need to investigate. See Investigate why det_cond_forecast does not distinguish between surprise and anticipated shocks (#1884) · Issues · Dynare / dynare · GitLab

1 Like

Dear Johannes,

thank you very much for looking into this!

I also noticed that running det_cond_foresight does not work without the bytecode option in the model block. For basic plans, it returns simply the steady state values (for both perfect_foresight and surprise). For flip plans with perfect_foresight, it runs into this error:

Unrecognized function or variable ‘simul’.
Error in det_cond_forecast (line 428)

For flip plans with surprise shocks, it reaches the maxit limit and returns the same error in every iteration without convergence or divergence.

Please see the file attached.
simulation.mod (1.9 KB)

Does det_cond_foresight require they bytecode option?

Thank you very much!

Dear schoderch,

Did you solve your problem. I have the same problem: When I use det_cond_forecast with only ‘perfect_foresight’ in flip_plan. I got the following error message: “Undefined function or variable ‘simul’. Error in det_cond_forecast (line 428)”.

Thanks for sharing with me how you solve the problem.

Dear JusteS,

If you use the ‘bytecode’ option in the model command, the flip plan works but will produce only ‘surprise’ results. The ‘perfect_foresight’ option is ignored. See jpfeifer’s bug report above. The problem with bytecode is that it is a mex-file, so I don’t know how to look into it.

Without the ‘bytecode’ option, neither the ‘surprise’ nor ‘perfect_foresight’ forecasts work for me on Dynare 5.0. I wonder if it might work with an older version of Dynare?


Many thanks. With the ‘bytecode’ option in the model command, my code works now. I am using Dynare 5.3


You mentioned you were using “perfect_foresight” in the flip_plan. Did you check if the results differ from using “surprise” shocks?

Not yet. I will check later. Thanks.

I verified and I found the same the path using “perfect_foresight” in the flip_plan and using “surprise” in the flip_plan. You are right! This is probably a bug. Maybe @jpfeifer will come back with solution soon.

Thanks to all.