dynare/doc/internals/dynare-internals.org

13 KiB
Raw Permalink Blame History

Dynare internal documentation

Stéphane Adjemian, Houtan Bastani, Michel Juillard, Ferhat Mihoubi, George Perendia, Marco Ratto, Sébastien Villemot

Introduction

This file is an attempt to document the algorithms, the M functions and the DLL's used in Dynare. This is work in progress and will be completed little by little overtime. The organization is the same as in the Dynare Reference Manual (http://www.dynare.org/manual or http://www.dynare.org/documentation-and-support/manual/manual.pdf). Being familar with the Reference Manual is of course a pre-requisite to understand the internal documentation. Thereis one entry point for each of the main Dynare commands.

Other available documentation

M2HTML documentation

M2html is a tool that documents automatically Matlab functions. In particular, it gives easy access to the other functions that call a particular functions and to the functions called by a particular function. http://www.dynare.org/dynare-matlab-m2html In this document, M2HTML links provide direct access to the M2HTML documentation for a particular function.

Starting Dynare processing

Function dynare.m (M2HTML) executes Dynare preprocessor dynare\_m that creates <fname>.m and, in turn, executes it. In addition Dynare preprocessor creates:

  • a representation of the dynamic model as a M function: <fname>\_dynamic.m (by default) or a <fname>\_dynamic DLL or in the form of bytecode, depending on the options used in the model command.
  • a representation for the static model <fname>\_static.m (by default), a DLL or as bytecode, depending on the options used in the model command
  • a function returning the steady state of the model <fname>\_steadystate.m, if steady\_state\_model command is used.
  • a function representing the period objective, of an optimizing agent when optimal policy commands are used: <fname>\_objective\_static.m

Model internal representation

TO BE DONE

Symbol declaration

TO BE DONE

Parameter and variable initialization

TO BE DONE

Solving and simulating

steady

Function steady.m

homotopy\_setup

  • TO BE DONE

check

Function check.m

model\_info

  • TO BE DONE

simul

Function simul.m

stoch\_simul

Function stoch\_simul.m

Function <<disp\_th\_moments.m>>

Function <<th\_autocovariances.m>>

  • M2HTML link
  • This function computes the following moments of the (selected) endogenous variables and returns them in cell array Gamma\_y:

    • matrix of covariance: Gamma\_y{1}
    • matrices of auto-correlation: Gamma\_y{2}…Gamma\_y{nar+1}. The number of autocovariances matrices that are computed is controlled by $options\_.nar$.
    • matrix of variance-decomposition: Gamma\_y{nar+2} (if there is more than one shock in the model).
    • second order approximation of unconditional expectation: Gamma\_y{nar+3} (only for second order approximation of the model)
  • with option hpfilter, Dynare returns the theoretical moments of endogenous variables filtered with Hodrick Prescott formula (see Uhlig, 1999).

Algorithm

At 1st order, the approximated solution of the model takes the form: \[ y_t = \bar y + g_y (s_{t-1}-\bar s)+g_u u_t \] where $s_t$ is the subset of variables that enter the state of the system. \[ s_t = \bar s + g_y^{(s)} (s_{t-1}-\bar s)+g_u^{(s)} u_t \]

$\Sigma_s$, the covariance matrix of $s_t$ must satisfy \[ \Sigma_s = g_y^{(s)}\Sigma_s g_y_{(s)}' + g_u^{(s)} \Sigma_u g_u^{(s)}' \] where $\Sigma_u$ is the covariance matrix of $u_t$. This requires that the eigenvalues of $g_y^{(s)}$ are smaller than 1 in modulus.

The full covariance matrix for $y_t$, $\Sigma_y$, or any subpart of it, can then be obtained as \[ \Sigma_ = g_y^{(s)}\Sigma_s g_y_{(s)}' + g_u^{(s)} \Sigma_u g_u^{(s)}' \]

The above equation is a Sylvester equation that is best solved by a specialized algorithm. Dynare, currently, uses /stepan/dynare/src/branch/master/doc/internals/lyapunov%5C_symm.m.

The vector of standard deviations $\sigma_y$ is obtained by taking the square root of the diagonal elements of $\Sigma_y$.

The autocovariance matrix of $y_t$ and $y_{t-1}$ is defined as \begin{align*} \mbox{cov}≤ft(y_t,yt-1\right) &=E≤ft\{y_t yt-1'\right\}
&= E≤ft\{≤ft(g_y \hat yt-1+g_u u_t\right)\hat yt-1'\right\}
&= g_yΣ_y \end{align*} by recursion we have \begin{align*} \mbox{cov}≤ft(y_t,yt-k\right) &=E≤ft\{y_t yt-k'\right\}
&=g_y^kΣ_y \end{align*}

The autocorrelation matrix is then \begin{equation*} \mbox{corr}≤ft(y_t,yt-k\right) = \mbox{diag}≤ft(σ_y\right)-1E≤ft\{y_tyt-k'\right\}\mbox{diag}≤ft(σ_y\right)-1 \end{equation*} where $\mbox{diag}\left(\sigma_y\right)$ is a diagonal matrix with the standard deviations on the main diagonal.

Function <<lyapunov\_symm.m>>

Function <<dr1.m>>

Estimation

estimation

Dynare command estimation calls function /stepan/dynare/src/branch/master/doc/internals/dynare%5C_estimation.m

Function <<dynare\_estimation.m>>

  • M2HTML link
  • This function handles recursive estimation over several samples, when option nobs contains several values.
  • For each given sample, estimation is done by function dynare\_estimation\_1.m

Function <<dynare\_estimation\_1.m>>

  • M2HTML link
  • The big parts of this function are as follows:

    • initialization and data preparation
    • computation of maximum likelihood or posterior mode (starts around line 347)
    • runs MCMC (starts around line 1003)
    • computes the posterior distributions of various statistics (starts around line 1038)
    • computes smooth values at the last point estimate of the parameters (maximum likelihood, posterior mode or posterior mean) (starts around line 1052)
  • Computation of the log posterior density (or log likelihood) is done by /stepan/dynare/src/branch/master/doc/internals/DsgeLikelihood.m
  • Computation of the smooth values is done by /stepan/dynare/src/branch/master/doc/internals/DsgeSmoother.m

Function <<DsgeLikelihood.m>>

Function <<DsgeSmoother.m>>

model\_comparison

TO BE DONE

shock\_decomposition

TO BE DONE

Forecasting

TO BE DONE

Optimal policy

TO BE DONE

Sensitivity and identification analysis

TO BE DONE

Displaying and saving results

TO BE DONE

Misc commands

TO BE DONE

REFERENCES

    1. Uhlig (1999) "A toolkit for analysing nonlinear dynamic models easily" in R. Marimón and A. Scott /Computational Methods for the

Study of Dynamic Economies/. Oxford University Press.