Dear all,

I am trying to understand the simul command in dynare. In sim1.m there is the following code which I do not understand at all:

model_dynamic = str2func([M_.fname,'*dynamic’]);*

z = Y(find(lead_lag_incidence’));

[d1,jacobian] = model_dynamic(z,oo.exo_simul, params, …

steady_state,2);

The Y is the stacked vector of all variables (to be determined) at all times of the simulation. At that point it is Y=[Y0,Y1,Y1,…Y1]’, thus the initial points and then the end points times the time of simulation.

The lead_lag_incidence determines the characteristc of each variable (backward looking, forward looking or present).

So far correct?

I do not understand what model_dynamic is (except that it is a function…but what does it do?).

I also do not understand the z variable since it stores values of initial steady states and future steady states.

Last but not least, I do not get the model_dynamic() and what it does. I tried

[d1,jacobian111] = model_dynamic(z,oo_.exo_simul, params, …

steady_state,2)

AAA=model_dynamic(z,oo_.exo_simul, params, …

steady_state,2)

[d2,jacobian1] = AAA

The first command works, for the second and third together I get “Too many output arguments.”

Any help is very much appreciated!

Best

model_dynamic is a link to the _dynamic-function created by Dynare. You can find that function in the folder where your mod-file is located after running Dynare. If your model is cally mymodel.mod the file will be mymodel_dynamic.m. This file computes the things as indicated in the header of that file:

[quote]function [residual, g1, g2, g3] = mymodel_dynamic(y, x, params, steady_state, it_)

%

% Status : Computes dynamic model for Dynare

%

% Inputs :

% y #dynamic variables by 1] double vector of endogenous variables in the order stored

% in M_.lead_lag_incidence; see the Manual

% x [M_.exo_nbr by nperiods] double matrix of exogenous variables (in declaration order)

% for all simulation periods

% params [M_.param_nbr by 1] double vector of parameter values in declaration order

% it_ scalar double time period for exogenous variables for which to evaluate the model

%

% Outputs:

% residual [M_.endo_nbr by 1] double vector of residuals of the dynamic model equations in order of

% declaration of the equations

% g1 [M_.endo_nbr by #dynamic variables] double Jacobian matrix of the dynamic model equations;

% columns: equations in order of declaration

% rows: variables in order stored in M_.lead_lag_incidence

% g2 [M_.endo_nbr by (#dynamic variables)^2] double Hessian matrix of the dynamic model equations;

% columns: equations in order of declaration

% rows: variables in order stored in M_.lead_lag_incidence

% g3 [M_.endo_nbr by (#dynamic variables)^3] double Third order derivative matrix of the dynamic model equations;

% columns: equations in order of declaration

% rows: variables in order stored in M_.lead_lag_incidence

%

%

% Warning : this file is generated automatically by Dynare

% from model file (.mod)

%

% Model equations

%

[/quote]

That is, given the value for the variables in z, it computes the residuals as well as the derivatives of the model.

Thank you for your answer!

One more question: Is there a documentation of how perfect foresight is implemented in Dynare? I am only aware of Juillard 1996, but I read from Sebastian Villemots slides of the summer school in 2012 that it is computed differently nowadays. However, I haven’t found any references.

Appreciate any comments, best

Peter

Juillard1996.pdf (183 KB)

Villemot2012.pdf (267 KB)

I attach slides that give a little more details about the methods used in Dynare for perfect foresight.

The default method (option “stack_solve_algo=0”) is now a simple Newton algorithm run on the stacked system for all the periods, using sparse matrix algebra. The problem is described in the slides 15 and 21.

Formerly, the default method was relaxation (also known as Laffargue-Boucekkine-Juillard), and it is still available with option “stack_solve_algo=6”. It is described in slides 16 to 20.

There are alternative methods based on block decomposition for better performance on big models, implemented by Ferhat Mihoubi. They are only hinted at in slides 22 to 24. I attach Ferhat’s slides that give more details.

ferhat-slides.pdf (534 KB)

deterministic.pdf (323 KB)