Select options for Stochastic Simulation outside of Dynare

Hello everyone,

I have an infrastructure for a model that allow me to solve it with PF and StochS. However, i would like to declare all the things needed without passing by Dynare, but directly from my infrastructure in Matlab.
For example for the perfect foresight algorithm i have the following in Dynare:

perfect_foresight_setup ;
options_.lmmcp.Display = Display ;
options_.lmmcp.MaxIter = MaxIter ;
options_.lmmcp.TolFun = TolFun ;
options_.lmmcp.preprocess = preprocess ;
options_.lmmcp.presteps = presteps ;
perfect_foresight_solver(lmmcp) ;

where the variables on the right hand side are declared in my infrastructure in Matlab. I would like to do the same with stochastic simulation but I didn’t find a way to do it. In particular I would like to have the possibility to change the order of the approximation and the periods for the IRFs from my Matlab infrastructure as well. Something like:

stoch_simul(order = order_approx, irf = length);

where order_approx and length are chosen outside of Dynare. How can i do that?

Thank you.

Best,

Alex.

You can manually set

options_.order=2;
options_.irf=20;

Alternatively, you can work with preprocessor switches.

Yes, I already tried that by doing the following:

options_.order=3;
stoch_simul(irf = 40, periods = 2500, pruning, nograph) ;

But it doesn’t work, Dynare runs the simulation with the default order, options_.order = 2 . This is what happens in driver.m when i run the simulation:

options_.order=3;
options_.irf = 40;
options_.nograph = true;
options_.order = 2;
options_.periods = 2500;
options_.pruning = true;

Basically it’s just like Dynare detects that options_.order is missing into stoch_simul and is gonna replace it by the default options_.order = 2.

About preprocessor switches, what do you mean? Is there documentation or other posts where is explained?

Alex.

In Dynare 5, do

options_.order=3;
options_.irf = 40;
options_.nograph = true;
options_.periods = 2500;
options_.pruning = true;
var_list_ = {};
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

That way, the preprocessor will not set the default order=2.

I tried, but it works just for order <=2. When i set order=3 i’m getting this:

Error using stochastic_solvers
You need to set k_order_solver for order>2

Error in resol (line 119)
[dr,info] = stochastic_solvers(dr,check_flag,M,options,oo);

Error in stoch_simul (line 109)
[~,info,M_,oo_] = resol(0,M_,options_,oo_);

Error in KN.driver (line 910)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

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

Error in solve_model (line 55)
eval([‘dynare ’ sModelSettings.ModelName ’ ’ opt{:} ’ -D’ calname]) %%nostrict

Error in main_5_0 (line 182)
ExAll = solve_model(Settings, calname) ;

I tried to set options_.k_order_solver to some values different from zero but then i get:

Error using print_info
k_order_pert was unable to compute the solution

Error in stoch_simul (line 120)
print_info(info, options_.noprint, options_);

Error in KN.driver (line 911)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

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

Error in solve_model (line 55)
eval([‘dynare ’ sModelSettings.ModelName ’ ’ opt{:} ’ -D’ calname]) %%nostrict

Error in main_5_0 (line 182)
ExAll = solve_model(Settings, calname) ;

Do you know how to go on?

Thank you,

Alex.

Also add
options_.k_order_solver=true;

I tried, but i’m getting the same error.

Error using print_info
k_order_pert was unable to compute the solution

Error in stoch_simul (line 120)
print_info(info, options_.noprint, options_);

Error in KN.driver (line 911)
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);

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

Error in solve_model (line 55)
eval([‘dynare ’ sModelSettings.ModelName ’ ’ opt{:} ’ -D’ calname]) %%nostrict

Error in main_5_0 (line 183)
ExAll = solve_model(Settings, calname) ;

But sorry i’m just realising that i forgot to use Dynare 5.0 as you mentioned. I 'm using Dynare 5.4, now i’ll try with 5.0 as well. In any case, if there is a way to make it work also with Dynare 5.4 would be great.

I tried with Dynare 5.0 as well, but nothing changes. Still same errors.

Dynare 5.4 should be fine. Can you provide me with the full files?

I will send you a private message.

This is a tricky issue. You did not provide the full error message. I opened a ticket because this seems like a bug. You can check the progress at

1 Like

Thank you so much for the help Johannes.

Alex.