Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Loading items
Show changes
Showing
with 3690 additions and 1500 deletions
......@@ -125,23 +125,20 @@ by the ``dynare`` command.
.. option:: noclearall
By default, ``dynare`` will issue a ``clear all`` command to
MATLAB (<R2015b) or Octave, thereby deleting all workspace
variables and functions; this option instructs ``dynare`` not
to clear the workspace. Note that starting with MATLAB 2015b
``dynare`` only deletes the global variables and the functions
using persistent variables, in order to benefit from the JIT
(Just In Time) compilation. In this case the option instructs
``dynare`` not to clear the globals and functions.
By default, ``dynare`` deletes all the global variables and the
functions using persistent variables, in order to benefit from the JIT
(just-in-time) compilation. This option instructs ``dynare`` not to
clear those.
.. option:: onlyclearglobals
By default, ``dynare`` will issue a ``clear all`` command to
MATLAB versions before 2015b and to Octave, thereby deleting
all workspace variables; this option instructs ``dynare`` to
clear only the global variables (i.e. ``M_, options_, oo_,
estim_params_, bayestopt_``, and ``dataset_``), leaving the
other variables in the workspace.
By default, ``dynare`` deletes all the global variables and the
functions using persistent variables, in order to benefit from the JIT
(just-in-time) compilation. This option instructs ``dynare`` to clear
only its own global variables (*i.e.* ``M_, options_, oo_,
estim_params_, bayestopt_``, ``dataset_``, ``dataset_info`` and
``estimation_info``), leaving the other variables in the workspace, and
not clearing functions using persistent variables.
.. option:: debug
......@@ -160,7 +157,7 @@ by the ``dynare`` command.
Instructs ``dynare`` to save the intermediary file which is obtained
after macro processing (see :ref:`macro-proc-lang`); the saved output
will go in the file specified, or if no file is specified in
``FILENAME-macroexp.mod``. See the :ref:`note on quotes<quote-note>`
``FILENAME_macroexp.mod``. See the :ref:`note on quotes<quote-note>`
for info on passing a ``FILENAME`` argument containing spaces.
.. option:: onlymacro
......@@ -191,10 +188,13 @@ by the ``dynare`` command.
Instructs Dynare to no create a logfile of this run in
``FILENAME.log.`` The default is to create the logfile.
.. option:: output=second|third
.. option:: output=first|second|third
Instructs the preprocessor to output derivatives of the dynamic model at
least up to the given order.
least up to the given order. The `first` option is useful in
larger models when debugging steady state computation, because it allows
overriding the default computation and output of dynamic second order derivatives
in case of the mod-file not containing commands for further computations.
.. option:: language=matlab|julia
......@@ -409,9 +409,11 @@ by the ``dynare`` command.
.. option:: fast
Only useful with model option :opt:`use_dll`. Don’t recompile the
MEX files when running again the same model file and the lists
of variables and the equations haven’t changed. We use a 32
Don’t rewrite the output files otherwise written to the disk by the preprocessor
when re-running the same model file while the lists of variables and the equations
haven’t changed. Note that the whole model still needs to be preprocessed. This option
is most useful with model option :opt:`use_dll`, because
the time-consuming compilation of the MEX files will be skipped. We use a 32
bit checksum, stored in ``<model filename>/checksum``. There
is a very small probability that the preprocessor misses a
change in the model. In case of doubt, re-run without the fast
......
......@@ -15,11 +15,16 @@ related to the model (and hence not placed in the model file). At the
moment, it is only used when using Dynare to run parallel
computations.
On Linux and macOS, the default location of the configuration file is
``$HOME/.dynare``, while on Windows it is ``%APPDATA%\dynare.ini``
(typically ``c:\Users\USERNAME\AppData\dynare.ini``). You
can specify a non standard location using the ``conffile`` option of
the ``dynare`` command (see :ref:`dyn-invoc`).
On Linux and macOS, the configuration file is searched by default under
``dynare/dynare.ini`` in the configuration directories defined by the XDG
specification (typically ``$HOME/.config/dynare/dynare.ini`` for the
user-specific configuration and ``/etc/xdg/dynare/dynare.ini`` for the
system-wide configuration, the former having precedence over the latter). Under
Windows, the configuration file is searched by default in
``%APPDATA%\dynare\dynare.ini`` (typically
``c:\Users\USERNAME\AppData\Roaming\dynare\dynare.ini``). You can specify a non
standard location using the ``conffile`` option of the ``dynare`` command (see
:ref:`dyn-invoc`).
The parsing of the configuration file is case-sensitive and it should
take the following form, with each option/choice pair placed on a
......@@ -76,8 +81,15 @@ processing. Currently, there is only one option available.
.. option:: GlobalInitFile = PATH_AND_FILE
The location of the global initialization file to be run at
the end of ``global_initialization.m``.
The location of a global initialization file that can be used to
customize some Dynare internals (typically default option values). This
is a MATLAB/Octave script.
If this option is not specified, Dynare will look for a
``global_init.m`` file in its configuration directory (typically
``$HOME/.config/dynare/global_init.m`` under Linux and macOS, and
``c:\Users\USERNAME\AppData\Roaming\dynare\global_init.m`` under
Windows).
*Example*
......@@ -276,20 +288,35 @@ lines starting with a hashtag (#).
.. option:: NumberOfThreadsPerJob = INTEGER
Sets the number of threads assigned to each remote MATLAB/Octave run.
Needs to be an exact divisor of the number :opt:`CPUnbr <CPUnbr = INTEGER | [INTEGER:INTEGER]>` of cores.
Particularly, for very large models setting the number of threads per job to 2 might be the faster choice,
but this depends on your hardware, model and estimation task, so you should experiment with different values.
The default value is ``1``, see also related option :opt:`SingleCompThread <SingleCompThread = BOOLEAN>`.
This option controls the distribution of jobs (e.g. MCMC chains) across additional MATLAB instances that are run in parallel.
Needs to be an exact divisor of the number of cores.
The formula :opt:`CPUnbr <CPUnbr = INTEGER | [INTEGER:INTEGER]>` divided by :opt:`NumberOfThreadsPerJob <NumberOfThreadsPerJob = INTEGER>`
calculates the number of MATLAB/Octave instances that will be launched in parallel,
where each instance will then execute a certain number of jobs sequentially.
For example, if you run a MCMC estimation with 24 chains on a 12 core machine, setting ``CPUnbr = 12`` and ``NumberOfThreadsPerJob = 4``
will launch 3 MATLAB instances in parallel, each of which will compute 8 chains sequentially.
Note that this option does not dictate the number of maximum threads utilized by each MATLAB/Octave instance,
see related option :opt:`SingleCompThread <SingleCompThread = BOOLEAN>` for this.
Particularly for very large models, setting this option to 2 might distribute the workload in a
more efficient manner, depending on your hardware and task specifics.
It’s advisable to experiment with different values to achieve optimal performance.
The default value is ``1``.
.. option:: SingleCompThread = BOOLEAN
Whether or not to disable MATLAB’s native multithreading.
The default value is ``false``. Option meaningless under Octave.
Note: By default, MATLAB tries to speed up calculations by spreading them out over your computer’s threads.
However, tests have shown that for certain tasks, like MCMC estimations, MATLAB’s attempt to multitask
can actually slow things down when parallel computing is turned on. Setting this option to ``true``
starts the additional instances of MATLAB in a single thread mode using MATLAB’s ``-singleCompThread`` startup option.
This option allows you to enable or disable MATLAB’s native multithreading capability. When set to ``true``,
the additional MATLAB instances are initiated in single thread mode utilizing the ``-singleCompThread`` startup option,
thereby disabling MATLAB’s native multithreading. When set to ``false``, MATLAB’s native multithreading
is enabled, e.g. the actual number of threads utilized by each MATLAB instance is usually determined by the number of CPU cores
(you can check this by running ``maxNumCompThreads`` in MATLAB’s command window).
Note: While MATLAB aims to accelerate calculations by distributing them across your computer’s threads,
certain tasks, like MCMC estimations, may exhibit slowdowns with MATLAB’s multitasking especially when Dynare’s parallel computing is turned on
as we do not use MATLAB’s parallel toolbox.
So in many cases it is advisable to set this setting to ``true``.
If you want to have more control, you can manually add the MATLAB command `maxNumCompThreads(N)` at the beginning of `fParallel.m`.
The default value is ``false``. This option is ineffective under Octave.
.. option:: OperatingSystem = OPERATING_SYSTEM
......
......@@ -54,7 +54,7 @@ are introduced by ``/*`` and terminated by ``*/``.
*/
 
Note that these comment marks should not be used in native MATLAB code regions
where the `%` should be preferred instead to introduce a comment. In a
where the ``%`` should be preferred instead to introduce a comment. In a
``verbatim`` block, see :ref:`verbatim`, this would result in a crash since
``//`` is not a valid MATLAB statement).
 
......@@ -86,10 +86,10 @@ observed:
(see :ref:`macro-exp`);
* VARIABLE_NAME (sometimes VAR_NAME) indicates a variable name
starting with an alphabetical character and can’t contain:
()+-\*/^=!;:@#. or accentuated characters;
``()+-\*/^=!;:@#.`` or accentuated characters;
* PARAMETER_NAME (sometimes PARAM_NAME) indicates a parameter name
starting with an alphabetical character and can’t contain:
()+-\*/^=!;:@#. or accentuated characters;
``()+-\*/^=!;:@#.`` or accentuated characters;
* LATEX_NAME (sometimes TEX_NAME) indicates a valid
LaTeX expression in math mode (not including the
dollar signs);
......@@ -98,7 +98,13 @@ observed:
system; it is necessary to put it between quotes when specifying the
extension or if the filename contains a non-alphanumeric character;
* QUOTED_STRING indicates an arbitrary string enclosed between (single)
quotes.
quotes;
* DATE indicates a time period which can be either a year (e.g. ``2024Y`` or
``2024A``), a half-year (``2024S1`` or ``2024H1``), a quarter (``2024Q2``) or a month
(``2024M3``) (see :ref:`dates in a mod file`). Optionally, the time period can
be followed by a plus sign and a number of periods, in which case the date is
shifted accordingly (e.g. ``2023Q1+6`` is accepted and is equivalent to
``2024Q3``).
 
 
.. _var-decl:
......@@ -168,7 +174,7 @@ for declaring variables and parameters are described below.
The expression used to detrend an endogenous variable. All
trend variables, endogenous variables and parameters
referenced in MODEL_EXPR must already have been declared by
the ``trend_var, log_trend_var, var`` and ``parameters``
the ``trend_var``, ``log_trend_var``, ``var`` and ``parameters``
commands. The deflator is assumed to be multiplicative; for an
additive deflator, use ``log_deflator``.
This option can be used together with the ``log`` option (the latter
......@@ -953,6 +959,15 @@ The model is declared inside a ``model`` block:
 
MODEL_EXPRESSION;
 
.. warning::
In Dynare, only equality signs can delineate the left and right-hand side of an
equation. If Dynare encounters an expression like ``a>=b``, this will therefore not
define an inequality constraint. Rather, it is interpreted as the homogenous equation
``(a>=b)=0;``, i.e., the Boolean ``(a>=b)`` must evaluate to 0. Inequality constraints
in Dynare instead need to be set up either via OccBin or as mixed complementarity problems.
|br| Inside the model block, Dynare allows the creation of
*model-local variables*, which constitute a simple way to share a
common expression between several equations. The syntax consists
......@@ -962,7 +977,10 @@ The model is declared inside a ``model`` block:
equal sign, and the expression for which this new variable will
stand. Later on, every time this variable appears in the model,
Dynare will substitute it by the expression assigned to the
variable. Note that the scope of this variable is restricted to
variable (if the model-local variable appears with a lead or a lag
attached to it between parenthesis, the substitution will be done by
shifting the expression accordingly).
Note that the scope of this variable is restricted to
the model block; it cannot be used outside. To assign a LaTeX name
to the model local variable, use the declaration syntax outlined
by :comm:`model_local_variable`. A model local variable declaration
......@@ -992,7 +1010,7 @@ The model is declared inside a ``model`` block:
 
model;
 
[name='Taylor rule',mcp = 'r > -1.94478']
[name='Taylor rule', endogenous='r']
r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;
 
end;
......@@ -1019,8 +1037,7 @@ The model is declared inside a ``model`` block:
Instructs the preprocessor to create dynamic loadable
libraries (DLL) containing the model equations and
derivatives, instead of writing those in M-files. You need a
working compilation environment, i.e. a working ``mex``
command (see :ref:`compil-install` for more details).
working compilation environment, (see :ref:`compil-install` for more details).
Using this option can result in
faster simulations or estimations, at the expense of some
initial compilation time. Alternatively, this option can be
......@@ -1048,8 +1065,8 @@ The model is declared inside a ``model`` block:
 
.. option:: mfs = INTEGER
 
Controls the handling of minimum feedback set of endogenous
variables. Only available with option ``block``. Possible
Controls the handling of minimum feedback set of endogenous variables
for the dynamic model. Only available with option ``block``. Possible
values:
 
``0``
......@@ -1063,7 +1080,7 @@ The model is declared inside a ``model`` block:
normalized (i.e. of the form :math:`x=f(Y)` where
:math:`x` does not appear in :math:`Y`) are potentially
recursive variables. All the other variables are forced to
belong to the set of feedback variables. (Default)
belong to the set of feedback variables.
 
``2``
 
......@@ -1081,6 +1098,14 @@ The model is declared inside a ``model`` block:
other variables are forced to belong to the set of
feedback variables.
 
|br| Default value is ``1``.
.. option:: static_mfs
Controls the handling of minimum feedback set of endogenous variables
for the static model. Only available with option ``block``. See the
``mfs`` option for the possible values. Default value is ``0``.
.. option:: no_static
 
Don’t create the static model file. This can be useful for
......@@ -1181,7 +1206,10 @@ The model is declared inside a ``model`` block:
The equations must be specified by a list of tag values, separated by
commas. Each element of the list is either a simple quoted string, in which
case it designates an equation by its ``name`` tag; or a tag name (without
quotes), followed by an equal sign, then by the tag value (within quotes).
quotes), followed by an equal sign, then by the tag value (within quotes);
or a list of tag-equals-value pairs separated by commas and enclosed
within brackets, in which case this element removes the equation(s) that
has all these tags with the corresponding values.
 
Each removed equation must either have an ``endogenous`` tag, or have a
left hand side containing a single endogenous variable. The corresponding
......@@ -1193,7 +1221,7 @@ The model is declared inside a ``model`` block:
 
::
 
var c k dummy1 dummy2;
var c k dummy1 dummy2 dummy3;
 
model;
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1) + dummy1;
......@@ -1202,13 +1230,15 @@ The model is declared inside a ``model`` block:
c*k = dummy1;
[ foo = 'eq:dummy2' ]
log(dummy2) = k + 2;
[ name = 'eq:dummy3', bar = 'baz' ]
dummy3 = c + 3;
end;
 
model_remove('eq:dummy1', foo = 'eq:dummy2');
model_remove('eq:dummy1', foo = 'eq:dummy2', [ name = 'eq:dummy3', bar = 'baz' ]);
 
In the above example, the last two equations will be removed,
``dummy1`` will be turned into an exogenous, and ``dummy2`` will be
removed.
In the above example, the last three equations will be removed,
``dummy1`` will be turned into an exogenous, and ``dummy2`` and
``dummy3`` will be removed.
 
 
.. block:: model_replace (TAGS...);
......@@ -1246,7 +1276,8 @@ command, the list of transformed model equations using the
``write_latex_dynamic_model command``, and the list of static model
equations using the ``write_latex_static_model`` command.
 
.. command:: write_latex_original_model (OPTIONS);
.. command:: write_latex_original_model ;
write_latex_original_model (OPTIONS);
 
|br| This command creates two LaTeX files: one
containing the model as defined in the model block and one
......@@ -1265,7 +1296,7 @@ equations using the ``write_latex_static_model`` command.
the variable names, as LaTeX subscripts.
 
Compiling the TeX file requires the following LaTeX
packages: ``geometry, fullpage, breqn``.
packages: ``geometry``, ``fullpage``, ``breqn``.
 
*Options*
 
......@@ -1321,7 +1352,8 @@ equations using the ``write_latex_static_model`` command.
See :opt:`write_equation_tags`
 
 
.. command:: write_latex_static_model (OPTIONS);
.. command:: write_latex_static_model ;
write_latex_static_model (OPTIONS);
 
|br| This command creates two LaTeX files: one
containing the static model and one containing the LaTeX
......@@ -1356,7 +1388,7 @@ equations using the ``write_latex_static_model`` command.
 
See :opt:`write_equation_tags`.
 
.. command:: write_latex_steady_state_model
.. command:: write_latex_steady_state_model ;
 
|br| This command creates two LaTeX files: one containing the steady
state model and one containing the LaTeX document header
......@@ -1756,7 +1788,7 @@ in this case ``initval`` is used to specify the terminal conditions.
``k`` inherited from :math:`t=0` as well as the current and
future values for technology ``x``, the values for ``c`` and
``x`` at time :math:`t=0` play no role. The same applies to
the choice of ``c,k`` at time :math:`t=200`, which does not
the choice of ``c``,``k`` at time :math:`t=200`, which does not
depend on ``k`` at :math:`t=201`. As the Euler equation shows,
that choice only depends on current capital as well as future
consumption ``c`` and technology ``x``, but not on future
......@@ -1819,7 +1851,7 @@ in this case ``initval`` is used to specify the terminal conditions.
jumps. In the example above, consumption will display a large
jump from :math:`t=0` to :math:`t=1` and capital will jump
from :math:`t=200` to :math:`t=201` when using :comm:`rplot`
or manually plotting ``oo_.endo_val``.
or manually plotting ``oo_.endo_simul``.
 
 
.. block:: histval ;
......@@ -2033,7 +2065,7 @@ in this case ``initval`` is used to specify the terminal conditions.
 
.. option:: last_obs = {INTEGER | DATE}
 
The observaton number or the date (see
The observation number or the date (see
:ref:`dates-members`) of the last observation to be used in
the file.
 
......@@ -2567,7 +2599,7 @@ blocks.
group of three lines::
 
var VARIABLE_NAME;
periods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;
periods INTEGER[:INTEGER] | DATE[:DATE] [[,] INTEGER[:INTEGER] | DATE[:DATE]]...;
values DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
 
It is possible to specify shocks which last several periods and
......@@ -2584,15 +2616,21 @@ blocks.
arbitrary expressions are also allowed, but you have to enclose
them inside parentheses.
 
The feasible range of ``periods`` is from 0 to the number of ``periods``
specified in ``perfect_foresight_setup``.
.. warning:: Note that the first endogenous simulation period is period 1.
Thus, a shock value specified for the initial period 0 may conflict with
(i.e. may overwrite or be overwritten by) values for the
initial period specified with ``initval`` or ``endval`` (depending on
the exact context). Users should always verify the correct setting
of ``oo_.exo_simul`` after ``perfect_foresight_setup``.
The feasible range of ``periods``, when specified as integers, is from 0 to
the number of ``periods`` specified in :comm:`perfect_foresight_setup` or
:comm:`perfect_foresight_with_expectation_errors_setup`. Alternatively, it
is possible to use real dates if the ``first_simulation_period`` and/or
``last_simulation_period`` option has been passed to the aforementioned
commands.
.. warning:: Note that the first endogenous simulation period is period 1
(when specified as an integer). Thus, a shock value specified for the
initial period 0 may conflict with (i.e. may overwrite or be
overwritten by) values for the initial period specified with
``initval`` or ``endval`` (depending on the exact context). Users
should always verify the correct setting of ``oo_.exo_simul`` after
``perfect_foresight_setup`` or
``perfect_foresight_with_expectation_errors_setup``.
 
*Example* (with scalar values)
 
......@@ -2627,6 +2665,21 @@ blocks.
values (xx);
end;
 
*Example* (with dates)
::
shocks;
var e;
periods 2023Q1;
values 0.5;
var u;
periods 2023Q2:2023Q4 2024Q1;
values 0 0.1;
end;
|br| *In stochastic context*
 
For stochastic simulations, the ``shocks`` block specifies the non
......@@ -2730,14 +2783,19 @@ blocks.
forecast;
 
.. block:: mshocks ;
mshocks(overwrite);
mshocks (OPTIONS...);
 
|br| The purpose of this block is similar to that of the
``shocks`` block for deterministic shocks, except that the numeric
values given will be interpreted in a multiplicative way. For
example, if a value of ``1.05`` is given as shock value for some
exogenous at some date, it means 5% above its steady state value
(as given by the last ``initval`` or ``endval`` block).
exogenous at some date, it means 5% above its steady state value.
If no ``endval`` block is present, the steady state as specified in the
``initval`` block is used as the basis for the multiplication. If an
``endval`` block is present, the terminal steady state as specified in the
``endval`` block will be used as the basis for the multiplication (unless
the ``relative_to_initval`` option is passed).
 
The syntax is the same as ``shocks`` in a deterministic context.
 
......@@ -2748,7 +2806,17 @@ blocks.
* on deterministic exogenous variables with a non-zero steady
state, in a stochastic setup.
 
See above for the meaning of the ``overwrite`` option.
*Options*
.. option:: overwrite
Same meaning as in the :bck:`shocks` block.
.. option:: relative_to_initval
If an ``endval`` block is present, the initial steady state as specified
in the ``initval`` block will be used as the basis for multiplication
(instead of the terminal steady state).
 
.. block:: heteroskedastic_shocks ;
heteroskedastic_shocks(overwrite);
......@@ -2882,6 +2950,9 @@ Finding the steady state with Dynare nonlinear solver
along. Iteration will cease when the attempted step size is smaller than
``tolx``. Default: ``eps^(2/3)``
 
.. option:: non_zero
See :opt:`non_zero`.
 
.. _solvalg:
 
......@@ -2917,27 +2988,25 @@ Finding the steady state with Dynare nonlinear solver
 
``5``
 
Newton algorithm with a sparse Gaussian elimination
(SPE) (requires ``bytecode`` option, see
:ref:`model-decl`).
Newton algorithm with a sparse Gaussian elimination (SPE)
solver at each iteration. This algorithm requires the
:opt:`bytecode` option. The :ref:`markowitz <steady_markowitz>`
option can be used to control the behaviour of the algorithm.
 
``6``
 
Newton algorithm with a sparse LU solver at each
iteration (requires ``bytecode`` and/or ``block``
option, see :ref:`model-decl`).
iteration.
 
``7``
 
Newton algorithm with a Generalized Minimal Residual
(GMRES) solver at each iteration (requires ``bytecode``
and/or ``block`` option, see :ref:`model-decl`).
(GMRES) solver at each iteration.
 
``8``
 
Newton algorithm with a Stabilized Bi-Conjugate
Gradient (BICGSTAB) solver at each iteration (requires
bytecode and/or block option, see :ref:`model-decl`).
Gradient (BiCGStab) solver at each iteration.
 
``9``
 
......@@ -2948,14 +3017,14 @@ Finding the steady state with Dynare nonlinear solver
 
Levenberg-Marquardt mixed complementarity problem
(LMMCP) solver (*Kanzow and Petra (2004)*). The complementarity
conditions are specified with an ``mcp`` equation tag, see
conditions are specified using the perpendicular symbol, see
:opt:`lmmcp`.
 
``11``
 
PATH mixed complementarity problem solver of *Ferris
and Munson (1999)*. The complementarity conditions are
specified with an ``mcp`` equation tag, see
specified using the perpendicular symbol, see
:opt:`lmmcp`. Dynare only provides the interface for
using the solver. Due to licence restrictions, you have
to download the solver’s most current version yourself
......@@ -2973,19 +3042,25 @@ Finding the steady state with Dynare nonlinear solver
blocks that can be evaluated rather than solved; and evaluations
of the residual and Jacobian of the model are more efficient
because only the relevant elements are recomputed at every
iteration.
iteration. This option is typically used with the
``perfect_foresight_solver`` command with purely backward,
forward or static models, or with routines for semi-structural
models, and it must *not* be combined with option ``block`` of
the :bck:`model` block or :comm:`model_options` command. Also
note that for those models, the block decomposition is
performed as if ``mfs=3`` had been passed to the :bck:`model`
block or :comm:`model_options` command, and the decomposition
is slightly different because it is computed in a
time-recursive fashion (*i.e.* in such a way that the
simulation is meant to be done with the outer loop on periods
and the inner loop on blocks; while for models with both leads
and lags, the outer loop is on blocks and the inner loop is on
periods).
 
``14``
 
Computes a block decomposition and then applies a trust region
solver with autoscaling on those smaller blocks rather than on
the full nonlinear system. This is similar to ``4``, but is
typically more efficient. The block decomposition is done at
the preprocessor level, which brings two benefits: it
identifies blocks that can be evaluated rather than solved; and
evaluations of the residual and Jacobian of the model are more
efficient because only the relevant elements are recomputed at
every iteration.
Same as ``12``, except that it applies a trust region solver
(similar to ``4``) to the blocks.
 
|br| Default value is ``4``.
 
......@@ -2996,6 +3071,10 @@ Finding the steady state with Dynare nonlinear solver
``homotopy_setup`` block. This option can take three possible
values:
 
``0``
Do not use homotopy.
``1``
 
In this mode, all the parameters are changed
......@@ -3023,10 +3102,12 @@ Finding the steady state with Dynare nonlinear solver
that last case ``homotopy_steps`` contains the maximum
number of computations attempted before giving up.
 
|br| Default value is ``0``.
.. option:: homotopy_steps = INTEGER
 
Defines the number of steps when performing a homotopy. See
``homotopy_mode`` option for more details.
``homotopy_mode`` option for more details. Default is ``10``.
 
.. option:: homotopy_force_continue = INTEGER
 
......@@ -3053,6 +3134,10 @@ Finding the steady state with Dynare nonlinear solver
unit roots as, in this case, the steady state is not unique or
doesn’t exist.
 
.. option:: noprint
See :opt:`noprint`.
.. _steady_markowitz:
 
.. option:: markowitz = DOUBLE
......@@ -3088,6 +3173,13 @@ After computation, the steady state is available in the following variable:
ordered in the order of declaration used in the ``var`` command (which
is also the order used in ``M_.endo_names``).
 
.. matvar:: oo_.exo_steady_state
Contains the steady state of the exogenous variables, as declared by the
previous ``initval`` or ``endval`` block. Exogenous variables are
ordered in the order of declaration used in the ``varexo`` command (which
is also the order used in ``M_.exo_names``).
.. matcomm:: get_mean ('ENDOGENOUS_NAME' [, 'ENDOGENOUS_NAME']... );
 
Returns the steady of state of the given endogenous variable(s), as it is
......@@ -3095,6 +3187,7 @@ After computation, the steady state is available in the following variable:
been computed with ``steady``, it will first try to compute it.
 
.. block:: homotopy_setup ;
homotopy_setup(from_initval_to_endval) ;
 
This block is used to declare initial and final values when using
a homotopy method. It is used in conjunction with the option
......@@ -3123,12 +3216,26 @@ After computation, the steady state is available in the following variable:
 
Here only the final value is specified for a given
parameter/exogenous; the initial value is taken from the
preceeding ``initval`` block.
preceeding ``initval`` block (or from the preceeding ``endval`` block if
there is one before the ``homotopy_setup`` block).
 
A necessary condition for a successful homotopy is that Dynare
must be able to solve the steady state for the initial
parameters/exogenous without additional help (using the guess
values given in the ``initval`` block).
values given in the ``initval`` or ``endval`` block).
The ``from_initval_to_endval`` option can be used in the context of a
permanent shock, when the initial steady state has already been computed.
This option can be used following the ``endval`` block that describes the
terminal steady state. In that case, in the subsequent ``steady`` command,
Dynare will perform a homotopy from the initial to the terminal steady
state (technically, using this option is equivalent to writing a
``homotopy_setup`` block where all exogenous variables are asked to
transition from their values in the ``initval`` to their values in the
``endval`` block). When this option is used, the ``homotopy_setup`` block
is typically empty (but it’s nevertheless possible to add explicit
directives for moving exogenous or parameters; these will be added on top
of those implicitly generated by the ``from_initval_to_endval`` option).
 
If the homotopy fails, a possible solution is to increase the
number of steps (given in ``homotopy_steps`` option of
......@@ -3464,14 +3571,15 @@ Getting information about the model
 
|br| Prints the equations and the Jacobian matrix of the dynamic
model stored in the bytecode binary format file. Can only be used
in conjunction with the ``bytecode`` option of the ``model``
block.
in conjunction with the ``bytecode`` option of the :bck:`model`
block or :comm:`model_options` command.
 
.. command:: print_bytecode_static_model ;
 
|br| Prints the equations and the Jacobian matrix of the static model
stored in the bytecode binary format file. Can only be used in
conjunction with the ``bytecode`` option of the ``model`` block.
conjunction with the ``bytecode`` option of the :bck:`model`
block or :comm:`model_options` command.
 
 
.. _det-simul:
......@@ -3556,13 +3664,45 @@ speed-up on large models.
 
.. option:: periods = INTEGER
 
Number of periods of the simulation.
Number of periods of the simulation. This option is mandatory, unless
both ``first_simulation_period`` and ``last_simulation_period`` options
are given.
.. option:: first_simulation_period = DATE
Assign a date to the first simulation period, i.e. the first period in
which endogenous variables are solved for. When this option is set, it
becomes possible to declare shocks using dates, and
:comm:`perfect_foresight_solver` returns the result of the simulation as
a time series object in :mvar:`Simulated_time_series`.
.. option:: last_simulation_period = DATE
Assign a date to the last simulation period, i.e. the last period in
which endogenous variables are solved for. When this option is set, it
becomes possible to declare shocks using dates, and
:comm:`perfect_foresight_solver` returns the result of the simulation as
a time series object in :mvar:`Simulated_time_series`.
 
.. option:: datafile = FILENAME
 
Used to specify path for all endogenous and exogenous variables.
Strictly equivalent to :comm:`initval_file`.
 
.. option:: endval_steady
In scenarios with a permanent shock, specifies that the terminal
condition is a steady state, even if the ``steady`` command has not been
called after the ``endval`` block. As a consequence, the subsequent
``perfect_foresight_solver`` command will compute the terminal steady
state itself (given the value of the exogenous variables given in the
``endval`` block). In practice, this option is useful when the permanent
shock is very large, in which case the homotopy procedure inside
``perfect_foresight_solver`` will find both the terminal steady state
and the transitional dynamics within the same loop (which is less costly
than first computing the terminal steady state by homotopy, then
computing the transitional dynamics by homotopy).
*Output*
 
The paths for the exogenous variables are stored into
......@@ -3624,60 +3764,72 @@ speed-up on large models.
``0``
 
Use a Newton algorithm with a direct sparse LU solver at each
iteration, applied on the stacked system of all the equations at
every period (Default).
iteration, applied to the stacked system of all equations in all
periods (Default).
 
``1``
 
Use the Laffargue-Boucekkine-Juillard (LBJ) algorithm proposed
in *Juillard (1996)*. It is slower than ``stack_solve_algo=0``,
but may be less memory consuming on big models. Note that if the
``block`` option is used (see :ref:`model-decl`), a simple
Newton algorithm with sparse matrices is used for blocks which
are purely backward or forward (of type ``SOLVE BACKWARD`` or
``SOLVE FORWARD``, see :comm:`model_info`), since LBJ only makes
sense on blocks with both leads and lags (of type ``SOLVE TWO
BOUNDARIES``).
in *Juillard (1996)* on top of a LU solver. It is slower
than ``stack_solve_algo=0``, but may be less memory consuming on
big models. Note that if the ``block`` option is used (see
:ref:`model-decl`), a simple Newton algorithm with sparse
matrices, applied to the stacked system of all block equations
in all periods, is used for blocks which are purely backward or
forward (of type ``SOLVE BACKWARD`` or ``SOLVE FORWARD``, see
:comm:`model_info`), since LBJ only makes sense on blocks with
both leads and lags (of type ``SOLVE TWO BOUNDARIES``).
 
``2``
 
Use a Newton algorithm with a Generalized Minimal
Residual (GMRES) solver at each iteration (requires
``bytecode`` and/or ``block`` option, see
:ref:`model-decl`)
Use a Newton algorithm with a Generalized Minimal Residual
(GMRES) solver at each iteration, applied on the stacked system
of all equations in all periods. The following options can be
used to control the behaviour of the algorithm:
:opt:`preconditioner <preconditioner = OPTION>`, :opt:`iter_tol
<iter_tol = DOUBLE>`, :opt:`iter_maxit <iter_maxit = INTEGER>`,
:opt:`gmres_restart <gmres_restart = INTEGER>`.
 
``3``
 
Use a Newton algorithm with a Stabilized Bi-Conjugate
Gradient (BICGSTAB) solver at each iteration (requires
``bytecode`` and/or ``block`` option, see
:ref:`model-decl`).
Use a Newton algorithm with a Stabilized Bi-Conjugate Gradient
(BiCGStab) solver at each iteration, applied on the stacked
system of all equations in all periods. The following options
can be used to control the behaviour of the algorithm:
:opt:`preconditioner <preconditioner = OPTION>`, :opt:`iter_tol
<iter_tol = DOUBLE>`, :opt:`iter_maxit <iter_maxit = INTEGER>`.
 
``4``
 
Use a Newton algorithm with an optimal path length at
each iteration (requires ``bytecode`` and/or ``block``
option, see :ref:`model-decl`).
Use a Newton algorithm with a direct sparse LU solver and an
optimal path length at each iteration, applied on the stacked
system of all equations in all periods (requires ``bytecode``
and/or ``block`` option, see :ref:`model-decl`).
 
``5``
 
Use a Newton algorithm with a sparse Gaussian
elimination (SPE) solver at each iteration (requires
``bytecode`` option, see :ref:`model-decl`).
Use the Laffargue-Boucekkine-Juillard (LBJ) algorithm proposed
in *Juillard (1996)* on top of a sparse Gaussian elimination
(SPE) solver. The latter takes advantage of the similarity of
the Jacobian across periods when searching for the pivots. This
algorithm requires the :opt:`bytecode` option. The following
options can be used to control the behaviour of the algorithm:
:ref:`markowitz <dynamic_markowitz>`,
:opt:`minimal_solving_periods <minimal_solving_periods = INTEGER>`.
 
``6``
 
Synonymous for ``stack_solve_algo=1``. Kept for historical
reasons.
Synonymous for ``stack_solve_algo=1``. Kept for backward
compatibility.
 
``7``
 
Allows the user to solve the perfect foresight model
with the solvers available through option
``solve_algo`` (See :ref:`solve_algo <solvalg>` for a
list of possible values, note that values 5, 6, 7 and
8, which require ``bytecode`` and/or ``block`` options,
are not allowed). For instance, the following
Allows the user to solve the perfect foresight model with the
solvers available through option ``solve_algo``, applied on the
stacked system of all equations in all periods (See
:ref:`solve_algo <solvalg>` for a list of possible values, note
that values ``5``, ``6``, ``7`` and ``8``, which require ``bytecode`` and/or
``block`` options, are not allowed). For instance, the following
commands::
 
perfect_foresight_setup(periods=400);
......@@ -3686,15 +3838,131 @@ speed-up on large models.
trigger the computation of the solution with a trust
region algorithm.
 
.. option:: preconditioner = OPTION
When :opt:`stack_solve_algo <stack_solve_algo = INTEGER>` is equal to
``2`` or ``3``, this option specifies which preconditioner will be used
in combination with the iterative sparse linear solver (either GMRES or
BiCGStab). Possible values for OPTION are:
``umfiter``
At the first iteration of the nonlinear Newton solver, compute
the full LU decomposition with complete pivoting of the linear
system (and use it to solve that first iteration rather than
using the iterative solver). This LU decomposition is then used
as the preconditioner in further Newton iterations. Inspired
from TROLL’s option with the same name.
``iterstack``
Compute the LU decomposition with complete pivoting for only a
few simulation periods within the stacked Jacobian (which is a
block tridiagonal matrix). Then repeat that LU decomposition
over the block diagonal to construct a preconditioner for the
linear system with all simulation periods. If the total number
of simulations periods is not a multiple of the number of
periods used for the small LU, then an additional LU is computed
for the remainder. The following options can be used to control
the construction of this preconditioner:
:opt:`iterstack_maxlu <iterstack_maxlu = INTEGER>`,
:opt:`iterstack_nperiods <iterstack_nperiods = INTEGER>`,
:opt:`iterstack_nlu <iterstack_nlu = INTEGER>`,
:opt:`iterstack_relu <iterstack_relu = DOUBLE>`.
Inspired from TROLL’s solver with the same name.
``ilu``
Use an incomple LU decomposition as the preconditioner,
recomputed at every iteration of the nonlinear Newton solver.
|br| Default value is ``umfiter``.
.. option:: iter_tol = DOUBLE
When :opt:`stack_solve_algo <stack_solve_algo = INTEGER>` is equal to
``2`` or ``3``, this option controls the relative tolerance of the
iterative linear solver (either GMRES or BiCGStab). It corresponds to
the ``tol`` option of the ``gmres`` and ``bicgstab`` MATLAB/Octave
functions. Note that the perfect foresight solver uses an *absolute*
tolerance for determining convergence, so this option should be used
with care, and the default is meant to suit most situations.
Default: the value of the :opt:``tolf <tolf = DOUBLE>`` option, divided
by 10 times the infinite norm of the right-hand side of the linear system.
.. option:: iter_maxit = INTEGER
When :opt:`stack_solve_algo <stack_solve_algo = INTEGER>` is equal to
``2`` or ``3``, this option controls the maximum number of iterations of
the iterative linear solver (either GMRES or BiCGStab). It corresponds
to the ``maxit`` option of the ``gmres`` and ``bicgstab`` MATLAB/Octave
functions. It should not be confused with the :opt:`maxit <maxit = INTEGER>`
option, which controls the (outer) nonlinear Newton loop, while
``iter_maxit`` controls the (inner) linear loop. Default: ``500``.
.. option:: gmres_restart = INTEGER
When :opt:`stack_solve_algo <stack_solve_algo = INTEGER>` is equal to
``2``, this option controls the number of iterations before restart of
the GMRES algorithm. It corresponds to the ``restart`` option of the
``gmres`` MATLAB/Octave function. Default: ``100``.
.. option:: iterstack_maxlu = INTEGER
When :opt:`preconditioner <preconditioner = OPTION>` is equal to
``iterstack``, controls the maximum size of the matrix for which the
small LU will computed. The actual size of the matrix will be determined
by the largest number of periods that, multiplied by the number of
equations, is less than the value of the option. Note that when combined
with block decomposition (see :opt:`block`), blocks for which the
whole stacked system is less than this option will be solved using a
regular LU decomposition instead of the iterative linear solver.
Default: ``20000``.
.. option:: iterstack_nperiods = INTEGER
When :opt:`preconditioner <preconditioner = OPTION>` is equal to
``iterstack``, controls the number of periods used for the small LU.
If nonzero, this option overrides the :opt:`iterstack_maxlu <iterstack_maxlu = INTEGER>`
and :opt:`iterstack_nlu <iterstack_nlu = INTEGER>` options. Default: ``0``.
.. option:: iterstack_nlu = INTEGER
When :opt:`preconditioner <preconditioner = OPTION>` is equal to
``iterstack``, specifies the number of times that the small LU should be
repeated in the large preconditioner. If nonzero, this option overrides
the :opt:`iterstack_maxlu <iterstack_maxlu = INTEGER>` option. Default:
``0``.
.. option:: iterstack_relu = DOUBLE
When :opt:`preconditioner <preconditioner = OPTION>` is equal to
``iterstack``, controls the relative position of the small LU within the
whole stacked system. Must be a number between ``0`` and ``1``. Default:
``0.5``.
.. option:: robust_lin_solve
 
Triggers the use of a robust linear solver for the default
``stack_solve_algo=0``.
 
.. option:: check_jacobian_singularity
Triggers a check of the dynamic Jacobian for singularity during the first iteration.
Useful for detecting pathologies in the model specification. Available only for
``stack_solve_algo`` equal to ``0``, ``2`` or ``3``. Neither compatible with the i) ``block``,``bytecode``, and ``linear``
``model`` or ``model_options`` options nor ii) the ``linear_approximation`` and ``lmmcp`` options,
nor iii) with purely forward or backward models.
Due to computational intensity and high memory requirements,
it is strongly recommended to conduct this test with ``periods=1``.
.. option:: solve_algo
 
See :ref:`solve_algo <solvalg>`. Allows selecting the solver
used with ``stack_solve_algo=7``.
used with ``stack_solve_algo=7``. Also used for purely backward, forward
and static models (when neither the ``block`` nor the ``bytecode``
option of the :bck:`model` block or :comm:`model_options` command is specified);
for those models, the values ``12`` and ``14`` are especially relevant.
 
.. option:: no_homotopy
 
......@@ -3735,6 +4003,11 @@ speed-up on large models.
the homotopy procedure has been able to find a solution, then the approximate
solution returned is :math:`\frac{y(s^*)-y(0)}{s^*}`.
 
If linearization is triggered, the variable
:mvar:`oo_.deterministic_simulation.homotopy_linearization` is set, and
the simulation corresponding to share :math:`s^*` is stored in
:mvar:`oo_.deterministic_simulation.sim1`.
.. option:: homotopy_marginal_linearization_fallback [= DOUBLE]
 
Whenever the homotopy procedure is not able to find a solution for 100%
......@@ -3754,6 +4027,13 @@ speed-up on large models.
of :math:`\epsilon` is ``0.01`` by default, but can be modified by
passing some other value to the option.
 
If marginal linearization is triggered, the variable
:mvar:`oo_.deterministic_simulation.homotopy_marginal_linearization` is
set. Moreover, the simulation corresponding to share :math:`s^*` is
stored in :mvar:`oo_.deterministic_simulation.sim1`, and the one
corresponding to share :math:`s^*-\epsilon` is stored in
:mvar:`oo_.deterministic_simulation.sim2`.
.. option:: homotopy_max_completion_share = DOUBLE
 
Instructs Dynare, within the homotopy procedure, to not try to compute
......@@ -3763,13 +4043,21 @@ speed-up on large models.
``homotopy_marginal_linearization_fallback`` option. It is typically
used in situations where it is known that homotopy will fail to go
beyond a certain point, so as to save computing time, while at the same
time getting an approximate solution.
time getting an approximate solution. Default: ``1``.
.. option:: homotopy_exclude_varexo = (VARIABLE_NAME...)
A list of exogenous variables which are to be excluded from the homotopy
procedure, *i.e.* which must be kept at their value corresponding to
100% of the shock during all homotopy iterations.
.. _dynamic_markowitz:
 
.. option:: markowitz = DOUBLE
 
Value of the Markowitz criterion, used to select the
pivot. Only used when ``stack_solve_algo = 5``. Default:
``0.5``.
Value of the Markowitz criterion, used to select the pivot (see
:ref:`markowitz <steady_markowitz>` for more details). Only used when
``stack_solve_algo = 5``. Default: ``0.5``.
 
.. option:: minimal_solving_periods = INTEGER
 
......@@ -3781,9 +4069,9 @@ speed-up on large models.
.. option:: lmmcp
 
Solves the perfect foresight model with a Levenberg-Marquardt
mixed complementarity problem (LMMCP) solver (*Kanzow and Petra
(2004)*), which allows to consider inequality constraints on
the endogenous variables (such as a ZLB on the nominal interest
mixed complementarity problem (LMMCP) solver (*Kanzow and Petra,
2004*), which allows to consider inequality constraints on
the endogenous variables (such as a zero lower bound, henceforth ZLB, on the nominal interest
rate or a model with irreversible investment). This option is
equivalent to ``stack_solve_algo=7`` **and**
``solve_algo=10``. Using the LMMCP solver avoids the need for min/max
......@@ -3794,24 +4082,24 @@ speed-up on large models.
.. math::
LB = X &\Rightarrow F(X)>0\\
LB\leq X \leq UB &\Rightarrow F(X)=0\\
LB < X < UB &\Rightarrow F(X)=0\\
 
X =UB &\Rightarrow F(X)<0.
where :math:`X` denotes the vector of endogenous variables, :math:`F(X)` the equations
of the model, :math:`LB` denotes a lower bound, and :math:`UB` an upper bound. Such a setup
is implemented by attaching an equation tag (see :ref:`model-decl`)
with the ``mcp`` keyword to the affected equations. This tag states that
the equation to which the tag is attached has to hold unless the inequality
constraint within the tag is binding.
is implemented by specifying the complementarity condition after the
equation to which it is attached, the two being separated by the
perpendicular symbol (the latter can be input either in UTF-8, as ⟂,
corresponding to Unicode codepoint U+27C2; or alternatively as pure ASCII, as
_|_, *i.e.* a vertical bar enclosed within two underscores).
 
For instance, a ZLB on the nominal interest rate would be specified
as follows in the model block::
 
model;
...
[mcp = 'r > -1.94478']
r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;
r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e ⟂ r > -1.94478;
...
end;
 
......@@ -3822,12 +4110,11 @@ speed-up on large models.
``r<=-1.94478``, in which case the ``r`` is fixed at
``-1.94478`` (thereby being equivalent to a complementary
slackness condition). By restricting the value of ``r`` coming
out of this equation, the ``mcp`` tag also avoids using
out of this equation, the complementarity condition also avoids using
``max(r,-1.94478)`` for other occurrences of ``r`` in the rest
of the model. Two things are important to keep in mind. First, because the
``mcp`` tag effectively replaces a complementary slackness
condition, it cannot be simply attached to any
equation. Rather, it must be attached to the correct affected
of the model. Two things are important to keep in mind. First, the complementary slackness
condition cannot be simply attached to any
equation; it must be attached to the correct affected
equation as otherwise the solver will solve a different problem
than originally intended. Second, the sign of the residual of the dynamic
equation must conform to the MCP setup outlined above. In case of the ZLB,
......@@ -3842,15 +4129,17 @@ speed-up on large models.
``rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e`` is
below ``r=-1.94478``. In contrast, specifying the equation as
 
``rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e = r;```
``rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e = r;``
 
would be wrong.
 
Note that in the current implementation, the content of the
``mcp`` equation tag is not parsed by the preprocessor. The
inequalities must therefore be as simple as possible: an
endogenous variable, followed by a relational operator,
followed by a number (not a variable, parameter or expression).
Note that both the lower and the upper bounds can be specified at the
same time in a given complementarity condition. Moreover, arbitrary
functions of parameters can appear in the bounds. As an example, the
following complementarity condition is syntactically correct (assuming
that ``alpha`` is a parameter):
``… ⟂ -1.94478 < r < 1+2*alpha;``
 
.. option:: endogenous_terminal_period
 
......@@ -3863,7 +4152,7 @@ speed-up on large models.
shooting and relaxation approaches. Note that round off errors
are more important with this mixed strategy (user should check
the reported value of the maximum absolute error). Only
available with option ``stack_solve_algo==0``.
available with ``stack_solve_algo`` option equal to ``0``.
 
 
.. option:: linear_approximation
......@@ -3872,22 +4161,8 @@ speed-up on large models.
model. The model must be stationary and a steady state
needs to be provided. Linearization is conducted about the
last defined steady state, which can derive from ``initval``,
``endval`` or a subsequent ``steady``. Only available with option
``stack_solve_algo==0`` or ``stack_solve_algo==7``.
.. option:: endval_steady
In scenarios with a permanent shock, specifies that the terminal
condition is a steady state, even if the ``steady`` command has not been
called after the ``endval`` block. As a consequence, the
``perfect_foresight_solver`` command will compute the terminal steady
state itself (given the value of the exogenous variables given in the
``endval`` block). In practice, this option is useful when the permanent
shock is very large, in which case the homotopy procedure inside
``perfect_foresight_solver`` will find both the terminal steady state
and the transitional dynamics within the same loop (which is less costly
than first computing the terminal steady state by homotopy, then
computing the transitional dynamics by homotopy).
``endval`` or a subsequent ``steady``. Only available with
``stack_solve_algo`` option equal to ``0`` or ``7``.
 
.. option:: steady_solve_algo = INTEGER
 
......@@ -3922,8 +4197,15 @@ speed-up on large models.
*Output*
 
The simulated endogenous variables are available in global matrix
``oo_.endo_simul``.
:mvar:`oo_.endo_simul`.
If any of the ``first_simulation_period`` or ``last_simulation_period``
option was passed to the preceding :comm:`perfect_foresight_setup` command,
a time series object containing both endogenous and exogenous variables is
stored in the workspace variable :mvar:`Simulated_time_series`.
 
The variable :mvar:`oo_.deterministic_simulation.status` indicates whether
the simulation was successful or not.
 
.. command:: simul ;
simul (OPTIONS...);
......@@ -3940,29 +4222,53 @@ speed-up on large models.
.. matvar:: oo_.endo_simul
 
|br| This variable stores the result of a deterministic simulation
(computed by ``perfect_foresight_solver`` or ``simul``) or of a
stochastic simulation (computed by ``stoch_simul`` with the
periods option or by ``extended_path``). The variables are
arranged row by row, in order of declaration (as in
``M_.endo_names``). Note that this variable also contains initial
and terminal conditions, so it has more columns than the value of the
``periods`` option: the first simulation period is in
column ``1+M_.maximum_lag``, and the total number of columns is
(computed by ``perfect_foresight_solver`` or
``perfect_foresight_with_expectation_errors_solver``) or of a stochastic
simulation (computed by ``stoch_simul`` with the ``periods`` option or by
``extended_path``). The variables are arranged row by row, in order of
declaration (as in ``M_.endo_names``). Note that this variable also
contains initial and terminal conditions, so it has more columns than the
value of the ``periods`` option: the first simulation period is in column
``1+M_.maximum_lag``, and the total number of columns is
``M_.maximum_lag+periods+M_.maximum_lead``.
 
.. matvar:: oo_.exo_simul
 
|br| This variable stores the path of exogenous variables during a
simulation (computed by ``perfect_foresight_solver``, ``simul``,
``stoch_simul`` or ``extended_path``). The variables are arranged
in columns, in order of declaration (as in
``M_.exo_names``). Periods are in rows. Note that this convention
regarding columns and rows is the opposite of the convention for
``oo_.endo_simul``! Also note that this variable also contains initial
and terminal conditions, so it has more rows than the value of the
``periods`` option: the first simulation period is in row
``1+M_.maximum_lag``, and the total number of rows is
``M_.maximum_lag+periods+M_.maximum_lead``.
simulation (computed by ``perfect_foresight_solver``,
``perfect_foresight_with_expectation_errors_solver``, ``stoch_simul`` or
``extended_path``). The variables are arranged in columns, in order of
declaration (as in ``M_.exo_names``). Periods are in rows. Note that this
convention regarding columns and rows is the opposite of the convention for
``oo_.endo_simul``! Also note that this variable also contains initial and
terminal conditions, so it has more rows than the value of the ``periods``
option: the first simulation period is in row ``1+M_.maximum_lag``, and the
total number of rows is ``M_.maximum_lag+periods+M_.maximum_lead``.
.. matvar:: Simulated_time_series
|br| This variable stores, as a :class:`dseries` object, the path of both
endogenous and exogenous variables after a deterministic simulation
(computed by ``perfect_foresight_solver`` or
``perfect_foresight_with_expectation_errors_solver`` using the
``first_simulation_period`` and/or ``last_simulation_period`` option).
.. matvar:: oo_.initial_steady_state
If a permanent shock is simulated through the use of both ``initval`` and
``endval`` blocks, this variable contains the initial steady state, as
determined by the ``initval`` block (when followed by a ``steady``
command). This variable has the same structure as :mvar:`oo_.steady_state`
(and this latter variable contains the terminal steady state, if the
``endval`` block is followed by a ``steady`` command).
.. matvar:: oo_.initial_exo_steady_state
If a permanent shock is simulated through the use of both ``initval`` and
``endval`` blocks, this variable contains the initial steady state of the
exogenous variables, as specified in the ``initval`` block. This variable
has the same structure as :mvar:`oo_.exo_steady_state` (and this latter
variable contains the terminal steady state of the exogenous variables).
 
.. matvar:: M_.maximum_lag
 
......@@ -3978,6 +4284,42 @@ speed-up on large models.
variables, so in practice it is either 1 or 0 (the latter value corresponds
to a purely backward or static model).
 
.. matvar:: oo_.deterministic_simulation.status
|br| Set to ``true`` by the :comm:`perfect_foresight_solver` command if the
simulation succeeded, otherwise set to ``false``.
.. matvar:: oo_.deterministic_simulation.homotopy_linearization
|br| Set to ``true`` by the :comm:`perfect_foresight_solver` command if
linearization has been used to compute an approximate solution.
.. matvar:: oo_.deterministic_simulation.homotopy_marginal_linearization
|br| Set to ``true`` by the :comm:`perfect_foresight_solver` command if
marginal linearization has been used to compute an approximate solution.
.. matvar:: oo_.deterministic_simulation.sim1
|br| Set by the :comm:`perfect_foresight_solver` command if either
linearization or marginal linearization has been used to compute an
approximate solution. This structure contains the simulation corresponding
to the greatest share of the shocks for which an exact solution could be
computed. The subfield ``homotopy_completion_share`` contains that share.
The subfields ``endo_simul``, ``exo_simul``, ``steady_state`` and
``exo_steady_state`` respectively contain the path of endogenous, the path
of exogenous, the steady state of endogenous and the steady state of
exogenous for that simulation (with the same conventions as the fields of
of the same name in ``oo_``).
.. matvar:: oo_.deterministic_simulation.sim2
|br| Set by the :comm:`perfect_foresight_solver` command if marginal
linearization has been used to compute an approximate solution. This
structure contains the simulation corresponding to a share marginally
smaller that the one in :mvar:`oo_.deterministic_simulation.sim1`. The
subfields are the same as in :mvar:`oo_.deterministic_simulation.sim1`.
Perfect foresight with expectation errors
-----------------------------------------
 
......@@ -3999,16 +4341,16 @@ Such a scenario can be solved by Dynare using the
``perfect_foresight_with_expectation_errors_solver`` commands, alongside ``shocks``
and ``endval`` blocks which are given a special ``learnt_in`` option.
 
.. block:: shocks(learnt_in=INTEGER) ;
shocks(learnt_in=INTEGER,overwrite) ;
.. block:: shocks(learnt_in=INTEGER|DATE) ;
shocks(learnt_in=INTEGER|DATE, overwrite) ;
 
|br| The ``shocks(learnt_in=INTEGER)`` can be used to specify temporary
|br| The ``shocks(learnt_in=INTEGER|DATE)`` syntax can be used to specify temporary
shocks that are learnt in a specific period. It should contain one or more
occurences of the following group of three lines, with the same semantics
as a regular :bck:`shocks` block::
 
var VARIABLE_NAME;
periods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;
periods INTEGER[:INTEGER] | DATE[:DATE] [[,] INTEGER[:INTEGER] | DATE[:DATE]]...;
values DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
 
If the period in which information is learnt is greater or equal than 2,
......@@ -4016,14 +4358,17 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
to the values that were expected from the perspective of the previous
period. If the new information consists of an addition to the
previously-anticipated value, the ``values`` keyword can be replaced by the
``add`` keyword; similarly, if the new information consists of an addition to the
previously-anticipated value, the ``values`` keyword can be replaced by the
``multiply`` keyword.
``add`` keyword; similarly, if the new information consists of a
multiplication of the previously-anticipated value, the ``values`` keyword
can be replaced by the ``multiply`` keyword.
 
The ``overwrite`` option says that this block cancels and replaces previous
``shocks`` blocks that have the same ``learnt_in`` option.
``shocks`` and ``mshocks`` blocks that have the same ``learnt_in`` option.
Note that a block with an integer-valued ``learnt_in`` option never
overwrites a block with a date-valued ``learnt_in`` option, even if they
correspond to the same period.
 
Note that a ``shocks(learnt_in=1)`` block is equivalent to a regular
Also note that a ``shocks(learnt_in=1)`` block is equivalent to a regular
:bck:`shocks` block.
 
*Example*
......@@ -4058,14 +4403,36 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
- from the perspective of periods 4 (and following), ``x`` is expected to
be equal to 1.3 in period 4, and to 2.8 in period 5.
 
.. block:: endval(learnt_in=INTEGER) ;
*Example* (with dates)
::
shocks(learnt_in=2023Q1);
var x;
periods 2023Q1:2023Q2 2023Q3:2023Q4 2024Q1;
values 1 1.2 1.4;
end;
 
|br| The ``endval(learnt_in=INTEGER)`` can be used to specify terminal
.. block:: endval(learnt_in=INTEGER|DATE) ;
|br| The ``endval(learnt_in=INTEGER|DATE)`` can be used to specify terminal
conditions that are learnt in a specific period.
 
Note that an ``endval(learnt_in=1)`` block is equivalent to a regular
:bck:`endval` block.
 
Also note that, similarly to the regular :bck:`endval` block, any variable
specified in this block will jump to its new value in the same period as
the one in which the information is learnt; and, from the perspective of
that period, the variable is expected by agents to remain to that value
until the end of the simulation. In particular, this means that any
temporary shock that may have been anticipated on that variable (as
specified through a ``shocks(learnt_in=...)`` block for a previous
informational period) will be overridden; if this is not the desired
behaviour, then the temporary shock will have to be reinstated through
another ``shocks(learnt_in=...)`` block.
It is possible to express the terminal condition by specifying the level of
the exogenous variable (using an equal symbol, as in a regular
:bck:`endval` blocks without the ``learnt_in`` option). But it is also
......@@ -4095,6 +4462,89 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
Those values will be the realized ones, unless there is another
``endval(learnt_in=p)`` block with ``p>3``.
 
The three variables will jump to their new value in period 3 and, from the
perspective of period 3, they are expected by agents to remain there until
the end of the simulation. In particular, any temporary shock on either
``x``, ``y`` or ``z`` specified through a regular ``shocks`` block or
through a ``shocks(learnt_in=2)`` block will be overridden. If this is not
the desired behaviour, a ``shocks(learnt_in=3)`` block will have to be
added to reinstate the temporary shock.
*Example* (with a date)
::
endval(learnt_in = 2024Q1);
x = 1.1;
end;
.. block:: mshocks(learnt_in=INTEGER|DATE) ;
mshocks(learnt_in=INTEGER|DATE,OPTIONS...) ;
|br| The ``mshocks(learnt_in=INTEGER|DATE)`` syntax can be used to specify temporary
shocks that are learnt in a specific period, specified in a multiplicative
way. It should contain one or more occurences of the following group of
three lines, with the same semantics as a regular :bck:`mshocks` block::
var VARIABLE_NAME;
periods INTEGER[:INTEGER] | DATE[:DATE] [[,] INTEGER[:INTEGER] | DATE[:DATE]]...;
values DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
As in the regular :bck:`mshocks` block (without the ``learnt_in`` option),
the values are interpreted as a multiplicative factor over the steady state
value of the exogenous variable (the latter being taken either from the
``initval`` or ``endval``, see :bck:`mshocks` for the details).
If the terminal steady state as specified in the ``endval`` block is used
as a basis for the multiplication, its value as anticipated from the period
given in the ``learnt_in`` option will be used.
Note that a ``mshocks(learnt_in=1)`` block is equivalent to a regular
:bck:`mshocks` block.
*Options*
.. option:: overwrite
This block cancels and replaces previous ``shocks`` and ``mshocks``
blocks that have the same ``learnt_in`` option. Note that a block with
an integer-valued ``learnt_in`` option never overwrites a block with a
date-valued ``learnt_in`` option, even if they correspond to the same
period.
.. option:: relative_to_initval
Same meaning as in the regular :bck:`mshocks` block.
*Example*
::
mshocks(learnt_in=2);
var x;
periods 3:4;
values 1.1;
end;
This syntax means that from the perspective of period 2, ``x`` in periods 3
and 4 is expected to be equal to 1.1 times its steady state. If there is no
``endval`` block, the initial steady state as given by ``initval`` is used;
if there is an ``endval`` block, the terminal steady state as anticipated
from the perspective of period 2 is used (as specified in the relevant
``endval(learnt_in=…`` block)).
*Example* (with dates)
::
mshocks(learnt_in=2024Q2);
var x;
periods 2024Q3:2024Q4;
values 1.1;
end;
.. command:: perfect_foresight_with_expectation_errors_setup ;
perfect_foresight_with_expectation_errors_setup (OPTIONS...);
 
......@@ -4121,6 +4571,14 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
 
Number of periods of the simulation.
 
.. option:: first_simulation_period = DATE
Same meaning as the eponymous option of :comm:`perfect_foresight_setup`.
.. option:: last_simulation_period = DATE
Same meaning as the eponymous option of :comm:`perfect_foresight_setup`.
.. option:: datafile = FILENAME
 
Used to specify the information about future shocks and their
......@@ -4232,8 +4690,8 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
x = 1.1;
end;
 
.. command:: perfect_foresight_with_expectation_solver ;
perfect_foresight_with_expectation_solver (OPTIONS...);
.. command:: perfect_foresight_with_expectation_errors_solver ;
perfect_foresight_with_expectation_errors_solver (OPTIONS...);
 
|br| Computes the perfect foresight simulation with expectation errors
of the model.
......@@ -4252,12 +4710,14 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
By default, every time the information set changes, the simulation with
the new information set is shorter than the previous one (because the
terminal date is getting closer). When this option is set, every new
simulation has the same length (as specified by the `periods`` option
of :comm:`perfect_foresight_with_expectation_errors_setup`; as a
simulation has the same length (as specified by the ``periods`` option
of :comm:`perfect_foresight_with_expectation_errors_setup`); as a
consequence, the simulated paths as stored in ``oo_.endo_simul`` will
be longer when this option is set (if `s` is the last period in which
the information set is modified, then they will contain `s+periods-1`
periods, excluding initial and terminal conditions).
periods, excluding initial and terminal conditions). Note that this
option is not available if ``last_simulation_period`` option has been
passed to :comm:`perfect_foresight_with_expectation_errors_setup`.
 
*Output*
 
......@@ -4266,6 +4726,12 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
last period of the information set are available in ``oo_.steady_state``
and ``oo_.exo_steady_state``.
 
If any of the ``first_simulation_period`` or ``last_simulation_period``
option was passed to the preceding
:comm:`perfect_foresight_with_expectation_errors_setup` command, a time
series object containing both endogenous and exogenous variables is stored
in the workspace variable :mvar:`Simulated_time_series`.
.. matvar:: oo_.pfwee.shocks_info
 
|br| This variable stores the temporary shocks used during perfect
......@@ -4287,6 +4753,144 @@ and ``endval`` blocks which are given a special ``learnt_in`` option.
the terminal condition for exogenous indexed ``k``, as anticipated from
period ``s``, is stored in ``oo_.pfwee.terminal_info(k,s)``.
 
Controlling the path of endogenous variables
--------------------------------------------
In the usual perfect foresight problem, the user controls the path of exogenous
variables for the simulation periods and the initial and terminal
conditions for endogenous variables, while Dynare solves for the path of
endogenous variables for the simulation periods.
However, Dynare offers the possibility of controlling the value of some
endogenous variables for some simulation periods (in which case some exogenous
variables must be left free and are thus solved for by Dynare, to avoid
over-determination of the problem). This exercise is called “conditional
forecasting” in some contexts (even though one may argue that this is not
really forecasting, since perfect foresight by the agents is assumed; for the
stochastic case, see the :comm:`conditional_forecast` command).
The description of controlled endogenous variables is done using the
``perfect_foresight_controlled_paths`` block. The information given therein is
then processed by the :comm:`perfect_foresight_setup` (or
:comm:`perfect_foresight_with_expectation_errors_setup`) command, so
that the next :comm:`perfect_foresight_solver` (or
:comm:`perfect_foresight_with_expectation_errors_solver`) command
computes the simulation with controlled paths. In particular,
:mvar:`oo_.exo_simul` will contain the computed value of exogenous variables
that have been left free.
.. block:: perfect_foresight_controlled_paths ;
perfect_foresight_controlled_paths(OPTIONS...);
|br| This block is used to tell the perfect foresight solver that the value
of some endogenous variables will be controlled (in other words, they will
be exogenized). It also gives the period(s) for which this control applies,
the value(s) imposed to the endogenous variable(s), and the exogenous
variable(s) that are left free at the same period(s) (in other words,
those exogenous are endogenized).
The block should contain one or more occurrences of the following
group of four lines::
exogenize ENDOGENOUS_NAME;
periods INTEGER[:INTEGER] | DATE[:DATE] [[,] INTEGER[:INTEGER] | DATE[:DATE]]...;
values DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
endogenize EXOGENOUS_NAME;
Note that it is possible to have both
``perfect_foresight_controlled_paths`` and regular :bck:`shocks` blocks in
the same ``.mod`` file (assuming of course that taken together they do not
impose inconsistent constraints).
The ``perfect_foresight_controlled_paths`` block requires that the
:opt:`stack_solve_algo <stack_solve_algo = INTEGER>` option be equal to
either ``0``, ``1``, ``2``, ``3``, ``6`` or ``7``, and is incompatible with
the :opt:`block` and :opt:`bytecode` options of the :bck:`model` block and
:comm:`model_options` command.
*Options*
.. option:: learnt_in = INTEGER | DATE
Used in conjunction with
:comm:`perfect_foresight_with_expectation_errors_setup` and
:comm:`perfect_foresight_with_expectation_errors_solver` commands,
specifies the period or date at which this controlled paths block is
learnt by agents.
*Example (perfect foresight)*
::
var c k;
varexo x z;
...
shocks;
var x;
periods 1;
values 1.2;
end;
perfect_foresight_controlled_paths;
exogenize c;
periods 2 4:5;
values 1.6 1.7;
endogenize x;
exogenize k;
periods 7:9;
values 13;
endogenize z;
end;
perfect_foresight_setup(periods = 100);
perfect_foresight_solver;
In this example, the exogenous variable ``x`` is equal to 1.2 in
period 1, but in periods 2, 4 and 5 it will be endogenized so that
endogenous variable `c` is equal to 1.6 in period 2 and then 1.7 in
periods 4 and 5. Similarly, the exogenous variable ``z`` will be
endogenized in periods 7 to 9 so that the endogenous variable ``k`` is
equal to 13 over the same periods.
*Example (perfect foresight with expectation errors)*
::
var c;
varexo x;
...
perfect_foresight_controlled_paths;
exogenize c;
periods 2002Y 2003Y:2005Y;
values 1.6 1.7;
endogenize x;
end;
perfect_foresight_controlled_paths(learnt_in=2004Y);
exogenize c;
periods 2004Y:2005Y;
values 1.8;
endogenize x;
end;
perfect_foresight_with_expectation_errors_setup(periods = 30,
first_simulation_period = 2001Y);
perfect_foresight_with_expectation_errors_solver;
In this example, agents in year 2001 (at beginning of the simulation)
compute their plan under the assumption that the endogenous variable
``c`` will be equal to 1.6 in year 2002 and 1.7 from years 2003 to
2005, and that exogenous variable ``x`` will behave so as to fulfill
that constraint. Then, when 2004 arrives, they recompute their plan
under the assumption that ``c`` will be equal to 1.8 in years 2004 and
2005 (and again that ``x`` will be endogenized accordingly).
.. _stoch-sol:
 
Stochastic solution and simulation
......@@ -4477,6 +5081,11 @@ Computing the stochastic solution
Don’t print moments of the endogenous variables (printing them
is the default).
 
.. option:: nomodelsummary
Don’t print the model summary and the covariance of the exogenous shocks (printing them
is the default).
.. option:: nograph
 
Do not create graphs (which implies that they are not saved to
......@@ -4499,8 +5108,8 @@ Computing the stochastic solution
graph_format = ( FORMAT, FORMAT... )
 
Specify the file format(s) for graphs saved to disk. Possible
values are ``eps`` (the default), ``pdf``, ``fig`` and ``none``
(under Octave, ``fig`` is unavailable). If the
values are ``eps`` (the default), ``pdf``, ``fig`` and ``none``.
Under Octave, ``fig`` will use Octave’s ``ofig`` format. If the
file format is set equal to ``none``, the graphs are displayed
but not saved to the disk.
 
......@@ -4638,31 +5247,6 @@ Computing the stochastic solution
and this option has no effect. More references can be found
`here <https://archives.dynare.org/DynareWiki/PartialInformation>`__ .
 
.. option:: sylvester = OPTION
Determines the algorithm used to solve the Sylvester equation
for block decomposed model. Possible values for OPTION are:
``default``
Uses the default solver for Sylvester equations
(``gensylv``) based on Ondra Kamenik’s algorithm (see
`here
<https://www.dynare.org/assets/team-presentations/sylvester.pdf>`__
for more information).
``fixed_point``
Uses a fixed point algorithm to solve the Sylvester
equation (``gensylv_fp``). This method is faster than
the default one for large scale models.
|br| Default value is ``default``.
.. option:: sylvester_fixed_point_tol = DOUBLE
The convergence criterion used in the fixed point
Sylvester solver. Its default value is ``1e-12``.
 
.. option:: dr = OPTION
 
......@@ -4677,7 +5261,7 @@ Computing the stochastic solution
 
``cycle_reduction``
 
Uses the cycle reduction algorithm to solve the
Uses the cycle reduction algorithm of ``Bini et al. (2002)`` to solve the
polynomial equation for retrieving the coefficients
associated to the endogenous variables in the decision
rule. This method is faster than the default one for
......@@ -4685,7 +5269,7 @@ Computing the stochastic solution
 
``logarithmic_reduction``
 
Uses the logarithmic reduction algorithm to solve the
Uses the logarithmic reduction algorithm of ``Bini et al. (2002)`` to solve the
polynomial equation for retrieving the coefficients
associated to the endogenous variables in the decision
rule. This method is in general slower than the
......@@ -4698,6 +5282,11 @@ Computing the stochastic solution
The convergence criterion used in the cycle reduction
algorithm. Its default value is ``1e-7``.
 
.. option:: dr_cycle_reduction_maxiter = INTEGER
The maximum number of iterations used in the cycle
reduction algorithm. Its default value is ``100``.
.. option:: dr_logarithmic_reduction_tol = DOUBLE
 
The convergence criterion used in the logarithmic reduction
......@@ -4756,14 +5345,10 @@ Computing the stochastic solution
 
If the ``periods`` option is present, sets ``oo_.skewness``,
``oo_.kurtosis``, and ``oo_.endo_simul`` (see
:mvar:`oo_.endo_simul`), and also saves the simulated variables in
MATLAB/Octave vectors of the global workspace with the same name
as the endogenous variables.
:mvar:`oo_.endo_simul`).
 
If option ``irf`` is different from zero, sets ``oo_.irfs`` (see
below) and also saves the IRFs in MATLAB/Octave vectors of the
global workspace (this latter way of accessing the IRFs is
deprecated and will disappear in a future version).
below).
 
If the option ``contemporaneous_correlation`` is different from
``0``, sets ``oo_.contemporaneous_correlation``, which is
......@@ -4972,10 +5557,13 @@ Computing the stochastic solution
For example, ``oo_.irfs.gnp_ea`` contains the effect on ``gnp`` of
a one-standard deviation shock on ``ea``.
 
.. matcomm:: get_irf ('EXOGENOUS_NAME' [, 'ENDOGENOUS_NAME']... );
.. matcomm:: IRF_MATRIX=get_irf ('EXOGENOUS_NAME' [, 'ENDOGENOUS_NAME']... );
 
|br| Given the name of an exogenous variables, returns the IRFs for the
requested endogenous variable(s), as they are stored in ``oo_.irfs``.
|br| Given the name of an exogenous variable, returns the IRFs for the
requested endogenous variable(s) (as they are stored in ``oo_.irfs``) in the output
``IRF_MATRIX``. The periods are stored along the first dimension, with the steady
state in the first row. The variables are stored along the second dimension. If no
endogenous variables were specified, the matrix contains all variables stored in ``oo_.irfs``.
 
The approximated solution of a model takes the form of a set of
decision rules or transition equations expressing the current value of
......@@ -5024,12 +5612,13 @@ which is described below.
 
If order is greater than ``0`` Dynare uses a gaussian
quadrature to take into account the effects of future
uncertainty. If ``order`` :math:`=S` then the time series for
uncertainty; this is called *stochastic* extended path, see *Adjemian
and Juillard (2025)*. If ``order`` :math:`=S` then the time series for
the endogenous variables are generated by assuming that the
agents believe that there will no more shocks after period
:math:`t+S`. This is an experimental feature and can be quite
slow. A non-zero value is not compatible with the ``bytecode``
option of the ``model`` block.
option of the :bck:`model` block or :comm:`model_options` command.
Default: ``0``.
 
.. option:: hybrid
......@@ -5045,7 +5634,14 @@ which is described below.
(2004)*), which allows to consider inequality constraints on
the endogenous variables (such as a ZLB on the nominal interest
rate or a model with irreversible investment). For specifying the
necessary ``mcp`` tag, see :opt:`lmmcp`.
necessary complementarity conditions, see :opt:`lmmcp`.
.. option:: use_first_order_solution
Utilize the model simulation based on a first-order local
approximation as the initial guess for the nonlinear solver in
each period. If this is not applied, solution in previous
period is used.
 
 
Typology and ordering of variables
......@@ -5356,7 +5952,7 @@ All of these elements are discussed in the following.
::
 
occbin_constraints;
name 'ELB'; bind inom <= iss-1e8; relax inom > iss+1e-8;
name 'ELB'; bind inom <= iss-1e-8; relax inom > iss+1e-8;
end;
 
The ``error_bind`` and ``error_relax`` options are optional and allow specifying
......@@ -5448,11 +6044,22 @@ All of these elements are discussed in the following.
or the piecewise Kalman filter (default). An issue that can arise in the context of
estimation is a structural shock dropping out of the model in a particular regime.
For example, at the zero lower bound on interest rates, the monetary policy shock
in the Taylor rule will not appear anymore. This may create a problem
of stochastic singularity if there are then more observables than shocks. To
avoid this issue, the data points for the zero interest rate should be set
to NaN and the standard deviation of the associated shock set to 0 for the
corresponding periods using the ``heteroskedastic_shocks`` block.
in the Taylor rule will not appear anymore. This may create a problem if there are
then more observables than shocks. The way to handle this issue depends on the type of filter used.
The first step is to set the data points for the zero interest rate period to NaN. For the piecewise
Kalman filter, the standard deviation of the associated shock needs to be set to 0 for the
corresponding periods using the ``heteroskedastic_shocks`` block. This avoids stochastic singularity.
However, this approach does not work for the inversion filter as the ``heteroskedastic_shocks`` block
does not do anything here. For the inversion filter, as many shocks as observables are required
at each point in time. Dynare assumes a one-to-one mapping between the declared shocks in
``varexo`` and declared observables in ``varobs``. For example, if the second declared observable
is NaN in a given period, Dynare will drop the second declared shock.
.. warning:: If there are missing values, it is imperative for the inversion filter that the
declaration order of shocks and observables is conformable. Sticking with our example, if the nominal
interest is the second ``varobs`` and is set to NaN, the inversion filter will drop the second
declared shock. If that second declared shock is, e.g., a TFP shock, it will be dropped instead
of the intended monetary policy shock.
 
Note that models with unit roots will require the user to specify the ``diffuse_filter`` option as
otherwise Blanchard-Kahn errors will be triggered. For the piecewise Kalman filter, the
......@@ -5645,6 +6252,14 @@ All of these elements are discussed in the following.
 
See :opt:`simul_check_ahead_periods <simul_check_ahead_periods = INTEGER>`.
 
.. option:: simul_reset_check_ahead_periods
See :opt:`simul_reset_check_ahead_periods`.
.. option:: simul_max_check_ahead_periods
See :opt:`simul_max_check_ahead_periods <simul_max_check_ahead_periods = INTEGER>`.
.. option:: simul_curb_retrench
 
See :opt:`simul_curb_retrench`.
......@@ -6136,9 +6751,8 @@ observed variables.
The Monte Carlo Markov Chain (MCMC) diagnostics are generated by
the estimation command if :opt:`mh_replic <mh_replic = INTEGER>`
is larger than 2000 and if option :opt:`nodiagnostic` is not
used. If :opt:`mh_nblocks <mh_nblocks = INTEGER>` is equal to one,
the convergence diagnostics of *Geweke (1992,1999)* is
computed. It uses a chi-square test to compare the means of the
used. By default, the convergence diagnostics of *Geweke (block_iter1992,1999)* is
computed for each chain. It uses a chi-square test to compare the means of the
first and last draws specified by :opt:`geweke_interval
<geweke_interval = [DOUBLE DOUBLE]>` after discarding the burn-in
of :opt:`mh_drop <mh_drop = DOUBLE>`. The test is computed using
......@@ -6146,7 +6760,7 @@ observed variables.
as well as using tapering windows specified in :opt:`taper_steps
<taper_steps = [INTEGER1 INTEGER2 ...]>`. If :opt:`mh_nblocks
<mh_nblocks = INTEGER>` is larger than 1, the convergence
diagnostics of *Brooks and Gelman (1998)* are used instead. As
diagnostics of *Brooks and Gelman (1998)* are also provided. As
described in section 3 of *Brooks and Gelman (1998)* the
univariate convergence diagnostics are based on comparing pooled
and within MCMC moments (Dynare displays the second and third
......@@ -6201,9 +6815,9 @@ observed variables.
 
.. option:: nobs = INTEGER
 
The number of observations following :opt:`first_obs <first_obs
= [INTEGER1:INTEGER2]>` to be used. Default: all observations
in the file after ``first_obs``.
The number of observations following :opt:`first_obs
<first_obs = [INTEGER1:INTEGER2]>` to be used. Default: all
observations in the file after ``first_obs``.
 
.. option:: nobs = [INTEGER1:INTEGER2]
 
......@@ -6244,8 +6858,8 @@ observed variables.
 
.. option:: presample = INTEGER
 
The number of observations after :opt:`first_obs <first_obs =
[INTEGER1:INTEGER2]>` to be skipped before evaluating the
The number of observations after :opt:`first_obs
<first_obs = [INTEGER1:INTEGER2]>` to be skipped before evaluating the
likelihood. These presample observations do not enter the
likelihood, but are used as a training sample for starting the
Kalman filter iterations. This option is incompatible with
......@@ -6369,8 +6983,8 @@ observed variables.
 
Do not use the kalman filter to evaluate the likelihood, but instead
evaluate the conditional likelihood, based on the first order reduced
form of the model, by assuming that the initial state vector is 0 for all
the endogenous variables. This approach requires that:
form of the model, by assuming that the initial state vector is at its
steady state. This approach requires that:
 
1. The number of structural innovations be equal to the number of observed variables.
 
......@@ -6385,7 +6999,7 @@ observed variables.
Note however that the conditional likelihood is sensitive to the choice
for the initial condition, which can be an issue if the data are
initially far from the steady state. This option is not compatible with
``analytical_derivation``.
``analytic_derivation``.
 
.. option:: conf_sig = DOUBLE
 
......@@ -6526,7 +7140,7 @@ observed variables.
.. option:: mh_tune_guess = DOUBLE
 
Specifies the initial value for the :opt:`mh_tune_jscale
<mh_tune_jscale [= DOUBLE]>` option. Default: ``2.39/sqrt(n)``. Must not
<mh_tune_jscale [= DOUBLE]>` option. Default: ``2.38/sqrt(n)``. Must not
be set if :opt:`mh_tune_jscale <mh_tune_jscale [= DOUBLE]>` is
not used.
 
......@@ -6654,13 +7268,10 @@ observed variables.
 
``11``
 
This is not strictly speaking an optimization
algorithm. The (estimated) parameters are treated as
state variables and estimated jointly with the
original state variables of the model using a
nonlinear filter. The algorithm implemented in Dynare
is described in *Liu and West (2001)*, and works with
``k`` order local approximations of the model.
Currently not in use. The Liu and West (2020) filter that
used to be available under this option value is now triggered with
``posterior_sampling_method='online'``.
 
``12``
 
......@@ -6775,9 +7386,9 @@ observed variables.
 
.. option:: prior_trunc = DOUBLE
 
Probability of extreme values of the prior density that is
Probability of extreme values of the prior density in each tail that is
ignored when computing bounds for the parameters. Default:
``1e-32``.
``1e-10`` for ``posterior_sampling_method=slice`` and ``0`` otherwise .
 
.. option:: huge_number = DOUBLE
 
......@@ -6855,8 +7466,7 @@ observed variables.
A list of NAME and VALUE pairs. Can be used to set options for
the optimization routines. The set of available options depends
on the selected optimization routine (i.e. on the value of
option :opt:`mode_compute <mode_compute = INTEGER |
FUNCTION_NAME>`):
option :opt:`mode_compute <mode_compute = INTEGER | FUNCTION_NAME>`):
 
``1, 3, 7, 12, 13``
 
......@@ -6998,6 +7608,18 @@ observed variables.
Stopping criteria. Default: ``1e-5`` for numerical
derivatives, ``1e-7`` for analytic derivatives.
 
``'robust'``
Trigger more robust but computationally more expensive line search. Default: ``false``.
``'TolGstep'``
Tolerance parameter used for tuning gradient step. Default: same value as ``TolFun``.
``'TolGstepRel'``
Parameter used for tuning gradient step, governing the tolerance relative to the functions value. Default: not triggered.
``'verbosity'``
 
Controls verbosity of display during
......@@ -7233,7 +7855,7 @@ observed variables.
Triggers the computation of the posterior distribution of
IRFs. The length of the IRFs are controlled by the ``irf``
option. Results are stored in ``oo_.PosteriorIRF.dsge`` (see
below for a description of this variable).
below for a description of this variable). Not compatible with OccBin.
 
.. option:: relative_irf
 
......@@ -7286,6 +7908,12 @@ observed variables.
density is recentered to the previous draw in every
step.
 
``'dime_mcmc'``
Instructs Dynare to use the Differential-Independence Mixture Ensemble ("DIME") MCMC sampler of *Boehl (2022)* instead of the standard Random-Walk Metropolis-Hastings. DIME is robust for odd shaped, multimodal, black-box distributions and shown to require significantly less likelihood evaluations than alternative samplers. Many chains run simultaneously, thereby further increasing sampling speed. The algorithm is based on a gradient-free global multi-start optimizer and does not require any posterior mode density maximization prior to MCMC sampling. DIME proposals are generated from an endogenous and adaptive proposal distribution, thereby providing close-to-optimal proposal distributions for black box target distributions without manual fine-tuning. Does not yet support ``moments_varendo``, ``bayesian_irf``, and ``smoother``.
Note that, since DIME is using parameter transformations, setting parameter bounds is often counterproductive. The ``prior_trunc`` option is disabled and set to zero.
``'tailored_random_block_metropolis_hastings'``
 
Instructs Dynare to use the Tailored randomized block
......@@ -7331,13 +7959,35 @@ observed variables.
Chain draws than the MH-algorithm. Its relative (in)efficiency can be investigated via
the reported inefficiency factors.
 
.. option:: posterior_sampler_options = (NAME, VALUE, ...)
``'hssmc'``
 
A list of NAME and VALUE pairs. Can be used to set options for
the posterior sampling methods. The set of available options
depends on the selected posterior sampling routine (i.e. on the
value of option :opt:`posterior_sampling_method
<posterior_sampling_method = NAME>`):
Instructs Dynare to use the *Herbst and Schorfheide (2014)*
version of the Sequential Monte-Carlo sampler instead of the
standard Random-Walk Metropolis-Hastings. Does not yet support
``moments_varendo``, ``bayesian_irf``, and ``smoother``.
``'dsmh'``
Instructs Dynare to use the Dynamic Striated Metropolis Hastings
sampler proposed by *Waggoner, Wu and Zha (2016)* instead of the
standard Random-Walk Metropolis-Hastings.
``'online'``
Instructs Dynare to treat the (estimated) parameters as
state variables and estimate them jointly with the
original state variables of the model using a
nonlinear filter. The algorithm implemented in Dynare
is described in *Liu and West (2001)*, and works with
``k`` order local approximations of the model.
.. option:: posterior_sampler_options = (NAME, VALUE, ...)
A list of NAME and VALUE pairs. Can be used to set options for
the posterior sampling methods. The set of available options
depends on the selected posterior sampling routine (i.e. on the
value of option :opt:`posterior_sampling_method
<posterior_sampling_method = NAME>`):
 
``'random_walk_metropolis_hastings'``
 
......@@ -7370,8 +8020,7 @@ observed variables.
Indicates to use the covariance matrix of the draws
from a previous MCMC run to define the covariance of
the proposal distribution. Requires the
:opt:`load_mh_file` option to be specified. Default:
``0``.
:opt:`load_mh_file` option to be specified. Default: ``0``.
 
.. _scale-file:
 
......@@ -7390,13 +8039,50 @@ observed variables.
the draws when the current ``_mh*_blck`` file is
full. Default: ``0``
 
``'dime_mcmc'``
Available options are:
``'niter'``
Number of iterations. Default value is 1500.
``'nchain'``
Number of chains/particles. A range between :math:`4 ndim` and :math:`6 ndim` is recommended. For very difficult problems, double the number of chains. Default value is: :math:`5 ndim`.
``'tune'``
Number of ensemble iterations to keep after burnin. Default value is chosen to obtain at least 50,000 samples.
``'aimh_prob'``
Probability to draw a global transition kernel. By default this is set to :math:`0.1`. It is usually not necessary to change this value.
``'df_proposal_dist'``
Degrees of freedom of the multivariate t distribution used for global kernel proposals. Defaults to :math:`10`.
``'rho'``
Decay parameter for the mean and covariances of the global transistion kernel. Defaults to :math:`0.999`.
``'gamma'``
Mean stretch factor for the proposal vector. By default, it is :math:`2.38 / \sqrt{2\,\mathrm{ndim}}` as recommended by *ter Braak (2006)*
``'sigma'``
Standard deviation of the Gaussian used to stretch the proposal vector. This is normally negligible. Defaults to :math:`1e-5`.
``'independent_metropolis_hastings'``
 
Takes the same options as in the case of
``random_walk_metropolis_hastings``.
Takes the same options as in the case of ``random_walk_metropolis_hastings``.
 
``'slice'``
 
Available options are:
``'rotated'``
 
Triggers rotated slice iterations using a covariance
......@@ -7443,6 +8129,8 @@ observed variables.
 
``'tailored_random_block_metropolis_hastings'``
 
Available options are:
``'proposal_distribution'``
 
Specifies the statistical distribution used for the
......@@ -7461,8 +8149,9 @@ observed variables.
 
Specifies the mode-finder run in every iteration for
every block of the TaRB Metropolis-Hastings
algorithm. See :opt:`mode_compute <mode_compute =
INTEGER | FUNCTION_NAME>`. Default: ``4``.
algorithm. See :opt:`mode_compute
<mode_compute = INTEGER | FUNCTION_NAME>`.
Default: ``4``.
 
``optim = (NAME, VALUE,...)``
 
......@@ -7478,6 +8167,36 @@ observed variables.
 
See :ref:`save_tmp_file <savetmp>`. Default: ``1``.
 
``'hssmc'``
Available options are:
``'particles'``
Number of particles. Default value is: 20000.
``'steps'``
Number of weights :math:`\phi_i\in[0,1]` on the likelihood function used to define a sequence of tempered likelihoods. This parameter is denoted :math:`N_{\phi}` in *Herbst and Schorfheide (2014)*, and we have :math:`\phi_1=0` and :math:`\phi_{N_\phi}=1`. Default value is: 25.
``'lambda'``
Positive parameter controling the sequence of weights :math:`\phi_i`, Default value is: 2. Weights are defined by:
.. math::
\phi_i = \left(\frac{i-1}{N_{\phi}-1}\right)^{\lambda}
for :math:`i=1,\ldots,N_{\phi}`. Usually we set :math:`\lambda>1`, so that :math:`\Delta \phi_i = \phi_i-\phi_{i-1}` is increasing with :math:`i`.
``'target'``
Acceptance rate target. Default value is: .25.
``'scale'``
Scale parameter in the mutation step (on the proposal covariance matrix of the MH iteration). Default value is: .5.
.. option:: moments_varendo
 
Triggers the computation of the posterior distribution of the
......@@ -7485,7 +8204,7 @@ observed variables.
stored in ``oo_.PosteriorTheoreticalMoments`` (see
:mvar:`oo_.PosteriorTheoreticalMoments`). The number of lags in
the autocorrelation function is controlled by the ``ar``
option.
option. Not compatible with OccBin.
 
.. option:: contemporaneous_correlation
 
......@@ -7570,7 +8289,7 @@ observed variables.
the posterior mode. If a Metropolis-Hastings is computed, the
distribution of forecasts is stored in variables
``oo_.PointForecast`` and ``oo_.MeanForecast``. See
:ref:`fore`, for a description of these variables.
:ref:`fore`, for a description of these variables. Not compatible with OccBin.
 
.. option:: tex
 
......@@ -7762,27 +8481,44 @@ observed variables.
 
.. option:: irf_shocks = ( VARIABLE_NAME [[,] VARIABLE_NAME ...] )
 
See :opt:`irf_shocks <irf_shocks = ( VARIABLE_NAME [[,]
VARIABLE_NAME ...] )>`. Only used if :opt:`bayesian_irf` is
passed.
See :opt:`irf_shocks
<irf_shocks = ( VARIABLE_NAME [[,] VARIABLE_NAME ...] )>`.
Only used if :opt:`bayesian_irf` is passed.
 
.. option:: irf_plot_threshold = DOUBLE
 
See :opt:`irf_plot_threshold <irf_plot_threshold =
DOUBLE>`. Only used if :opt:`bayesian_irf` is passed.
See :opt:`irf_plot_threshold
<irf_plot_threshold = DOUBLE>`.
Only used if :opt:`bayesian_irf` is passed.
 
.. option:: aim_solver
 
See :opt:`aim_solver`.
 
.. option:: sylvester = OPTION
.. option:: dr = OPTION
See :opt:`dr <dr = OPTION>`. Default: ``default``, i.e. generalized
Schur decomposition.
.. option:: dr_cycle_reduction_tol = DOUBLE
 
See :opt:`sylvester <sylvester = OPTION>`.
See :opt:`dr_cycle_reduction_tol <dr_cycle_reduction_tol = DOUBLE>`.
Default: ``1e-7``.
 
.. option:: sylvester_fixed_point_tol = DOUBLE
.. option:: dr_cycle_reduction_maxiter = INTEGER
See :opt:`dr_cycle_reduction_maxiter <dr_cycle_reduction_maxiter = INTEGER>`.
Default: ``100``.
.. option:: dr_logarithmic_reduction_tol = DOUBLE
See :opt:`dr_logarithmic_reduction_tol <dr_logarithmic_reduction_tol = DOUBLE>`.
Default: ``1e-12``.
.. option:: dr_logarithmic_reduction_maxiter = INTEGER
 
See :opt:`sylvester_fixed_point_tol <sylvester_fixed_point_tol
= DOUBLE>` .
See :opt:`dr_logarithmic_reduction_maxiter <dr_logarithmic_reduction_maxiter = INTEGER>`.
Default: ``100``.
 
.. option:: lyapunov = OPTION
 
......@@ -7927,9 +8663,10 @@ observed variables.
 
Percentage of MCMC draws at the beginning and end of the MCMC
chain taken to compute the *Geweke (1992,1999)* convergence
diagnostics (requires :opt:`mh_nblocks=1 <mh_nblocks =
INTEGER>`) after discarding the first :opt:`mh_drop = DOUBLE
<mh_drop>` percent of draws as a burnin. Default: [0.2 0.5].
diagnostics (requires :opt:`mh_nblocks=1
<mh_nblocks = INTEGER>`) after discarding
the first :opt:`mh_drop <mh_drop = DOUBLE>` percent of draws
as a burnin. Default: [0.2 0.5].
 
.. option:: raftery_lewis_diagnostics
 
......@@ -8000,17 +8737,16 @@ observed variables.
 
Resampling if and only if the effective sample size is
below a certain level defined by
:opt:`resampling_threshold <resampling_threshold =
DOUBLE>` * :opt:`number_of_particles
<number_of_particles = INTEGER>`.
:opt:`resampling_threshold <resampling_threshold = DOUBLE>`
* :opt:`number_of_particles <number_of_particles = INTEGER>`.
 
.. option:: resampling_threshold = DOUBLE
 
A real number between zero and one. The resampling step is
triggered as soon as the effective number of particles is less
than this number times the total number of particles (as set by
:opt:`number_of_particles <number_of_particles =
INTEGER>`). This option is effective if and only if option
:opt:`number_of_particles <number_of_particles = INTEGER>`).
This option is effective if and only if option
:opt:`resampling <resampling = OPTION>` has value ``generic``.
 
.. option:: resampling_method = OPTION
......@@ -8108,7 +8844,8 @@ observed variables.
 
``'liu_west_delta'``
 
Set the value for delta for the Liu/West online filter. Default: ``0.99``.
Set the value for delta for the Liu/West online filter (``posterior_sampling_method='online'``).
Default: ``0.99``.
 
``'unscented_alpha'``
 
......@@ -8292,8 +9029,8 @@ observed variables.
 
Inverse Hessian matrix at the mode or MCMC jumping
covariance matrix when used with the
:opt:`MCMC_jumping_covariance <mcmc_jumping_covariance
= OPTION>` option.
:opt:`MCMC_jumping_covariance <mcmc_jumping_covariance = OPTION>`
option.
 
``log_density``
 
......@@ -8810,8 +9547,7 @@ observed variables.
.. matvar:: oo_.convergence.geweke
 
Variable set by the convergence diagnostics of the ``estimation``
command when used with ``mh_nblocks=1`` option (see
:opt:`mh_nblocks <mh_nblocks = INTEGER>`).
command. There is a subfield in the struct array for each MCMC chain.
 
Fields are of the form::
 
......@@ -8851,8 +9587,8 @@ observed variables.
<geweke_interval = [DOUBLE DOUBLE]>` and weighting them with
their relative precision. It is a vector containing the
results under the iid assumption followed by the ones using
the ``taper_steps`` option (see :opt:`taper_steps <taper_steps
= [INTEGER1 INTEGER2 ...]>`).
the ``taper_steps`` option (see :opt:`taper_steps
<taper_steps = [INTEGER1 INTEGER2 ...]>`).
 
``pooled_nse``
 
......@@ -8875,7 +9611,8 @@ observed variables.
 
Variable set by the convergence diagnostics of the ``estimation``
command when used with ``raftery_lewis_diagnostics`` option (see
:opt:`raftery_lewis_diagnostics`). Contains the results of the test in individual fields.
:opt:`raftery_lewis_diagnostics`). There is a subfield in the struct array
for each MCMC chain. Contains the results of the test in individual fields.
 
 
.. command:: unit_root_vars VARIABLE_NAME...;
......@@ -8907,21 +9644,27 @@ Dynare also has the ability to estimate Bayesian VARs:
 
Estimation based on moments
===========================
Provided that you have observations on some endogenous variables
or their dynamic behavior following structural shocks,
Dynare provides a suite of tools for parameter estimation utilizing the method of moments approach.
This includes the Simulated Method of Moments (SMM),
the Generalized Method of Moments (GMM),
and Impulse Response Function Matching (IRF matching).
Each of these methods offers a distinct strategy for estimating some or all parameters
by minimizing the distances between unconditional model objects (moments or impulse responses)
and their empirical counterparts.
 
Provided that you have observations on some endogenous variables, it
is possible to use Dynare to estimate some or all parameters using a
method of moments approach. Both the Simulated Method of Moments (SMM)
and the Generalized Method of Moments (GMM) are available. The general
idea is to minimize the distance between unconditional model moments
and corresponding data moments (so called orthogonality or moment
conditions). For SMM, Dynare computes model moments via stochastic
**GMM and SMM estimation**
For SMM Dynare computes model moments via stochastic
simulations based on the perturbation approximation up to any order,
whereas for GMM model moments are computed in closed-form based on the
pruned state-space representation of the perturbation solution up to third
order. The implementation of SMM is inspired by *Born and Pfeifer (2014)*
pruned state-space representation of the perturbation solution up to third order.
The implementation of SMM is inspired by *Born and Pfeifer (2014)*
and *Ruge-Murcia (2012)*, whereas the one for GMM is adapted from
*Andreasen, Fernández-Villaverde and Rubio-Ramírez (2018)* and *Mutschler
(2018)*. Successful estimation heavily relies on the accuracy and efficiency of
*Andreasen, Fernández-Villaverde and Rubio-Ramírez (2018)* and *Mutschler (2018)*.
Successful estimation heavily relies on the accuracy and efficiency of
the perturbation approximation, so it is advised to tune this as much as
possible (see :ref:`stoch-sol-simul`). The method of moments estimator is consistent
and asymptotically normally distributed given certain regularity conditions
......@@ -8965,10 +9708,45 @@ to more plausible regions of the parameter space. Ideally, these regions are
characterized by only slightly worse values of the objective function. Note that
adding prior information comes at the cost of a loss in efficiency of the estimator.
 
**IRF matching**
Dynare employs a user-specified `simulation_method` to compute the impulse response function (IRF)
for observable variables with respect to the structural shocks.
Currently, only stochastic simulations based on the perturbation method are supported
and it is advised to fine-tune the perturbation approximation as much as possible for optimal results
(see :ref:`stoch-sol-simul` for guidance).
The core idea of IRF matching is then to treat empirical impulse responses
(e.g. given from a SVAR or local projection estimation) as data
and select model parameters that align the model's IRFs closely with their empirical counterparts.
Dynare supports both Frequentist and Bayesian IRF matching approaches,
using the same optimization and sampling techniques as those applied in likelihood-based estimation
(sharing many options with the :ref:`estimation command <estim-comm>`).
The Frequentist approach to this is inspired by the work of *Christiano, Eichenbaum, and Evans (2005)*,
while the Bayesian method adapts from *Christiano, Trabandt, and Walentin (2010)*.
A crucial element in IRF matching is the choice of the weighting matrix,
which influences how the distances between model-generated and empirical IRFs are weighted in the estimation process.
It is common practice to employ a diagonal weighting matrix,
with the diagonal elements set to the inverse of the estimated variance of the respective empirical impulse response,
thereby prioritizing more precisely estimated IRFs.
While it's possible to also specify weights using covariances between different IRF components (possibly with shrinking),
this is less common due to the complex interpretation involved
(cross effects of different variables or different shocks or both).
Importantly, it is the user's responsibility to supply
(1) the values of the empirical IRFs intended for matching
and (2) their importance by choosing an appropriate weighting matrix.
Dynare does not perform the SVAR or local projection estimation,
it treats the empirical IRFs as given.
Method of moments specific blocks
---------------------------------
.. command:: varobs VARIABLE_NAME...;
 
|br| Required. All variables used in the :bck:`matched_moments` block
need to be observable. See :ref:`varobs <varobs>` for more details.
|br| Required. All variables used in the :bck:`matched_moments`, :bck:`matched_irfs`,
or :bck:`matched_irfs_weights` block need to be observable.
See :ref:`varobs <varobs>` for more details.
 
.. block:: matched_moments ;
 
......@@ -9029,17 +9807,147 @@ adding prior information comes at the cost of a loss in efficiency of the estima
last row, which is the same as the second-to-last one. The original block is
saved in ``M_.matched_moments_orig``.
 
.. block:: matched_irfs ;
matched_irfs(overwrite);
|br| This block specifies the values and diagonal weights of the empirical IRFs that are matched in estimation.
The ``overwrite`` option replaces the current ``matched_irfs`` block with the new one.
Each line inside of the block should be of the form::
var ENDOGENOUS_NAME;
varexo EXOGENOUS_NAME;
periods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;
values DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
weights DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;
`ENDOGENOUS_NAME` is the name of a declared observable variable,
whereas `EXOGENOUS_NAME` is the name of an exogenous variable.
It is possible to specify individual horizons or a range of specified periods
as lists with the ``periods`` keyword.
Note that for each entry a corresponding entry in ``values`` needs to be provided;
that is ``values`` is a list of the same length as ``periods``.
If only one value is specified, it is used at all corresponding ``periods`` in the list.
``weights`` are optional and specify the diagonal element of the corresponding
entry in the weighting matrix.
Typically, these are set to the inverse of the variance of the empirical IRF.
If only one weight is specified, it is used at all corresponding ``periods`` in the list.
If not specified, the weight defaults to 1.
For ``values`` and ``weights`` you can use expressions (e.g. variables or anonymous functions
in the workspace) by by putting paranthesis around them.
A new statement is started with either the ``var`` or ``varexo`` keyword.
*Example*
You can either enter the values directly or load them from variables in the workspace.
::
% MATLAB expressions that can be used
xx = [23,24,25];
ww = [51,52];
irfs_eR = @(j) IRFFF(2:15,j); % gdp is the 3th column of IRFFF
weights_eR = @(j) 1./(IRFFFSE(2:15,j).^2);
R_eR = IRFFF(1:15,3);
weight_R_eR = 1./(IRFFFSE(1:15,3).^2);
matched_irfs;
var gdp; varexo eR; periods 2:15; values (irfs_eR(3)); weights (weights_eR(3));
var R; varexo eR; periods 1:15; values (R_eR); weights (weight_R_eR);
var y; varexo eD; periods 5; values 7; weights 25;
var r; varexo eD; periods 1,2; values 17,18; weights 37,38;
var c; varexo eA; periods 3:5; values (xx);
var y; varexo eA; periods 1:2; values 30; weights (ww);
varexo eR;
var w;
periods 1, 13:15, 2:12;
values 2, (xx), 15;
weights 3, (xx), 4;
end;
*Limitations*
*Output*
Dynare translates the :bck:`matched_irfs` block into a cell array
where the rows correspond to the statements in the block
``M_.matched_irfs`` where:
* the first column contains the names of the endogenous variables
* the second column contains the names of the exogenous variables
* the third column contains a nested cell array that contains
the list of horizons, values and weights.
.. block:: matched_irfs_weights ;
matched_irfs_weights(overwrite) ;
|br| This optional block specifies elements of the weighting matrix used for IRF matching.
The ``overwrite`` option replaces the current ``matched_irfs_weights`` block with the new one.
The weighting matrix is initialized as a diagonal matrix with ones on the diagonal.
Each line inside of the block should be of the form::
ENDOGENOUS_NAME_1(HORIZON_1), EXOGENOUS_NAME_1, ENDOGENOUS_NAME_2(HORIZON_2), EXOGENOUS_NAME_2, WEIGHT;
where `ENDOGENOUS_NAME_1` and `ENDOGENOUS_NAME_2` are the names of declared observable variables,
`EXOGENOUS_NAME_1` and `EXOGENOUS_NAME_2` are the names of exogenous variables,
`HORIZON_1` and `HORIZON_2` are integers indicating the horizon of the IRFs
and `WEIGHT` is a double value of the weight one wants to assign to the covariance between the two specified IRFs.
*Example*
You can either enter the values directly or load them from variables in the workspace.
::
matched_irfs_weights;
c(1), e_A, c(1), e_A, 20;
y(3), e_R, y(2), e_R, (empIRFsCovInv_yR3_yR2);
end;
*Limitations*
*Output*
Dynare translates the :bck:`matched_irfs_weights` block into a cell array
``M_.matched_irfs_weights`` where:
* the first column contains the names of the first endogenous variables
* the second column contains the names of the first exogenous variables
* the third column contains the horizons of the IRFs for the first endogneous variable
* the fourth column contains the names of the second endogenous variables
* the fifth column contains the names of the second exogenous variables
* the sixth column contains the horizons of IRFs for the second endogenous variable
* the seventh column contains the vector of weights
All values that are not specified will be either one (if they are on the diagonal)
or zero (if they are not on the diagonal).
Symmetry is respected, so one does not need to specify both
``c(1), e_A, y(3), e_R, WEIGHT`` and ``y(3), e_R, c(1), e_A, WEIGHT``.
Default: empty cell.
.. block:: estimated_params ;
 
|br| Required. See :bck:`estimated_params` for the meaning and syntax.
|br| Required.
This block lists all parameters to be estimated and specifies
bounds and priors as necessary.
See :bck:`estimated_params` for details and syntax.
.. block:: estimated_params_init ;
 
|br| See :bck:`estimated_params_init` for the meaning and syntax.
|br| Optional.
This block declares numerical initial values for the
optimizer when these ones are different from the prior mean.
See :bck:`estimated_params_init` for details and syntax.
 
.. block:: estimated_params_bounds ;
 
|br| See :bck:`estimated_params_bounds` for the meaning and syntax.
|br| Optional.
This block declares lower and upper bounds for parameters in maximum likelihood estimation.
See :bck:`estimated_params_bounds` for details and syntax.
method_of_moments command
-------------------------
 
.. command:: method_of_moments (OPTIONS...);
 
......@@ -9049,27 +9957,32 @@ adding prior information comes at the cost of a loss in efficiency of the estima
* Overview of options chosen by the user
* Estimation results for each stage and iteration
* Value of minimized moment distance objective function
* Result of the J-test
* Table of data moments and estimated model moments
* Result of the J-test (for SMM/GMM)
* Comparison plot of model IRFs and empirical IRFs (for IRF matching)
* Table of data moments/IRFs and estimated model moments/IRFs
 
*Necessary options*
Necessary Options
^^^^^^^^^^^^^^^^^^
 
.. option:: mom_method = SMM|GMM
.. option:: mom_method = SMM|GMM|IRF_MATCHING
 
"Simulated Method of Moments" is triggered by `SMM` and
"Generalized Method of Moments" by `GMM`.
"Simulated Method of Moments" is triggered by `SMM`,
"Generalized Method of Moments" by `GMM` and
"Impulse Response Function Matching" by `IRF_MATCHING`.
 
.. option:: datafile = FILENAME
 
The name of the file containing the data. See
The name of the file containing the data (for GMM and SMM only). See
:opt:`datafile <datafile = FILENAME>` for the meaning and syntax.
For IRF matching, the data is specified in the :bck:`matched_irfs` block.
 
*Options common for SMM and GMM*
Common Options
^^^^^^^^^^^^^^
.. option:: order = INTEGER
 
Order of perturbation approximation. For GMM only orders 1|2|3 are
supported. For SMM, you can choose an arbitrary order. Note that the
supported. For SMM and IRF matching, you can choose an arbitrary order. Note that the
order set in other functions will not overwrite the default.
Default: ``1``.
 
......@@ -9077,7 +9990,15 @@ adding prior information comes at the cost of a loss in efficiency of the estima
 
Discard higher order terms when iteratively computing simulations
of the solution. See :opt:`pruning <pruning>` for more details.
Default: not set for SMM, always set for GMM.
Default: not set for SMM and IRF matching, always set for GMM.
.. option:: verbose
Display and store intermediate estimation results in ``oo_.mom``.
Default: not set.
*Common options for SMM and GMM*
 
.. option:: penalized_estimator
 
......@@ -9137,12 +10058,8 @@ adding prior information comes at the cost of a loss in efficiency of the estima
errors with a two-sided finite difference method.
Default: ``1e-5``.
 
.. option:: verbose
Display and store intermediate estimation results in ``oo_.mom``.
Default: not set.
*SMM-specific options*
SMM specific options
^^^^^^^^^^^^^^^^^^^^
 
.. option:: burnin = INTEGER
 
......@@ -9164,7 +10081,8 @@ adding prior information comes at the cost of a loss in efficiency of the estima
Multiple of data length used for simulation.
Default: ``7``.
 
*GMM-specific options*
GMM specific options
^^^^^^^^^^^^^^^^^^^^
 
.. option:: analytic_standard_errors
 
......@@ -9173,7 +10091,54 @@ adding prior information comes at the cost of a loss in efficiency of the estima
Default: not set, i.e. standard errors are computed using a two-sided
finite difference method, see :opt:`se_tolx <se_tolx = DOUBLE>`.
 
*General options*
IRF matching specific options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. option:: simulation_method = METHOD
Method to compute IRFs. Possible values for ``METHOD`` are:
``STOCH_SIMUL``
Simulate the model with stochastic simulations and compute IRFs
as the difference between the simulated and steady state values.
See :opt:`stoch_simul` for more details.
.. option:: irf_matching_file = FILENAME
A MATLAB file containing additional transformations on the model IRFs.
This enables more flexibility in matching the model IRFs to the empirical IRFs,
e.g. by adding constants to model IRFs, multiplying them with factors,
taking the cumulative sum, creating ratios etc.
See ``NK_irf_matching_file.m`` in the examples directory for an example.
Default: empty, i.e. model IRFs exactly match empirical IRFs.
.. option:: add_tiny_number_to_cholesky = DOUBLE
In case of a non-positive definite covariance matrix,
a tiny number is added to the Cholesky factor
to avoid numerical problems when computing IRFs.
Default: `1e-14`.
.. option:: drop = INTEGER
Truncation when computing IRFs with perturbation at orders greater than 1.
Default: ``100``.
.. option:: relative_irf
Requests the computation of normalized IRFs.
See :opt:`relative_irf` for more details.
Default: false.
.. option:: replic = INTEGER
Number of simulated series used to compute the IRFs.
Default: ``1`` if ``order=1``, and ``50`` otherwise.
General options
^^^^^^^^^^^^^^^
 
.. option:: dirname = FILENAME
 
......@@ -9214,7 +10179,15 @@ adding prior information comes at the cost of a loss in efficiency of the estima
 
See :opt:`tex`. Default: not set.
 
*Data options*
Data options
^^^^^^^^^^^^
.. option:: prefilter = INTEGER
A value of 1 means that the estimation procedure will demean each data
series by its empirical mean and each model moment by its theoretical
mean. See :opt:`prefilter <prefilter = INTEGER>` for more details.
Default: ``0``, i.e. no prefiltering.
 
.. option:: first_obs = INTEGER
 
......@@ -9226,57 +10199,226 @@ adding prior information comes at the cost of a loss in efficiency of the estima
See :opt:`nobs <nobs = INTEGER>`.
Default: all observations are considered.
 
.. option:: prefilter = INTEGER
.. option:: logdata
 
A value of 1 means that the estimation procedure will demean each data
series by its empirical mean and each model moment by its theoretical
mean. See :opt:`prefilter <prefilter = INTEGER>` for more details.
Default: ``0``, i.e. no prefiltering.
See :opt:`logdata <logdata>`. Default: not set.
 
.. option:: logdata
.. option:: xls_sheet = QUOTED_STRING
See :opt:`xls_sheet <xls_sheet = QUOTED_STRING>`.
Default: ``1``.
.. option:: xls_range = RANGE
See :opt:`xls_range <xls_range = RANGE>`.
Default: empty.
Optimization options
^^^^^^^^^^^^^^^^^^^^
.. option:: mode_file = FILENAME
Name of the file containing previous value for the mode.
See :opt:`mode_file <mode_file = FILENAME>`.
Default: empty.
.. option:: mode_compute = INTEGER | FUNCTION_NAME
See :opt:`mode_compute <mode_compute = INTEGER | FUNCTION_NAME>`.
Default: ``13`` for GMM and SMM and ``5`` for IRF matching.
.. option:: additional_optimizer_steps = [INTEGER]
additional_optimizer_steps = [INTEGER1:INTEGER2]
additional_optimizer_steps = [INTEGER1 INTEGER2]
Vector of additional minimization algorithms run after ``mode_compute``.
If :opt:`verbose` option is set, then the additional estimation
results are saved into the ``oo_.mom`` structure prefixed with `verbose_`.
Default: empty, i.e. no additional optimization iterations.
.. option:: optim = (NAME, VALUE, ...)
See :opt:`optim <optim = (NAME, VALUE, ...)>`.
Default: empty.
.. option:: analytic_jacobian
Use analytic Jacobian in optimization, only available for GMM and gradient-based optimizers.
Default: not set.
.. option:: huge_number = DOUBLE
See :opt:`huge_number <huge_number = DOUBLE>`.
Default: ``1e7``.
.. option:: silent_optimizer
See :opt:`silent_optimizer`.
Default: not set.
.. option:: use_penalized_objective_for_hessian
See :opt:`use_penalized_objective_for_hessian <use_penalized_objective_for_hessian>`.
Default: not set.
Bayesian estimation options
^^^^^^^^^^^^^^^^^^^^^^^^^^^
**General options**
.. option:: posterior_sampling_method = NAME
See :opt:`posterior_sampling_method <posterior_sampling_method = NAME>`.
Default: ``random_walk_metropolis_hastings``.
.. option:: posterior_sampler_options = (NAME, VALUE, ...)
See :opt:`posterior_sampler_options <posterior_sampler_options = (NAME, VALUE, ...)>`.
Default: not set.
.. option:: mh_posterior_mode_estimation
See :opt:`mh_posterior_mode_estimation`.
Default: not set.
.. option:: cova_compute = INTEGER
See :opt:`cova_compute <cova_compute = INTEGER>`.
Default: ``1``.
.. option:: mcmc_jumping_covariance = OPTION
See :opt:`mcmc_jumping_covariance <mcmc_jumping_covariance = OPTION>`.
Default: ``hessian``.
.. option:: mh_replic = INTEGER
See :opt:`mh_replic <mh_replic = INTEGER>`.
Default: ``0``.
.. option:: mh_nblocks = INTEGER
See :opt:`mh_nblocks <mh_nblocks = INTEGER>`.
Default: ``2``.
.. option:: mh_jscale = DOUBLE
See :opt:`mh_jscale <mh_jscale = DOUBLE>`.
Default: ``2.38`` divided by the square root of the number of estimated parameters.
.. option:: mh_tune_jscale [= DOUBLE]
See :opt:`mh_tune_jscale <mh_tune_jscale [= DOUBLE]>`.
Default: ``0.33``.
.. option:: mh_tune_guess = DOUBLE
See :opt:`mh_tune_guess <mh_tune_guess = DOUBLE>`.
Default: ``2.38`` divided by the square root of the number of estimated parameters.
.. option:: mh_conf_sig = DOUBLE
See :opt:`mh_conf_sig <mh_conf_sig = DOUBLE>`.
Default: ``0.9``.
.. option:: mh_drop = DOUBLE
See :opt:`mh_drop <mh_drop = DOUBLE>`.
Default: ``0.5``.
.. option:: mh_init_scale_factor = DOUBLE
See :opt:`mh_init_scale_factor <mh_init_scale_factor = DOUBLE>`.
Default: ``2``.
.. option:: no_posterior_kernel_density
See :opt:`no_posterior_kernel_density`.
Default: not set.
.. option:: posterior_max_subsample_draws = INTEGER
See :opt:`posterior_max_subsample_draws <posterior_max_subsample_draws = INTEGER>`.
Default: ``1200``.
.. option:: sub_draws = INTEGER
See :opt:`sub_draws <sub_draws = INTEGER>`.
Default: ``min(posterior_max_subsample_draws, (Total number of draws)*(number of chains) )``.
**MCMC initialization and recovery**
.. option:: load_mh_file
See :opt:`load_mh_file`.
Default: not set.
.. option:: load_results_after_load_mh
See :opt:`load_results_after_load_mh`.
Default: not set.
.. option:: mh_initialize_from_previous_mcmc
See :opt:`mh_initialize_from_previous_mcmc`.
Default: not set.
.. option:: mh_initialize_from_previous_mcmc_directory = FILENAME
See :opt:`mh_initialize_from_previous_mcmc_directory <mh_initialize_from_previous_mcmc_directory = FILENAME>`.
Default: empty.
.. option:: mh_initialize_from_previous_mcmc_prior = FILENAME
See :opt:`mh_initialize_from_previous_mcmc_prior <mh_initialize_from_previous_mcmc_prior = FILENAME>`.
Default: empty.
.. option:: mh_initialize_from_previous_mcmc_record = FILENAME
See :opt:`mh_initialize_from_previous_mcmc_record <mh_initialize_from_previous_mcmc_record = FILENAME>`.
Default: empty.
See :opt:`logdata <logdata>`. Default: not set.
.. option:: mh_recover
 
.. option:: xls_sheet = QUOTED_STRING
See :opt:`mh_recover`.
Default: not set.
 
See :opt:`xls_sheet <xls_sheet = QUOTED_STRING>`.
**Convergence diagnostics**
 
.. option:: xls_range = RANGE
.. option:: nodiagnostic
 
See :opt:`xls_range <xls_range = RANGE>`.
See :opt:`nodiagnostic`.
Default: not set.
 
*Optimization options*
.. option:: brooks_gelman_plotrows = INTEGER
 
.. option:: huge_number = DOUBLE
See :opt:`brooks_gelman_plotrows <brooks_gelman_plotrows = INTEGER>`.
Default: ``3``.
See :opt:`huge_number <huge_number = DOUBLE>`.
Default: ``1e7``.
.. option:: geweke_interval = [DOUBLE DOUBLE]
 
.. option:: mode_compute = INTEGER | FUNCTION_NAME
See :opt:`geweke_interval <geweke_interval = [DOUBLE DOUBLE]>`.
Default: ``[0.2 0.5]``.
 
See :opt:`mode_compute <mode_compute = INTEGER | FUNCTION_NAME>`.
Default: ``13``, i.e. ``lsqnonlin`` if the MATLAB Optimization Toolbox or
the Octave optim-package are present, ``4``, i.e. ``csminwel`` otherwise.
.. option:: taper_steps = [INTEGER1 INTEGER2 ...]
 
.. option:: additional_optimizer_steps = [INTEGER]
additional_optimizer_steps = [INTEGER1:INTEGER2]
additional_optimizer_steps = [INTEGER1 INTEGER2]
See :opt:`taper_steps <taper_steps = [INTEGER1 INTEGER2 ...]>`.
Default: ``[4 8 15]``.
Vector of additional minimization algorithms run after
``mode_compute``. If :opt:`verbose` option is set, then the additional estimation
results are saved into the ``oo_.mom`` structure prefixed with `verbose_`.
Default: no additional optimization iterations.
.. option:: raftery_lewis_diagnostics
 
.. option:: optim = (NAME, VALUE, ...)
See :opt:`raftery_lewis_diagnostics`.
Default: not set.
 
See :opt:`optim <optim = (NAME, VALUE, ...)>`.
.. option:: raftery_lewis_qrs = [DOUBLE DOUBLE DOUBLE]
 
.. option:: silent_optimizer
See :opt:`raftery_lewis_qrs <raftery_lewis_qrs = [DOUBLE DOUBLE DOUBLE]>`.
Default: ``[0.025 0.005 0.95]``.
 
See :opt:`silent_optimizer`.
Default: not set.
 
*Numerical algorithms options*
Numerical algorithms options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
.. option:: aim_solver
 
......@@ -9297,6 +10439,11 @@ adding prior information comes at the cost of a loss in efficiency of the estima
See :opt:`dr_cycle_reduction_tol <dr_cycle_reduction_tol = DOUBLE>`.
Default: ``1e-7``.
 
.. option:: dr_cycle_reduction_maxiter = INTEGER
See :opt:`dr_cycle_reduction_maxiter <dr_cycle_reduction_maxiter = INTEGER>`.
Default: ``100``.
.. option:: dr_logarithmic_reduction_tol = DOUBLE
 
See :opt:`dr_logarithmic_reduction_tol <dr_logarithmic_reduction_tol = DOUBLE>`.
......@@ -9327,19 +10474,10 @@ adding prior information comes at the cost of a loss in efficiency of the estima
See :opt:`lyapunov_doubling_tol <lyapunov_doubling_tol = DOUBLE>`.
Default: ``1e-16``.
.. option:: sylvester = OPTION
See :opt:`sylvester <sylvester = OPTION>`.
Default: ``default``, i.e. uses ``gensylv``.
.. option:: sylvester_fixed_point_tol = DOUBLE
See :opt:`sylvester_fixed_point_tol <sylvester_fixed_point_tol = DOUBLE>`.
Default: ``1e-12``.
.. option:: qz_criterium = DOUBLE
 
See :opt:`qz_criterium <qz_criterium = DOUBLE>`.
For unit roots (only possible at order=1) set e.g. to 1.000001.
Default: ``0.999999`` as it is assumed that the observables are weakly
stationary.
 
......@@ -9356,8 +10494,8 @@ adding prior information comes at the cost of a loss in efficiency of the estima
.. option:: mode_check
 
Plots univariate slices through the moments distance objective function around the
computed minimum for each estimated parameter. This is
helpful to diagnose problems with the optimizer.
computed minimum for each estimated parameter.
This is helpful to diagnose problems with the optimizer.
Default: not set.
 
.. option:: mode_check_neighbourhood_size = DOUBLE
......@@ -9376,71 +10514,76 @@ adding prior information comes at the cost of a loss in efficiency of the estima
Default: ``20``.
 
 
*Output*
Method of moments specific outputs
----------------------------------
 
``method_of_moments`` stores user options in a structure called
`options_mom_` in the global workspace. After running the estimation,
the parameters ``M_.params`` and the covariance matrices of the shocks
``M_.Sigma_e`` and of the measurement errors ``M_.H`` are set to the
parameters that minimize the quadratic moments distance objective
function. The estimation results are stored in the ``oo_.mom`` structure
with the following fields:
parameters that either minimize the quadratic moments distance objective
function or at the posterior mean in case of Bayesian MCMC estimation.
The estimation results are stored in a subfolder of :opt:`dirname <dirname = FILENAME>`
called `method_of_moments`.
Moreover, output is stored in the ``oo_.mom`` structure with the following fields:
**Common outputs**
 
.. matvar:: oo_.mom.data_moments
 
Variable set by the ``method_of_moments`` command. Stores the mean
of the selected empirical moments of data. NaN values due to leads/lags
or missing data are omitted when computing the mean. Vector of dimension
equal to the number of orthogonality conditions.
.. matvar:: oo_.mom.m_data
Variable set by the ``method_of_moments`` command. Stores the selected
empirical moments at each point in time. NaN values due to leads/lags
or missing data are replaced by the corresponding mean of the moment.
Matrix of dimension time periods times number of orthogonality conditions.
.. matvar:: oo_.mom.Sw
Variable set by the ``method_of_moments`` command. Stores the
Cholesky decomposition of the currently used weighting matrix.
Square matrix of dimensions equal to the number of orthogonality
conditions.
of the selected empirical moments/IRFs of data. NaN values due to leads/lags
or missing data are omitted when computing the mean for moments.
Vector of dimension equal to the number of orthogonality conditions or IRFs.
.. matvar:: oo_.mom.model_moments
 
Variable set by the ``method_of_moments`` command. Stores the implied
selected model moments given the current parameter guess. Model moments
selected model moments or IRFs given the current parameter guess. Model moments
are computed in closed-form from the pruned state-space system for GMM,
whereas for SMM these are based on averages of simulated data. Vector of dimension equal
to the number of orthogonality conditions.
whereas for SMM these are based on averages of simulated data.
Model IRFs are computed from the specified `simulation_method`.
Vector of dimension equal to the number of orthogonality conditions.
.. matvar:: oo_.mom.model_moments_params_derivs
 
Variable set by the ``method_of_moments`` command. Stores the analytically
computed Jacobian matrix of the derivatives of the model moments with
respect to the estimated parameters. Only for GMM with :opt:`analytic_standard_errors`.
Matrix with dimension equal to the number of orthogonality conditions
times number of estimated parameters.
.. matvar:: oo_.mom.weighting_info
Variable set by the ``method_of_moments`` command.
Stores the currently used weighting matrix (`W`), its Cholesky factor (`Sw`),
and an indicator whether the weighting matrix is the optimal one (`Woptflag`).
The inverse (`Winv`) and its log determinant (`Winv_logdet`) are also stored.
.. matvar:: oo_.mom.Q
 
Variable set by the ``method_of_moments`` command. Stores the scalar
value of the quadratic moment's distance objective function.
.. matvar:: oo_.mom.verbose
 
.. matvar:: oo_.mom.model_moments_params_derivs
Structure that contains intermediate estimation results if ``verbose`` is used.
 
Variable set by the ``method_of_moments`` command. Stores the analytically
computed Jacobian matrix of the derivatives of the model moments with
respect to the estimated parameters. Only for GMM with :opt:`analytic_standard_errors`.
Matrix with dimension equal to the number of orthogonality conditions
times number of estimated parameters.
 
**SMM and GMM specific outputs**
.. matvar:: oo_.mom.m_data
Variable set by the ``method_of_moments`` command. Stores the selected
empirical moments at each point in time. NaN values due to leads/lags
or missing data are replaced by the corresponding mean of the moment.
Matrix of dimension time periods times number of orthogonality conditions.
 
.. matvar:: oo_.mom.gmm_stage_*_mode
.. matvar:: oo_.mom.smm_stage_*_mode
.. matvar:: oo_.mom.verbose_gmm_stage_*_mode
.. matvar:: oo_.mom.verbose_smm_stage_*_mode
.. matvar:: oo_.mom.gmm_mode
.. matvar:: oo_.mom.smm_mode
Variables set by the ``method_of_moments`` command when estimating
with GMM or SMM. Stores the estimated values at stages 1, 2,....
with GMM or SMM. Stores the estimated values of the final stage.
The structures contain the following fields:
 
- ``measurement_errors_corr``: estimated correlation between two measurement errors
......@@ -9449,16 +10592,11 @@ adding prior information comes at the cost of a loss in efficiency of the estima
- ``shocks_corr``: estimated correlation between two structural shocks.
- ``shocks_std``: estimated standard deviation of structural shocks.
 
If the :opt:`verbose` option is set, additional fields prefixed with
``verbose_`` are saved for all :opt:`additional_optimizer_steps<additional_optimizer_steps = [INTEGER]>`.
.. matvar:: oo_.mom.gmm_stage_*_std_at_mode
.. matvar:: oo_.mom.smm_stage_*_std_at_mode
.. matvar:: oo_.mom.verbose_gmm_stage_*_std_at_mode
.. matvar:: oo_.mom.verbose_smm_stage_*_std_at_mode
.. matvar:: oo_.mom.gmm_std_at_mode
.. matvar:: oo_.mom.smm_std_at_mode
Variables set by the ``method_of_moments`` command when estimating
with GMM or SMM. Stores the estimated standard errors at stages 1, 2,....
with GMM or SMM. Stores the estimated standard errors of the final stage.
The structures contain the following fields:
 
- ``measurement_errors_corr``: standard error of estimated correlation between two measurement errors
......@@ -9467,10 +10605,6 @@ adding prior information comes at the cost of a loss in efficiency of the estima
- ``shocks_corr``: standard error of estimated correlation between two structural shocks.
- ``shocks_std``: standard error of estimated standard deviation of structural shocks.
If the :opt:`verbose` option is set, additional fields prefixed with
``verbose_`` are saved for all :opt:`additional_optimizer_steps<additional_optimizer_steps = [INTEGER]>`.
.. matvar:: oo_.mom.J_test
 
Variable set by the ``method_of_moments`` command. Structure where the
......@@ -9478,6 +10612,186 @@ adding prior information comes at the cost of a loss in efficiency of the estima
degress of freedom into a field called ``degrees_freedom`` and the p-value
of the test statistic into a field called ``p_val``.
 
**IRF matching specific outputs**
.. matvar:: oo_.mom.irf_model_varobs
Variable set by the ``method_of_moments`` command. Stores all the implied
model impulse response functions (not only the matched ones)
and is used for the comparison plot.
Array of dimension equal to number of observables by number of shocks
by maximum horizon.
**Bayesian specific outputs**
.. matvar:: oo_.mom.prior
Variable set by the ``method_of_moments`` command if Bayesian estimation is used.
Stores information of the joint prior. Fields are of the form::
oo_.mom.prior.OBJECT
where OBJECT is one of the following:
``mean``
Prior mean parameter vector.
``mode``
Prior mode parameter vector.
``variance``
Covariance matrix of joint prior.
``hyperparameters``
Vectors of hyperparameters of the prior distributions stored in fields
``first`` and ``second``.
.. matvar:: oo_.mom.posterior.optimization
Variable set by the ``method_of_moments`` command if mode-finding is used.
Stores the results at the mode. Fields are of the form::
oo_.mom.posterior.optimization.OBJECT
where OBJECT is one of the following:
``mode``
Parameter vector at the mode.
``Variance``
Inverse Hessian matrix at the mode or MCMC jumping
covariance matrix when used with the
:opt:`MCMC_jumping_covariance <mcmc_jumping_covariance = OPTION>` option.
``log_density``
Log likelihood (ML)/log posterior density (Bayesian) at the
mode when used with ``mode_compute>0``.
.. matvar:: oo_.mom.posterior.metropolis
Variable set by the ``method_of_moments`` command if ``mh_replic>0`` is used.
Fields are of the form::
oo_.mom.posterior.metropolis.OBJECT
where OBJECT is one of the following:
``mean``
Mean parameter vector from the MCMC.
``Variance``
Covariance matrix of the parameter draws in the MCMC.
.. matvar:: oo_.mom.prior_density
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.prior_density.PARAMETER_NAME
.. matvar:: oo_.mom.posterior_density
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_density.PARAMETER_NAME
.. matvar:: oo_.mom.posterior_hpdinf
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_hpdinf.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_hpdsup
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_hpdsup.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_mean
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.posterior_mean.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_mode
Variable set by the ``method_of_moments`` command during mode-finding.
Fields are of the form::
oo_.mom.posterior_mode.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_std_at_mode
Variable set by the ``method_of_moments`` command during mode-finding.
It is based on the inverse Hessian at ``oo_.mom.posterior_mode``.
Fields are of the form::
oo_.mom.posterior_std_at_mode.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_std
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_std.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_variance
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_variance.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_median
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_median.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.posterior_deciles
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option.
Fields are of the form::
oo_.mom.posterior_deciles.ESTIMATED_OBJECT.VARIABLE_NAME
.. matvar:: oo_.mom.MarginalDensity.LaplaceApproximation
Variable set by the ``method_of_moments`` command. Stores the marginal
data density based on the Laplace Approximation.
.. matvar:: oo_.mom.MarginalDensity.ModifiedHarmonicMean
Variable set by the ``method_of_moments`` command, if it is used with
``mh_replic > 0`` or ``load_mh_file`` option. Stores the
marginal data density based on *Geweke (1999)* Modified
Harmonic Mean estimator.
 
Model Comparison
......@@ -9751,8 +11065,8 @@ Shock Decomposition
contributions.
* Real-time conditional shock decomposition of the difference
between the real-time historical shock decomposition and the
forecast shock decomposition. If :opt:`vintage <vintage =
INTEGER>` is equal to ``0``, it computes the effect of
forecast shock decomposition. If :opt:`vintage
<vintage = INTEGER>` is equal to ``0``, it computes the effect of
shocks realizing in period :math:`T`, i.e. decomposes
:math:`Y(T\vert T)-Y(T\vert T-1)`. Put differently, it
conducts a :math:`1`-period ahead shock decomposition from
......@@ -10562,7 +11876,7 @@ the :comm:`bvar_forecast` command.
 
.. math::
 
\varepsilon_{c,t} = R_{c,c}^{-1}\bigl( y_{c,t} - T_{c,c}y_{c,t} - T_{c,u}y_{u,t} - R_{c,u}\varepsilon_{u,t}\bigr)
\varepsilon_{c,t} = R_{c,c}^{-1}\bigl( y_{c,t} - T_{c,c}y_{c,t-1} - T_{c,u}y_{u,t-1} - R_{c,u}\varepsilon_{u,t}\bigr)
 
and :math:`y_{u,t}` can be updated by evaluating the second block of equations:
 
......@@ -10570,15 +11884,16 @@ the :comm:`bvar_forecast` command.
 
y_{u,t} = T_{u,c}y_{c,t-1} + T_{u,u}y_{u,t-1} + R_{u,c}\varepsilon_{c,t} + R_{u,u}\varepsilon_{u,t}
 
By iterating over these two blocks of equations, we can build a forecast for
all the endogenous variables in the system conditional on paths for a subset of the
endogenous variables. If the distribution of the free innovations
:math:`\varepsilon_{u,t}` is provided (*i.e.* some of them have positive
variances) this exercise is replicated (the number of replication is
controlled by the option :opt:`replic` described below) by drawing different
sequences of free innovations. The result is a predictive distribution for
the uncontrolled endogenous variables, :math:`y_{u,t}`, that Dynare will use to report
confidence bands around the point conditional forecast.
By iterating over these two blocks of equations, we can build a forecast
for all the endogenous variables in the system conditional on paths for a
subset of the endogenous variables. If the distribution of the free
innovations :math:`\varepsilon_{u,t}` is provided (*i.e.* some of them have
positive variances) this exercise is replicated (the number of replication
is controlled by the option :opt:`replic <replic = INTEGER>` described
below) by drawing different sequences of free innovations. The result is a
predictive distribution for the uncontrolled endogenous variables,
:math:`y_{u,t}`, that Dynare will use to report confidence bands around the
point conditional forecast.
 
A few things need to be noted. First, the controlled
exogenous variables are set to zero for the uncontrolled periods. This implies
......@@ -10694,9 +12009,9 @@ the :comm:`bvar_forecast` command.
oo_.conditional_forecast.uncond.FORECAST_MOMENT.VARIABLE_NAME
 
 
.. matvar:: forecasts.instruments
.. matvar:: oo_.conditional_forecast.instruments
 
Variable set by the ``conditional_forecast command``. Stores
Variable set by the ``conditional_forecast`` command. Stores
the names of the exogenous instruments.
 
 
......@@ -10727,10 +12042,10 @@ the :comm:`bvar_forecast` command.
 
|br| Describes the path of constrained endogenous, before calling
``conditional_forecast``. The syntax is similar to deterministic
shocks in ``shocks``, see ``conditional_forecast`` for an example.
shocks in ``shocks``, see :comm:`conditional_forecast` for an
example and :ref:`shocks-exo` for the detailed syntax reference.
 
The syntax of the block is the same as for the deterministic
shocks in the ``shocks`` blocks (see :ref:`shocks-exo`). Note that
Note that
you need to specify the full path for all constrained endogenous
variables between the first and last specified period. If an
intermediate period is not specified, a value of 0 is
......@@ -10826,12 +12141,12 @@ The forecast scenario can contain some simple shocks on the exogenous
variables. This shocks are described using the function
``basic_plan``:
 
.. matcomm:: HANDLE = basic_plan (HANDLE, `VAR_NAME', `SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE | [DOUBLE | EXPR [DOUBLE | EXPR] ] );
.. matcomm:: HANDLE = basic_plan (HANDLE, 'VAR_NAME', 'SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE);
 
Adds to the forecast scenario a shock on the exogenous variable
indicated between quotes in the second argument. The shock type
has to be specified in the third argument between quotes:
surprise in case of an unexpected shock or perfect_foresight
``'surprise'`` in case of an unexpected shock or ``'perfect_foresight'``
for a perfectly anticipated shock. The fourth argument indicates
the period of the shock using a dates class (see :ref:`dates class
members <dates-members>`). The last argument is the shock path
......@@ -10844,7 +12159,7 @@ compatible with the constrained path are in this case computed. In
other words, a conditional forecast is performed. This kind of shock
is described with the function ``flip_plan``:
 
.. matcomm:: HANDLE = flip_plan (HANDLE, `VAR_NAME', `VAR_NAME', `SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE | [DOUBLE | EXPR [DOUBLE | EXPR] ] );
.. matcomm:: HANDLE = flip_plan (HANDLE, 'VAR_NAME', 'VAR_NAME', 'SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE);
 
Adds to the forecast scenario a constrained path on the endogenous
variable specified between quotes in the second argument. The
......@@ -10853,8 +12168,8 @@ is described with the function ``flip_plan``:
values compatible with the constrained path on the endogenous
variable will be computed. The nature of the expectation on the
constrained path has to be specified in the fourth argument
between quotes: surprise in case of an unexpected path or
perfect_foresight for a perfectly anticipated path. The fifth
between quotes: ``'surprise'`` in case of an unexpected path or
``'perfect_foresight'`` for a perfectly anticipated path. The fifth
argument indicates the period where the path of the endogenous
variable is constrained using a dates class (see :ref:`dates class
members <dates-members>`). The last argument contains the
......@@ -10864,18 +12179,17 @@ is described with the function ``flip_plan``:
Once the forecast scenario if fully described, the forecast is
computed with the command ``det_cond_forecast``:
 
.. matcomm:: DSERIES = det_cond_forecast (HANDLE[, DSERIES [, DATES]]);
.. matcomm:: DSERIES = det_cond_forecast (HANDLE, DSERIES, DATES);
 
Computes the forecast or the conditional forecast using an
extended path method for the given forecast scenario (first
argument). The past values of the endogenous and exogenous
variables provided with a dseries class (see :ref:`dseries class
members <dseries-members>`) can be indicated in the second
argument. By default, the past values of the variables are equal
to their steady-state values. The initial date of the forecast can
be provided in the third argument. By default, the forecast will
start at the first date indicated in the ``init_plan
command``. This function returns a dset containing the historical
argument). The first argument is a handle to the forecast scenario
as created by `init_plan` and associated commands.
The second argument contains the past values of the endogenous and the path
of exogenous variables, in a dseries object (see :ref:`dseries class
members <dseries-members>`). The third argument is the date range of the
forecast, typically the range used when creating the scenario handle.
This function returns a dataset containing the historical
and forecast values for the endogenous and exogenous variables.
 
 
......@@ -10891,11 +12205,12 @@ computed with the command ``det_cond_forecast``:
...
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 ]);
frng = 2013Q4:2029Q4;
fplan = init_plan(frng);
fplan = flip_plan(fplan, 'y', 'u', 'surprise', frng(1:4), [1 1.1 1.2 1.1]);
fplan = flip_plan(fplan, 'r', 'e', 'perfect_foresight', frng(1:4), [2 1.9 1.9 1.9]);
 
dset_forecast = det_cond_forecast(fplan, smoothed);
dset_forecast = det_cond_forecast(fplan, smoothed, frng);
 
plot(dset_forecast.{'y','u'});
plot(dset_forecast.{'r','e'});
......@@ -11297,7 +12612,7 @@ Optimal policy under discretion
You must ensure that your objective is quadratic. Regarding the model, it must
either be linear or solved at first order with an analytical steady state provided.
In the first case, you should set the ``linear`` option of the
``model`` block.
:bck:`model` block or :comm:`model_options` command.
 
It is possible to use the :comm:`estimation` command after the
``discretionary_policy`` command, in order to estimate the model with
......@@ -11607,8 +12922,8 @@ estimation environment is set up.
Performing sensitivity analysis
-------------------------------
 
.. command:: dynare_sensitivity ;
dynare_sensitivity(OPTIONS...);
.. command:: sensitivity ;
sensitivity(OPTIONS...);
 
|br| This command triggers sensitivity analysis on a DSGE model.
 
......@@ -11644,8 +12959,9 @@ Performing sensitivity analysis
If equal to ``0``, ANOVA mapping (Type I error) If equal to
``1``, Screening analysis (Type II error). If equal to ``2``,
Analytic derivatives (similar to Type II error, only valid
when identification=1). Default: ``1`` when
``identification=1``, ``0`` otherwise.
when identification=1). The ANOVA mapping requires the SS-ANOVA-R MATLAB
Toolbox available at https://joint-research-centre.ec.europa.eu/system/files/2025-01/ss_anova_recurs.zip
Default: ``1`` when ``identification=1``, ``0`` otherwise.
 
.. option:: morris_nliv = INTEGER
 
......@@ -11892,6 +13208,12 @@ Performing sensitivity analysis
 
See :opt:`diffuse_filter`.
 
.. command:: dynare_sensitivity ;
dynare_sensitivity(OPTIONS...);
|br| This is a deprecated alias for the ``sensitivity`` command.
.. _irf-momcal:
 
IRF/Moment calibration
......@@ -12654,8 +13976,8 @@ below.
vector of size equal ``number_of_regimes``, it specifies the
average duration of the associated regimes
(``1:number_of_regimes``) in this chain. An absorbing state
can be specified through the :opt:`restrictions <restrictions
= [[ROW VECTOR OF 3 DOUBLES],[ROW VECTOR OF 3 DOUBLES],...]>`
can be specified through the :opt:`restrictions
<restrictions = [[ROW VECTOR OF 3 DOUBLES],[ROW VECTOR OF 3 DOUBLES],...]>`
option.
 
.. option:: restrictions = [[ROW VECTOR OF 3 DOUBLES],[ROW VECTOR OF 3 DOUBLES],...]
......@@ -13345,8 +14667,8 @@ below.
 
.. option:: error_band_percentiles = [DOUBLE1 ...]
 
See :opt:`error_band_percentiles <error_band_percentiles =
[DOUBLE1 ...]>`.
See :opt:`error_band_percentiles
<error_band_percentiles = [DOUBLE1 ...]>`.
 
.. option:: shock_draws = INTEGER
 
......@@ -13423,8 +14745,8 @@ below.
 
.. option:: error_band_percentiles = [DOUBLE1 ...]
 
See :opt:`error_band_percentiles <error_band_percentiles =
[DOUBLE1 ...]>`.
See :opt:`error_band_percentiles
<error_band_percentiles = [DOUBLE1 ...]>`.
 
.. option:: shock_draws = INTEGER
 
......@@ -13509,7 +14831,7 @@ assumed that each equation is written as ``VARIABLE = EXPRESSION`` or
``T(VARIABLE) = EXPRESSION`` where ``T(VARIABLE)`` stands for a transformation
of an endogenous variable (``log`` or ``diff``). This representation, where each
equation determines the endogenous variable on the LHS, can be exploited when
simulating the model (see algorithms 12 and 14 in :ref:`solve_algo <solvalg>`)
simulating the model (see algorithms ``12`` and ``14`` in :ref:`solve_algo <solvalg>`)
and is mandatory to define auxiliary models used for computing expectations (see
below).
 
......@@ -13546,7 +14868,7 @@ a trend target to which the endogenous variables may be attracted in the long-ru
:math:`n\times 1` vector of parameters, :math:`A_i` (:math:`i=0,\ldots,p`)
are :math:`n\times n` matrices of parameters, and :math:`A_0` is non
singular square matrix. Vector :math:`\mathbf{c}` and matrices :math:`A_i`
(:math:`i=0,\ldots,p`) are set by Dynare by parsing the equations in the
(:math:`i=0,\ldots,p`) are set by parsing the equations in the
``model`` block. Then, Dynare builds a VAR(1)-companion form model for
:math:`\mathcal{Y}_t = (1, Y_t, \ldots, Y_{t-p+1})'` as:
 
......@@ -13757,7 +15079,7 @@ up to time :math:`t-\tau`, :math:`\mathcal{Y}_{\underline{t-\tau}}`) is:
 
In a semi-structural model, variables appearing in :math:`t+h` (*e.g.*
the expected output gap in a dynamic IS curve or expected inflation in a
(New Keynesian) Phillips curve) will be replaced by the expectation implied by an auxiliary VAR
New Keynesian Phillips curve) will be replaced by the expectation implied by an auxiliary VAR
model. Another use case is for the computation of permanent
incomes. Typically, consumption will depend on something like:
 
......@@ -13765,13 +15087,13 @@ incomes. Typically, consumption will depend on something like:
 
\sum_{h=0}^{\infty} \beta^h y_{t+h|t-\tau}
 
Assuming that $0<\beta<1$ and knowing the limit of geometric series, the conditional expectation of this variable can be evaluated based on the same auxiliary model:
Assuming that :math:`0<\beta<1` and knowing the limit of geometric series, the conditional expectation of this variable can be evaluated based on the same auxiliary model:
 
.. math ::
 
\mathbb E \left[\sum_{h=0}^{\infty} \beta^h y_{t+h}\Biggl| \mathcal{Y}_{\underline{t-\tau}}\right] = \alpha \mathcal{C}^\tau(I-\beta\mathcal{C})^{-1}\mathcal{Y}_{t-\tau}
 
More generally, it is possible to consider finite discounted sums.
Finite discounted sums can also be considered.
 
.. command:: var_expectation_model (OPTIONS...);
 
......@@ -13781,9 +15103,9 @@ More generally, it is possible to consider finite discounted sums.
 
.. math ::
 
\sum_{h=a}^b \mathbb \beta^{h-\tau}\mathbb E[y_{t+h}|\mathcal{Y}_{\underline{t-\tau}}]
\sum_{h=a}^b \beta^{h-\tau}\mathbb E[y_{t+h}|\mathcal{Y}_{\underline{t-\tau}}]
 
where :math:`(a,b)\in\mathbb N^2` with :math:`a<b`, :math:`\beta\in(0,1]` is a discount factor,
where :math:`(a,b)\in\mathbb N^2` with :math:`a<b` and :math:`a<\infty`, :math:`\beta\in(0,1]` is a discount factor,
and :math:`\tau` is a finite positive integer.
 
*Options*
......@@ -13806,14 +15128,19 @@ More generally, it is possible to consider finite discounted sums.
 
.. option:: horizon = INTEGER | [INTEGER:INTEGER]
 
The upper limit :math:`b` of the horizon :math:`h` (in which case :math:`a=0`), or range of periods
:math:`a:b` over which the discounted sum is computed (the upper bound can be ``Inf``).
If the value of ``horizon`` is a finite integer scalar, the following expectation is computed:
.. math ::
\beta^{h-\tau}\mathbb E[y_{t+h}|\mathcal{Y}_{\underline{t-\tau}}]
otherwise the value is a range of periods :math:`a:b` over which the expected discounted sum is computed (the upper bound can be ``Inf``).
 
.. option:: time_shift = INTEGER
 
Shift of the information set (:math:`\tau`), default value is 0.
 
.. operator:: var_expectation (NAME_OF_VAR_EXPECTATION_MODEL);
 
|br| This operator is used instead of a leaded variable, e.g. ``X(1)``, in the
......@@ -13956,7 +15283,7 @@ simply add the exogenous variables to the PAC equation (without the weight
``trend_component_model``, to compute the VAR based expectations for the
expected changes in the target, *i.e.* to evaluate
:math:`\sum_{i=0}^{\infty} d_i \Delta y^{\star}_{t+i}`. The infinite sum
will then be replaced by a linear combination of the variables involved in
will then be replaced by a linear combination, defined by a vector :math:`h`, of the variables involved in
the companion representation of the auxiliary model. The weights defining
the linear combination are nonlinear functions of the
:math:`(a_i)_{i=0}^{m-1}` coefficients in the PAC equation. This option is
......@@ -13976,6 +15303,21 @@ simply add the exogenous variables to the PAC equation (without the weight
or expression is given) is consistent with the asymptotic growth rate of the
endogenous variable.
 
.. option:: kind = dd | dl
Instructs Dynare how to compute the vector :math:`h`, the weights
defining the linear combination of the companion VAR
variables. The default value ``dd`` must be used if the target
appears in first difference in the auxiliary model, see equation
(A.79) in *Brayton et alii (2000)*, while value ``dl`` must be
used if the target shows up in level in the auxiliary model,
equation (A.74) in *Brayton et alii (2000)*.
.. option:: auxname = STRING
Name the auxiliary variable, created by the preprocessor, that
will define the expectation term in the PAC equation.
 
.. operator:: pac_expectation (NAME_OF_PAC_MODEL);
 
......@@ -13986,7 +15328,89 @@ simply add the exogenous variables to the PAC equation (without the weight
the variables involved in the companion representation of the auxiliary model
or by a recursive forward equation.
 
|br|
The PAC equation target can be composite and defined as a weighted sum
of stationary and non stationary components. Such a target requires an
additional equation in the model block, with the target variable on
the left hand-side and the components in the right hand-side. Each
component must be an endogenous variable in the auxiliary model. The
characteristics of each component must be described in the
``pac_target_info`` block, see below, and the
``pac_target_nonstationary`` operator must be used in the error
correction term of the PAC equation to link the target to the provided
description. Note that composite targets make only sense if the
auxiliary model is not a trend component model (where all the
variables are non stationary).
.. block:: pac_target_info (NAME_OF_PAC_MODEL);
|br| This block enables the user to provide the properties of each
component of a target in PAC models with a composite target. The
``NAME_OF_PAC_MODEL`` argument refers to a PAC model (must match
the value of option ``model_name`` in the declaration of a PAC
model).
On the first line of the block, the name of the composite target
variable must be provided using the following syntax::
target VARIABLE_NAME ;
where ``VARIABLE_NAME`` is a declared endogenous variable, its
associated equation is not part of the auxiliary model but all the
components (the variables on the right hand-side) must be defined
in the auxiliary model. Next, the following line declares the name
of the auxilary variable that will appear in the error correction
term, this variable contains only the non stationary components of
the target::
auxname_target_nonstationary NAME ;
The block should contain the following group of lines for each
stationary component::
component STATIONARY_VARIABLE_NAME ;
kind ll ;
auxname AUX_VAR_NAME ;
where ``STATIONARY_VARIABLE_NAME`` is the name of a stationary
variable appearing in the right hand-side of the equation defining
the target ``VARIABLE_NAME``. The second line instructs Dynare that
the component appears in levels in the auxiliary model and in the
PAC expectations. The third line specifies the name of the
auxiliary variable created by Dynare for the component of the PAC
expectation related to ``STATIONARY_VARIABLE_NAME``.
The block should contain the following group of lines for each
nonstationary component::
component NONSTATIONARY_VARIABLE_NAME ;
kind dd | dl ;
auxname AUX_VAR_NAME ;
growth PARAMETER_NAME | VARIABLE_NAME | EXPRESSION | DOUBLE ;
where ``NONSTATIONARY_VARIABLE_NAME`` is the name of a
nonstationary variable appearing in the right hand-side of the
equation defining the target ``VARIABLE_NAME``. The second line
instructs Dynare on how to calculate the weights that define the linear
combination of the companion VAR variables. Use value ``dd`` if the
target appears in first difference in the auxiliary model, or
``dl`` if the target shows up in level in the auxiliary model. The
third line sets the name of the auxiliary variable created by
Dynare for the component of the PAC expectation related to
``NONSTATIONARY_VARIABLE_NAME``. The fourth line is mandatory if a
growth neutrality correction is required. The provided value for
this option must be consistent with the asymptotic growth rate of
the PAC endogenous variable.
.. operator:: pac_target_nonstationary (NAME_OF_PAC_MODEL);
|br| This operator is only required in presence of a composite
target in the PAC equation. The operator, used in the error
correction term of the PAC equation, selects the non stationary
components of the target.
 
.. matcomm:: pac.initialize(NAME_OF_PAC_MODEL);
.. matcomm:: pac.update(NAME_OF_PAC_MODEL);
......@@ -13999,18 +15423,18 @@ simply add the exogenous variables to the PAC equation (without the weight
the infinite sum in the MCE case).
 
 
*Example*
*Example (trend component auxiliary model)*
 
::
 
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
 
pac_model(auxiliary_model_name=toto, discount=beta, growth=diff(x1(-1)), model_name=pacman);
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
 
model;
 
[name='eq:y']
y = rho_1*y(-1) + rho_2*y(-2) + ey;
y = (1-rho_1-rho_2)*diff(x2(-1)) + rho_1*y(-1) + rho_2*y(-2) + ey;
 
[name='eq:x1']
diff(x1) = a_x1_0*(x1(-1)-x1bar(-1)) + a_x1_1*diff(x1(-1)) + a_x1_2*diff(x1(-2)) + a_x1_x2_1*diff(x2(-1)) + a_x1_x2_2*diff(x2(-2)) + ex1;
......@@ -14034,6 +15458,51 @@ simply add the exogenous variables to the PAC equation (without the weight
pac.update.expectation('pacman');
 
 
*Example (VAR auxiliary model and composite target)*
::
var_model(model_name=toto, eqtags=['eq:x', 'eq:y']);
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
pac_target_info(pacman);
target v;
auxname_target_nonstationary vns;
component y;
auxname pv_y_;
kind ll;
component x;
growth diff(x(-1));
auxname pv_dx_;
kind dd;
end;
model;
[name='eq:y']
y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ;
[name='eq:x']
diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ;
[name='eq:v']
v = x + d_y*y ; // Composite PAC target, no residuals here only variables defined in the auxiliary model.
[name='zpac']
diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
end;
pac.initialize('pacman');
pac.update.expectation('pacman');
Estimation of a PAC equation
----------------------------
 
......@@ -14205,13 +15674,13 @@ Macro expressions
Macro-expressions can be used in two places:
 
* Inside macro directives, directly;
* In the body of the ``.mod`` file, between an at-sign and curly
* In the body of the ``.mod`` file, between an @-sign and curly
braces (like ``@{expr}``): the macro processor will substitute
the expression with its value
 
It is possible to construct macro-expressions that can be assigned to
macro-variables or used within a macro-directive. The expressions are
constructed using literals of the basic types (boolean, real, string, tuple,
constructed using literals (*i.e.*\ fixed values) of the basic types (boolean, real, string, tuple,
array), comprehensions, macro-variables, macro-functions, and standard
operators.
 
......@@ -14223,16 +15692,16 @@ operators.
 
The following operators can be used on booleans:
 
* Comparison operators: ``==, !=``
* Logical operators: ``&&, ||, !``
* Comparison operators: ``==``, ``!=``
* Logical operators: ``&&``, ``||``, ``!``
 
.. rubric:: Real
 
The following operators can be used on reals:
 
* Arithmetic operators: ``+, -, *, /, ^``
* Comparison operators: ``<, >, <=, >=, ==, !=``
* Logical operators: ``&&, ||, !``
* Arithmetic operators: ``+``, ``-``, ``*``, ``/``, ``^``
* Comparison operators: ``<``, ``>``, ``<=``, ``>=``, ``==``, ``!=``
* Logical operators: ``&&``, ``||``, ``!``
* Ranges with an increment of ``1``: ``REAL1:REAL2`` (for example, ``1:4``
is equivalent to real array ``[1, 2, 3, 4]``).
 
......@@ -14241,9 +15710,11 @@ The following operators can be used on reals:
will create an array containing an array (i.e. ``[ [1, 2, 3, 4] ]``).
* Ranges with user-defined increment: ``REAL1:REAL2:REAL3`` (for example,
``6:-2.1:-1`` is equivalent to real array ``[6, 3.9, 1.8, -0.3]``).
* Functions: ``max, min, mod, exp, log, log10, sin, cos, tan, asin, acos,
atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma,
round, normpdf, normcdf``. NB ``ln`` can be used instead of ``log``
* Functions: ``max``, ``min``, ``mod``, ``exp``, ``log``, ``log10``,
``sin``, ``cos``, ``tan``, ``asin``, ``acos``, ``atan``, ``sqrt``,
``cbrt``, ``sign``, ``floor``, ``ceil``, ``trunc``, ``erf``, ``erfc``,
``gamma``, ``lgamma``, ``round``, ``normpdf``, ``normcdf``. NB ``ln`` can
be used instead of ``log``
 
.. rubric:: String
 
......@@ -14251,7 +15722,7 @@ String literals have to be enclosed by **double** quotes (like ``"name"``).
 
The following operators can be used on strings:
 
* Comparison operators: ``<, >, <=, >=, ==, !=``
* Comparison operators: ``<``, ``>``, ``<=``, ``>=``, ``==``, ``!=``
* Concatenation of two strings: ``+``
* Extraction of substrings: if ``s`` is a string, then ``s[3]`` is
a string containing only the third character of ``s``, and
......@@ -14260,13 +15731,13 @@ The following operators can be used on strings:
 
.. rubric:: Tuple
 
Tuples are enclosed by parenthesis and elements separated by commas (like
Tuples are enclosed by parentheses and elements are separated by commas (like
``(a,b,c)`` or ``(1,2,3)``).
 
The following operators can be used on tuples:
 
* Comparison operators: ``==, !=``
* Functions: ``empty, length``
* Comparison operators: ``==``, ``!=``
* Functions: ``empty``, ``length``
 
 
.. rubric:: Array
......@@ -14276,7 +15747,7 @@ by commas (like ``[1,[2,3],4]`` or ``["US", "FR"]``).
 
The following operators can be used on arrays:
 
* Comparison operators: ``==, !=``
* Comparison operators: ``==``, ``!=``
* Dereferencing: if ``v`` is an array, then ``v[2]`` is its 2nd element
* Concatenation of two arrays: ``+``
* Set union of two arrays: ``|``
......@@ -14288,7 +15759,7 @@ The following operators can be used on arrays:
* Extraction of sub-arrays: e.g. ``v[4:6]``
* Testing membership of an array: ``in`` operator (for example:
``"b"`` in ``["a", "b", "c"]`` returns ``1``)
* Functions: ``empty, sum, length``
* Functions: ``empty``, ``sum``, ``length``
 
.. rubric:: Comprehension
 
......@@ -14354,7 +15825,8 @@ every selected element of an array.
.. rubric:: Function
 
Functions can be defined in the macro processor using the ``@#define``
directive (see below). A function is evaluated at the time it is invoked, not
directive (see below). A function is evaluated at the time it is invoked during
the macroprocessing stage, not
at define time. Functions can be included in expressions and the operators that
can be combined with them depend on their return type.
 
......@@ -14514,10 +15986,10 @@ Macro directives
|br| Conditional inclusion of some part of the ``.mod`` file. The lines
between ``@#if``, ``@#ifdef``, or ``@#ifndef`` and the next ``@#elseif``,
``@#else`` or ``@#endif`` is executed only if the condition evaluates to
``true``. Following the ``@#if`` body, you can zero or more ``@#elseif``
branches. An ``@#elseif`` condition is only evaluated if the preceding
``@#if`` or ``@#elseif`` condition evaluated to ``false``. The ``@#else``
branch is optional and is only evaluated if all ``@#if`` and ``@#elseif``
``true``. Following the ``@#if`` body, zero or more ``@#elseif``
branches are allowed. An ``@#elseif`` condition is only evaluated if the preceding
``@#if`` or ``@#elseif`` condition(s) evaluated to ``false``. The ``@#else``
branch is optional and only evaluated if all ``@#if`` and ``@#elseif``
statements evaluate to false.
 
Note that when using ``@#ifdef``, the condition will evaluate to ``true``
......@@ -14536,7 +16008,7 @@ Macro directives
imprecision of reals, extra care must be taken when testing them in the
MACRO_EXPRESSION. For example, ``exp(log(5)) == 5`` will evaluate to
``false``. Hence, when comparing real values, you should generally use a
zero tolerance around the value desired, e.g. ``exp(log(5)) > 5-1e-14 &&
non-zero tolerance around the value desired, e.g. ``exp(log(5)) > 5-1e-14 &&
exp(log(5)) < 5+1e-14``
 
*Example*
......@@ -14567,10 +16039,7 @@ Macro directives
 
Choose between two alternative monetary policy rules using a
macro-variable. The only difference between this example and the
previous one is the use of ``@#ifdef`` instead of ``@#if``. Even though
``linear_mon_pol`` contains the value ``false`` because ``@#ifdef`` only
checks that the variable has been defined, the linear monetary policy
is output::
previous one is the use of ``@#ifdef`` instead of ``@#if``::
 
@#define linear_mon_pol = false // 0 would be treated the same
...
......@@ -14583,7 +16052,9 @@ Macro directives
...
end;
 
This would result in::
Although ``linear_mon_pol`` contains the value ``false`` because ``@#ifdef`` only
checks that the variable has been defined, the linear monetary policy
is output::This would result in::
 
...
model;
......@@ -14600,8 +16071,8 @@ Macro directives
@#endfor
 
|br| Loop construction for replicating portions of the ``.mod``
file. Note that this construct can enclose variable/parameters
declaration, computational tasks, but not a model declaration.
file. Note that this construct can enclose variable/parameter
declarations, computational tasks, but not a model declaration.
 
*Example*
 
......@@ -14722,11 +16193,11 @@ Example setup:
Includes ``modeldesc.mod``, declares priors on parameters, and runs
Bayesian estimation.
 
Dynare can be called on ``simul.mod`` and ``estim.mod`` but it makes
Dynare can be called on ``simul.mod`` and ``estim.mod``, but it makes
no sense to run it on ``modeldesc.mod``.
 
The main advantage is that you don't have to copy/paste the whole model (at the
beginning) or changes to the model (during development).
The main advantage is that you don't have to copy/paste the whole model (during initial development)
or changes to the model (during development).
 
 
Indexed sums of products
......@@ -14768,7 +16239,7 @@ After macro processing, this is equivalent to::
Multi-country models
^^^^^^^^^^^^^^^^^^^^
 
Here is a skeleton example for a multi-country model::
Here is a bare bones example for a multi-country model::
 
@#define countries = [ "US", "EA", "AS", "JP", "RC" ]
@#define nth_co = "US"
......@@ -14795,33 +16266,33 @@ Here is a skeleton example for a multi-country model::
Endogeneizing parameters
^^^^^^^^^^^^^^^^^^^^^^^^
 
When calibrating the model, it may be useful to consider a parameter as an
endogenous variable (and vice-versa).
When calibrating the model, it may be useful to pin down parameters by targeting endogenous objects.
 
For example, suppose production is defined by a CES function:
 
.. math::
 
y = \left(\alpha^{1/\xi} \ell^{1-1/\xi}+(1-\alpha)^{1/\xi}k^{1-1/\xi}\right)^{\xi/(\xi-1)}
y_t = \left(\alpha^{1/\xi} \ell_t^{1-1/\xi}+(1-\alpha)^{1/\xi}k_t^{1-1/\xi}\right)^{\xi/(\xi-1)}
 
and the labor share in GDP is defined as:
 
.. math::
 
\textrm{lab\_rat} = (w \ell)/(p y)
\textrm{lab\_rat}_t = (w_t \ell_t)/(p_t y_t)
 
In the model, :math:`\alpha` is a (share) parameter and ``lab_rat`` is an
In the model, :math:`\alpha` is a (share) parameter and :math:`lab\_rat_t` is an
endogenous variable.
 
It is clear that calibrating :math:`\alpha` is not straightforward;
on the contrary, we have real world data for ``lab_rat`` and it
is clear that these two variables are economically linked.
It is clear that setting a value for :math:`\alpha` is not straightforward. But
we have real world data for :math:`lab\_rat_t` and it
is clear that these two objects are economically linked.
 
The solution is to use a method called *variable flipping*, which
consists in changing the way of computing the steady state. During
this computation, :math:`\alpha` will be made an endogenous variable
and ``lab_rat`` will be made a parameter. An economically relevant
value will be calibrated for ``lab_rat``, and the solution algorithm
and the steady state value :math:`lab\_rat` of the dynamic variable :math:`lab\_rat_t`
will be made a parameter. An economically sensible
value will be calibrated for :math:`lab\_rat`, and the solution algorithm
will deduce the implied value for :math:`\alpha`.
 
An implementation could consist of the following files:
......@@ -14840,7 +16311,7 @@ An implementation could consist of the following files:
var lab_rat;
@#endif
 
``steady.mod``
``steadystate.mod``
 
This file computes the steady state. It begins with::
 
......@@ -14850,17 +16321,17 @@ An implementation could consist of the following files:
Then it initializes parameters (including ``lab_rat``, excluding
:math:`\alpha`), computes the steady state (using guess values for
endogenous, including :math:`\alpha`), then saves values of
parameters and endogenous at steady state in a file, using the
parameters and variables at steady state in a file, using the
``save_params_and_steady_state`` command.
 
``simul.mod``
``simulate.mod``
 
This file computes the simulation. It begins with::
 
@#define steady = 0
@#include "modeqs.mod"
 
Then it loads values of parameters and endogenous at steady state
Then it loads values of parameters and variables at steady state
from file, using the ``load_params_and_steady_state`` command, and
computes the simulations.
 
......@@ -14878,12 +16349,17 @@ to run simulations for three values: :math:`\rho = 0.8, 0.9,
 
rhos = [ 0.8, 0.9, 1];
for i = 1:length(rhos)
rho = rhos(i);
set_param_value('rho',rhos(i));
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
end
 
Here the loop is not unrolled, MATLAB/Octave manages the
iterations. This is interesting when there are a lot of iterations.
It is strongly advised to always check whether the error flag ``info(1)==0``
to prevent erroneously relying on stale results from previous iterations.
 
*With a macro processor loop (case 1)*
 
......@@ -14891,8 +16367,11 @@ to run simulations for three values: :math:`\rho = 0.8, 0.9,
 
rhos = [ 0.8, 0.9, 1];
@#for i in 1:3
rho = rhos(@{i});
set_param_value('rho',rhos(@{i}));
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor
 
This is very similar to the previous example, except that the loop
......@@ -14906,6 +16385,9 @@ to run simulations for three values: :math:`\rho = 0.8, 0.9,
@#for rho_val in [ 0.8, 0.9, 1]
rho = @{rho_val};
stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor
 
The advantage of this method is that it uses a shorter syntax, since the list
......@@ -14946,10 +16428,10 @@ Misc commands
=============
 
.. command:: set_dynare_seed (INTEGER)
set_dynare_seed (`default')
set_dynare_seed (`clock')
set_dynare_seed (`reset')
set_dynare_seed (`ALGORITHM', INTEGER)
set_dynare_seed ('default')
set_dynare_seed ('clock')
set_dynare_seed ('reset')
set_dynare_seed ('ALGORITHM', INTEGER)
 
|br| Sets the seed used for random number generation. It is
possible to set a given integer value, to use a default value, or
......@@ -15101,7 +16583,7 @@ Misc commands
``pdflatex`` and automatically tries to load all required
packages. Requires the following LaTeX packages:
``breqn``, ``psfrag``, ``graphicx``, ``epstopdf``, ``longtable``,
``booktabs``, ``caption``, ``float,`` ``amsmath``, ``amsfonts``,
``booktabs``, ``caption``, ``float,`` ``amsmath``, ``amsfonts``, ``amssymb``,
and ``morefloats``.
 
 
......
......@@ -22,6 +22,8 @@ Dates
=====
.. highlight:: matlab
.. _dates in a mod file:
Dates in a mod file
-------------------
......@@ -29,10 +31,15 @@ Dynare understands dates in a mod file. Users can declare annual, bi-annual,
quarterly, or monthly dates using the following syntax::
1990Y
1990A
1990S2
1990H2
1990Q4
1990M11
Note that there are two syntaxes for annual dates (`1990A` is equivalent to
`1990Y`), and for bi-annual dates (`1990H2` is equivalent to `1990S2`).
Behind the scene, Dynare’s preprocessor translates these expressions
into instantiations of the MATLAB/Octave’s class ``dates`` described
below. Basic operations can be performed on dates:
......@@ -52,7 +59,7 @@ below. Basic operations can be performed on dates:
Has two functions: difference and subtraction. If the second
argument is a date, calculates the difference between the first
date and the secmond date (e.g. ``1951Q2-1950Q1`` is equal to
date and the second date (e.g. ``1951Q2-1950Q1`` is equal to
``5``). If the second argument is an integer ``X``, subtracts
``X`` periods from the date (e.g. ``1951Q2-2`` is equal to
``1950Q4``).
......@@ -67,7 +74,7 @@ below. Basic operations can be performed on dates:
Can be used to create a range of dates. For instance, ``r =
1950Q1:1951Q1`` creates a ``dates`` object with five elements:
``1950Q1, 1950Q2, 1950Q3, 1950Q4`` and ``1951Q1``. By default the
``1950Q1``, ``1950Q2``, ``1950Q3``, ``1950Q4`` and ``1951Q1``. By default the
increment between each element is one period. This default can be
changed using, for instance, the following instruction:
``1950Q1:2:1951Q1`` which will instantiate a ``dates`` object with
......@@ -261,6 +268,39 @@ The dates class
do4 = dates('Q',1950, 1);
do5 = dates('D',1973, 1, 25);
|br|
A ``dates`` object with multiple elements can be considered a one-dimensional array of dates. Standard array operations can be applied to a ``dates`` object:
- square brackets can be used to concatenate dates objects::
>> A = dates('1938Q4');
>> B = dates('1945Q3');
>> C = [A, B];
- semicolons can be used to create ranges of dates::
>> A = dates('2009Q2');
>> B = A:A+2;
>> B
B = <dates: 2009Q2, 2009Q3, 2009Q4>
- objects can be indexed by an integer or a vector of integer::
>> B(1)
ans = <dates: 2009Q2>
>> B(end)
ans = <dates: 2009Q4>
>> B(1:2)
ans = <dates: 2009Q2, 2009Q3>
|br|
A list of the available methods, by alphabetical order, is given
below. Note that by default the methods do not allow in place
......@@ -299,8 +339,10 @@ The dates class
particularly useful if the methods are called in loops, since this
saves the object instantiation overhead.
|br|
.. datesmethod:: C = append (A, B)
C = append_ (A, B)
append_ (B)
|br| Appends ``dates`` object ``B``, or a string that can be
interpreted as a date, to the ``dates`` object ``A``. If ``B``
......@@ -784,8 +826,8 @@ The dates class
.. datesmethod:: C = pop (A)
C = pop (A, B)
C = pop_ (A)
C = pop_ (A, B)
pop_ ()
pop_ (B)
|br| Pop method for ``dates`` class. If only one input is
provided, the method removes the last element of a ``dates``
......@@ -808,7 +850,7 @@ The dates class
.. datesmethod:: C = remove (A, B)
C = remove_ (A, B)
remove_ (B)
|br| Remove method for ``dates`` class. Both inputs have to be ``dates`` objects, removes dates in ``B`` from ``A``.
......@@ -848,7 +890,7 @@ The dates class
.. datesmethod:: B = sort (A)
B = sort_ (A)
sort_ ()
|br| Sort method for ``dates`` objects. Returns a ``dates`` object
with elements sorted by increasing order.
......@@ -934,7 +976,7 @@ The dates class
.. datesmethod:: B = unique (A)
B = unique_ (A)
unique_ ()
|br| Overloads the MATLAB/Octave ``unique`` function. Returns
a ``dates`` object with repetitions removed (only the last
......@@ -1117,7 +1159,7 @@ The dseries class
.. dseriesmethod:: A = abs (B)
abs_ (B)
abs_ ()
|br| Overloads the ``abs()`` function for ``dseries``
objects. Returns the absolute value of the variables in
......@@ -1147,9 +1189,32 @@ The dseries class
1973Q2 | 0.51222 | 0.4948
1973Q3 | 0.99791 | 0.22677
*Example (in-place modification version)*
::
>> ts0 = dseries(randn(3,2),'1973Q1',{'A1'; 'A2'},{'A_1'; 'A_2'});
>> ts0
ts0 is a dseries object:
| A1 | A2
1973Q1 | -0.67284 | 1.4367
1973Q2 | -0.51222 | -0.4948
1973Q3 | 0.99791 | 0.22677
>> ts0.abs_();
>> ts0
ts0 is a dseries object:
| abs(A1) | abs(A2)
1973Q1 | 0.67284 | 1.4367
1973Q2 | 0.51222 | 0.4948
1973Q3 | 0.99791 | 0.22677
.. dseriesmethod:: [A, B] = align (A, B)
align_ (A, B)
align_ (B)
If ``dseries`` objects ``A`` and ``B`` are defined on
different time ranges, this function extends ``A`` and/or
......@@ -1204,8 +1269,60 @@ The dseries class
2001Q2 | 0.12801
*Example (in-place modification version)*
::
>> ts0 = dseries(rand(5,1),dates('2000Q1')); % 2000Q1 -> 2001Q1
>> ts1 = dseries(rand(3,1),dates('2000Q4')); % 2000Q4 -> 2001Q2
>> ts0
ts0 is a dseries object:
| Variable_1
2000Q1 | 0.80028
2000Q2 | 0.14189
2000Q3 | 0.42176
2000Q4 | 0.91574
2001Q1 | 0.79221
>> ts1
ts1 is a dseries object:
| Variable_1
2000Q4 | 0.95949
2001Q1 | 0.65574
2001Q2 | 0.035712
>> align_(ts0, ts1); % 2000Q1 -> 2001Q2
>> ts0
ts0 is a dseries object:
| Variable_1
2000Q1 | 0.80028
2000Q2 | 0.14189
2000Q3 | 0.42176
2000Q4 | 0.91574
2001Q1 | 0.79221
2001Q2 | NaN
>> ts1
ts1 is a dseries object:
| Variable_1
2000Q1 | NaN
2000Q2 | NaN
2000Q3 | NaN
2000Q4 | 0.95949
2001Q1 | 0.65574
2001Q2 | 0.035712
.. dseriesmethod:: C = backcast (A, B[, diff])
backcast_ (A, B[, diff])
backcast_ (B[, diff])
Backcasts ``dseries`` object ``A`` with ``dseries`` object B's
growth rates (except if the last optional argument, ``diff``,
......@@ -1213,8 +1330,8 @@ The dseries class
``dseries`` objects must have the same frequency.
.. dseriesmethod:: B = baxter_king_filter (A, hf, lf, K)
baxter_king_filter_ (A, hf, lf, K)
.. dseriesmethod:: B = baxter_king_filter (A[, hf[, lf[, K]]])
baxter_king_filter_ ([hf[, lf[, K]]])
|br| Implementation of the *Baxter and King* (1999) band pass
filter for ``dseries`` objects. This filter isolates business
......@@ -1260,7 +1377,7 @@ The dseries class
.. dseriesmethod:: B = center (A[, geometric])
center_ (A[, geometric])
center_ ([geometric])
|br| Centers variables in ``dseries`` object ``A`` around their
arithmetic means, except if the optional argument ``geometric``
......@@ -1269,7 +1386,7 @@ The dseries class
.. dseriesmethod:: C = chain (A, B)
chain_ (A, B)
chain_ (B)
|br| Merge two ``dseries`` objects along the time
dimension. The two objects must have the same number of
......@@ -1282,7 +1399,7 @@ The dseries class
::
>> ts = dseries([1; 2; 3; 4],dates(`1950Q1'))
>> ts = dseries([1; 2; 3; 4],dates('1950Q1'))
ts is a dseries object:
......@@ -1292,7 +1409,7 @@ The dseries class
1950Q3 | 3
1950Q4 | 4
>> us = dseries([3; 4; 5; 6],dates(`1950Q3'))
>> us = dseries([3; 4; 5; 6],dates('1950Q3'))
us is a dseries object:
......@@ -1314,6 +1431,25 @@ The dseries class
1951Q1 | 5
1951Q2 | 6
*Example (in-place modification version)*
::
>> ts = dseries([1; 2; 3; 4],dates('1950Q1'))
>> us = dseries([3; 4; 5; 6],dates('1950Q3'))
>> ts.chain_(us);
>> ts
ts is a dseries object:
| Variable_1
1950Q1 | 1
1950Q2 | 2
1950Q3 | 3
1950Q4 | 4
1951Q1 | 5
1951Q2 | 6
.. dseriesmethod:: [error_flag, message ] = check (A)
......@@ -1384,7 +1520,7 @@ The dseries class
.. dseriesmethod:: B = cumprod (A[, d[, v]])
cumprod_ (A[, d[, v]])
cumprod_ ([d[, v]])
|br| Overloads the MATLAB/Octave ``cumprod`` function for
``dseries`` objects. The cumulated product cannot be computed
......@@ -1447,7 +1583,7 @@ The dseries class
.. dseriesmethod:: B = cumsum (A[, d[, v]])
cumsum (A[, d[, v]])
cumsum_ ([d[, v]])
|br| Overloads the MATLAB/Octave ``cumsum`` function for
``dseries`` objects. The cumulated sum cannot be computed if
......@@ -1518,22 +1654,23 @@ The dseries class
10Y | 10.1416
.. dseriesmethod:: B = detrend (A, m)
detrend_ (A, m)
.. dseriesmethod:: B = detrend (A[, m])
detrend_ ([m])
|br| Detrends ``dseries`` object ``A`` with a fitted
polynomial of order ``m``. Note that each variable is
detrended with a different polynomial.
polynomial of order ``m``. Default value fir ``m`` is 0 (time
series are detrended by removing the average). Note that each
variable is detrended with a different polynomial.
.. dseriesmethod:: B = dgrowth (A)
dgrowth_ (A)
dgrowth_ ()
|br| Computes daily growth rates.
.. dseriesmethod:: B = diff (A)
diff_ (A)
diff_ ()
|br| Returns the first difference of ``dseries`` object ``A``.
......@@ -1623,6 +1760,29 @@ The dseries class
>> ts0 = dseries(rand(10,1));
>> ts1 = ts0.exp();
*Exemple (in-place modification version)*
::
>> ts0 = dseries(rand(3,1))
ts0 is a dseries object:
| Variable_1
1Y | 0.82953
2Y | 0.84909
3Y | 0.37253
>> ts0.exp_();
>> ts0
ts0 is a dseries object:
| Variable_1
1Y | 2.2922
2Y | 2.3375
3Y | 1.4514
.. dseriesmethod:: C = extract (A, B[, ...])
......@@ -1671,9 +1831,40 @@ The dseries class
1973Q4 | -0.03705 | -0.35899 | 0.85838 | -1.4675 | -2.1666 | -0.62032
.. dseriesmethod:: fill_(name, v)
|br| Assign the value ``v`` to the variable ``name`` in a
dseries object. If ``name`` is a character row array, it should
correspond to an existing variable within the dseries
object. When ``v`` is a scalar, its value will be applied to
all periods uniformly. If ``v`` is a vector, its length must
match the number of observations in the dseries object.You can
invoke this method for a batch of variables by providing a 1 by
n cell array of character row arrays as the first argument. When
"v" is a row vector with n elements, the method will be applied
uniformly across all periods. If "v" is a matrix, it must have
n columns, and the number of rows should correspond to the
number of periods.
*Example*
::
>> ts = dseries(rand(3,3));
>> ts.fill_({'Variable_1', 'Variable_3'}, [1 3]);
>> ts
ts is a dseries object:
| Variable_1 | Variable_2 | Variable_3
1Y | 1 | 0.91338 | 3
2Y | 1 | 0.63236 | 3
3Y | 1 | 0.09754 | 3
.. dseriesmethod:: f = firstdate (A)
|br| Returns the first period in ``dseries`` object ``A``.
|br| Returns the initial period in the ``dseries`` object ``A``.
.. dseriesmethod:: f = firstobservedperiod (A)
......@@ -1704,6 +1895,66 @@ The dseries class
4
.. dseriesmethod:: l = ge (A, B)
l = gt (A, B)
|br| Overloads the ``gt`` (>) and ``ge`` (>=) binary operators. Returns a logical array.
*Example*
::
>> ts = dseries(randn(3,1))
ts is a dseries object:
| Variable_1
1Y | -1.2075
2Y | 0.71724
3Y | 1.6302
>> ts>1
ans =
3x1 logical array
0
0
1
>> ds = dseries(randn(3,1))
ds is a dseries object:
| Variable_1
1Y | 0.48889
2Y | 1.0347
3Y | 0.72689
>> ds>ts
ans =
3x1 logical array
1
1
0
.. dseriesmethod:: B = hdiff (A)
hdiff_ ()
|br| Computes bi-annual differences.
.. dseriesmethod:: B = hgrowth (A)
hgrowth_ ()
|br| Computes bi-annual growth rates.
.. dseriesmethod:: D = horzcat (A, B[, ...])
|br| Overloads the ``horzcat`` MATLAB/Octave’s method for
......@@ -1740,7 +1991,7 @@ The dseries class
.. dseriesmethod:: B = hpcycle (A[, lambda])
hpcycle_ (A[, lambda])
hpcycle_ ([lambda])
|br| Extracts the cycle component from a ``dseries`` ``A``
object using the *Hodrick and Prescott (1997)* filter and
......@@ -1781,7 +2032,7 @@ The dseries class
.. dseriesmethod:: B = hptrend (A[, lambda])
hptrend_ (A[, lambda])
hptrend_ ([lambda])
|br| Extracts the trend component from a ``dseries`` A object
using the *Hodrick and Prescott (1997)* filter and returns a
......@@ -1878,10 +2129,12 @@ The dseries class
.. dseriesmethod:: B = lag (A[, p])
lag_ (A[, p])
lag_ ([p])
|br| Returns lagged time series. Default value of integer scalar ``p``, the number
of lags, is ``1``.
|br| Returns lagged time series. Default value of integer
scalar ``p``, the number of lags, is ``1``. The `dseries`
class overloads the parentheses, so that `ts.lag(p)` is
equivalent to `ts(-p)`.
*Example*
......@@ -1946,7 +2199,7 @@ The dseries class
.. dseriesmethod:: l = lastdate (B)
|br| Returns the last period in ``dseries`` object ``B``.
|br| Retrieves the final period from the ``dseries`` object ``B``.
*Example*
......@@ -1960,23 +2213,76 @@ The dseries class
.. dseriesmethod:: f = lastobservedperiod (A)
|br| Returns the last period where all the variables in ``dseries`` object ``A`` are observed (non NaN).
|br| Returns the last period in which all variables of the
``dseries`` object ``A`` are fully observed (i.e., contain no
NaN values).
.. dseriesmethod:: f = lastobservedperiods (A)
|br| Returns for each variable the last period without missing
observations in ``dseries`` object ``A``. Output argument ``f`` is a
structure, each field name is the name of a variable in ``A``, each field
content is a singleton ``date`` object.
|br| Returns the last period without missing observations for
each variable in the ``dseries`` object ``A``. The output
argument ``f`` is a structure where each field name corresponds
to a variable in ``A``, and the content of each field is a
singleton ``date`` object.
.. dseriesmethod:: l = le (A, B)
l = lt (A, B)
|br| Overloads the ``gt`` (<) and ``ge`` (<=) binary operators. Returns a logical array.
*Example*
::
>> ts = dseries(randn(3,1))
ts is a dseries object:
| Variable_1
1Y | -1.2075
2Y | 0.71724
3Y | 1.6302
>> ts<1
ans =
3x1 logical array
1
1
0
>> ds = dseries(randn(3,1))
ds is a dseries object:
| Variable_1
1Y | 0.48889
2Y | 1.0347
3Y | 0.72689
>> ds<ts
ans =
3x1 logical array
0
0
1
.. dseriesmethod:: B = lead (A[, p])
lead_ (A[, p])
lead_ ([p])
|br| Returns lead time series. Default value of integer scalar
``p``, the number of leads, is ``1``. As in the ``lag``
method, the ``dseries`` class overloads the parenthesis so
that ``ts.lead(p)`` is equivalent to ``ts(p)``.
|br| Returns a lead time series. The default value for the
integer scalar ``p``, which represents the number of leads, is
``1``. Similar to the ``lag`` method, the ``dseries`` class
overloads the parentheses, making ``ts.lead(p)`` equivalent to
``ts(p)``.
*Example*
......@@ -2005,11 +2311,11 @@ The dseries class
*Remark*
The overloading of the parenthesis for ``dseries`` objects,
allows to easily create new ``dseries`` objects by
copying/pasting equations declared in the ``model`` block. For
instance, if an Euler equation is defined in the ``model``
block::
The overload of parentheses for ``dseries`` objects simplifies
the creation of new ``dseries`` instances by enabling the
direct copying and pasting of equations defined within the
``model`` block. For example, if an Euler equation is
specified in the ``model`` block,::
model;
...
......@@ -2050,7 +2356,7 @@ The dseries class
.. dseriesmethod:: B = log (A)
log_ (A)
log_ ()
|br| Overloads the MATLAB/Octave ``log`` function for
``dseries`` objects.
......@@ -2063,37 +2369,36 @@ The dseries class
>> ts1 = ts0.log();
.. dseriesmethod:: B = mdiff (A)
mdiff_ (A)
mdiff_ ()
B = mgrowth (A)
mgrowth_ (A)
mgrowth_ ()
|br| Computes monthly differences or growth rates of variables in
``dseries`` object ``A``.
|br| Calculates the monthly differences or growth rates of
variables in the ``dseries`` object ``A``.
.. dseriesmethod:: B = mean (A[, geometric])
|br| Overloads the MATLAB/Octave ``mean`` function for
``dseries`` objects. Returns the mean of each variable in
``dseries`` object ``A``. If the second argument is ``true``
the geometric mean is computed, otherwise (default) the
arithmetic mean is reported.
|br| This function overloads the MATLAB/Octave ``mean``
function specifically for ``dseries`` objects. It calculates
the mean for each variable within the ``dseries`` object
``A``. If the second argument is set to ``true``, the
geometric mean is calculated; otherwise, the arithmetic mean
is computed by default.
.. dseriesmethod:: C = merge (A, B[, legacy])
|br| Merges two ``dseries`` objects ``A`` and ``B`` in
``dseries`` object ``C``. Objects ``A`` and ``B`` need to have
common frequency but can be defined on different time
ranges. If a variable, say ``x``, is defined both in
``dseries`` objects ``A`` and ``B``, then the ``merge`` will
select the variable ``x`` as defined in the second input
argument, ``B``, except for the NaN elements in ``B`` if
corresponding elements in ``A`` (ie same periods) are well
defined numbers. This behaviour can be changed by setting the
optional argument ``legacy`` equal to true, in which case the
second variable overwrites the first one even if the second
variable has NaNs.
|br| Merges two ``dseries`` objects, ``A`` and ``B``, into a new
``dseries`` object ``C``. The objects ``A`` and ``B`` must share a
common frequency, although they can cover different time
ranges. If a variable, such as ``x``, exists in both ``dseries``
objects, the ``merge`` function will prioritize the definition
from the second input, ``B``, while retaining the values from
``A`` for any corresponding periods where ``B`` has NaN
values. This behavior can be altered by setting the optional
argument ``legacy`` to true, in which case the second variable
will replace the first, even if it contains NaN values.
*Example*
......@@ -2141,30 +2446,29 @@ The dseries class
.. dseriesmethod:: C = minus (A, B)
|br| Overloads the MATLAB/Octave ``minus`` (``-``) operator
for ``dseries`` objects, element by element subtraction. If
both ``A`` and ``B`` are ``dseries`` objects, they do not need
to be defined over the same time ranges. If ``A`` and ``B``
are ``dseries`` objects with :math:`T_A` and :math:`T_B`
for ``dseries`` objects, allowing for element-by-element
subtraction. When both ``A`` and ``B`` are ``dseries``
objects, they do not need to be defined over the same time
ranges. If ``A`` and ``B`` have :math:`T_A` and :math:`T_B`
observations and :math:`N_A` and :math:`N_B` variables, then
:math:`N_A` must be equal to :math:`N_B` or :math:`1` and
:math:`N_B` must be equal to :math:`N_A` or :math:`1`. If
:math:`T_A=T_B`, ``isequal(A.init,B.init)`` returns ``1`` and
:math:`N_A=N_B`, then the ``minus`` operator will compute for
each couple :math:`(t,n)`, with :math:`1\le t\le T_A` and
:math:`1\le n\le N_A`,
``C.data(t,n)=A.data(t,n)-B.data(t,n)``. If :math:`N_B` is
equal to :math:`1` and :math:`N_A>1`, the smaller ``dseries``
object (``B``) is “broadcast” across the larger ``dseries``
(``A``) so that they have compatible shapes, the ``minus``
operator will subtract the variable defined in ``B`` from each
variable in ``A``. If ``B`` is a double scalar, then the
method ``minus`` will subtract ``B`` from all the
observations/variables in ``A``. If ``B`` is a row vector of
length :math:`N_A`, then the ``minus`` method will subtract
``B(i)`` from all the observations of variable ``i``, for
:math:`N_A` must equal :math:`N_B` or :math:`1`, and
:math:`N_B` must equal :math:`N_A` or :math:`1`. If
:math:`T_A=T_B`, ``isequal(A.init,B.init)`` returns ``1``,
and :math:`N_A=N_B`, then the ``minus`` operator will compute
for each pair :math:`(t,n)`, where :math:`1\le t\le T_A` and
:math:`1\le n\le N_A`, the operation
``C.data(t,n)=A.data(t,n)-B.data(t,n)``. If :math:`N_B` equals
:math:`1` and :math:`N_A>1`, the smaller ``dseries`` object
(``B``) is “broadcasted” across the larger ``dseries`` (``A``),
ensuring compatible shapes for the subtraction of the variable
defined in ``B`` from each variable in ``A``. If ``B`` is a
double scalar, the ``minus`` method will subtract ``B`` from
all observations and variables in ``A``. If ``B`` is a row
vector of length :math:`N_A`, the ``minus`` method will
subtract ``B(i)`` from all observations of variable ``i``, for
:math:`i=1,...,N_A`. If ``B`` is a column vector of length
:math:`T_A`, then the ``minus`` method will subtract ``B``
from all the variables.
:math:`T_A`, the ``minus`` method will subtract ``B`` from all
the variables.
*Example*
......@@ -2211,15 +2515,16 @@ The dseries class
.. dseriesmethod:: C = mpower (A, B)
|br| Overloads the MATLAB/Octave ``mpower`` (``^``) operator for ``dseries``
objects and computes element-by-element power. ``A`` is a
|br| Overloads the MATLAB/Octave ``mpower`` (``^``) operator
for ``dseries`` objects, performing element-wise
exponentiation. Given a ``dseries`` object ``A`` with ``N``
variables and ``T`` observations, if ``B`` is a real scalar,
then ``mpower(A,B)`` yields a ``dseries`` object ``C`` where
``C.data(t,n) = A.data(t,n)^B``. If ``B`` is also a
``dseries`` object with ``N`` variables and ``T``
observations. If ``B`` is a real scalar, then ``mpower(A,B)``
returns a ``dseries`` object ``C`` with
``C.data(t,n)=A.data(t,n)^C``. If ``B`` is a ``dseries``
object with ``N`` variables and ``T`` observations then
``mpower(A,B)`` returns a ``dseries`` object ``C`` with
``C.data(t,n)=A.data(t,n)^C.data(t,n)``.
observations, then ``mpower(A,B)`` produces a ``dseries``
object ``C`` such that ``C.data(t,n) =
A.data(t,n)^{C.data(t,n)}``.
*Example*
......@@ -2247,31 +2552,31 @@ The dseries class
.. dseriesmethod:: C = mrdivide (A, B)
|br| Overloads the MATLAB/Octave ``mrdivide`` (``/``) operator for
``dseries`` objects, element by element division (like the
``./`` MATLAB/Octave operator). If both ``A`` and ``B`` are
``dseries`` objects, they do not need to be defined over the
same time ranges. If ``A`` and ``B`` are ``dseries`` objects
with :math:`T_A` and :math:`T_B` observations and :math:`N_A`
and :math:`N_B` variables, then :math:`N_A` must be equal to
:math:`N_B` or :math:`1` and :math:`N_B` must be equal to
:math:`N_A` or :math:`1`. If :math:`T_A=T_B`,
``isequal(A.init,B.init)`` returns ``1`` and :math:`N_A=N_B`,
then the ``mrdivide`` operator will compute for each couple
:math:`(t,n)`, with :math:`1\le t\le T_A` and :math:`1\le n\le
N_A`, ``C.data(t,n)=A.data(t,n)/B.data(t,n)``. If :math:`N_B`
is equal to :math:`1` and :math:`N_A>1`, the smaller
``dseries`` object (``B``) is “broadcast” across the larger
``dseries`` (``A``) so that they have compatible shapes. In
this case the ``mrdivide`` operator will divide each variable
defined in A by the variable in B, observation per
observation. If B is a double scalar, then ``mrdivide`` will
divide all the observations/variables in ``A`` by ``B``. If
``B`` is a row vector of length :math:`N_A`, then ``mrdivide``
will divide all the observations of variable ``i`` by
``B(i)``, for :math:`i=1,...,N_A`. If ``B`` is a column vector
of length :math:`T_A`, then ``mrdivide`` will perform a
division of all the variables by ``B``, element by element.
|br| Overloads the MATLAB/Octave ``mrdivide`` (``/``) operator
for ``dseries`` objects, enabling element-wise division
similar to the ``./`` operator in MATLAB/Octave. When both
``A`` and ``B`` are ``dseries`` objects, they can have
different time ranges. If ``A`` contains :math:`T_A`
observations and :math:`N_A` variables, and ``B`` has
:math:`T_B` observations and :math:`N_B` variables, then
:math:`N_A` must equal :math:`N_B` or :math:`1`, and vice
versa. If :math:`T_A=T_B` and ``isequal(A.init,B.init)``
returns ``1``, along with :math:`N_A=N_B`, the ``mrdivide``
operator calculates for each pair :math:`(t,n)`, where
:math:`1\le t\le T_A` and :math:`1\le n\le N_A`, the value of
``C.data(t,n)=A.data(t,n)/B.data(t,n)``. If :math:`N_B` equals
:math:`1` and :math:`N_A>1`, the smaller ``dseries`` object
(``B``) is “broadcast” across the larger one (``A``) to ensure
compatible shapes. In this case, the ``mrdivide`` operator
divides each variable in ``A`` by the variable in ``B``,
observation by observation. If ``B`` is a double scalar, then
``mrdivide`` will divide all observations and variables in
``A`` by ``B``. If ``B`` is a row vector of length
:math:`N_A`, then ``mrdivide`` will divide each observation of
variable ``i`` by ``B(i)``, for :math:`i=1,...,N_A`. If ``B``
is a column vector of length :math:`T_A`, then ``mrdivide``
will perform an element-wise division of all variables by
``B``.
*Example*
......@@ -2300,62 +2605,62 @@ The dseries class
.. dseriesmethod:: C = mtimes (A, B)
|br| Overloads the MATLAB/Octave ``mtimes`` (``*``) operator
for ``dseries`` objects and the Hadammard product (the .*
MATLAB/Octave operator). If both ``A`` and ``B`` are
``dseries`` objects, they do not need to be defined over the
same time ranges. If ``A`` and ``B`` are ``dseries`` objects
with :math:`T_A` and :math:`_B` observations and :math:`N_A`
and :math:`N_B` variables, then :math:`N_A` must be equal to
:math:`N_B` or :math:`1` and :math:`N_B` must be equal to
:math:`N_A` or :math:`1`. If :math:`T_A=T_B`,
``isequal(A.init,B.init)`` returns ``1`` and :math:`N_A=N_B`,
then the ``mtimes`` operator will compute for each couple
:math:`(t,n)`, with :math:`1\le t\le T_A` and :math:`1\le n\le
N_A`, ``C.data(t,n)=A.data(t,n)*B.data(t,n)``. If :math:`N_B`
is equal to :math:`1` and :math:`N_A>1`, the smaller
``dseries`` object (``B``) is “broadcast” across the larger
``dseries`` (``A``) so that they have compatible shapes,
``mtimes`` operator will multiply each variable defined in
``A`` by the variable in ``B``, observation per
observation. If ``B`` is a double scalar, then the method
``mtimes`` will multiply all the observations/variables in
for ``dseries`` objects, enabling element-wise multiplication
similar to the ``.*`` operator in MATLAB/Octave. When both
``A`` and ``B`` are ``dseries`` objects, they can have
different time ranges. If ``A`` contains :math:`T_A`
observations and :math:`N_A` variables, and ``B`` has
:math:`T_B` observations and :math:`N_B` variables, then
:math:`N_A` must equal :math:`N_B` or :math:`1`, and vice
versa. If :math:`T_A=T_B` and ``isequal(A.init,B.init)``
returns ``1``, along with :math:`N_A=N_B`, the ``mtimes``
operator calculates for each pair :math:`(t,n)`, where
:math:`1\le t\le T_A` and :math:`1\le n\le N_A`, the value of
``C.data(t,n)=A.data(t,n)*B.data(t,n)``. If :math:`N_B` equals
:math:`1` and :math:`N_A>1`, the smaller ``dseries`` object
(``B``) is “broadcasted” across the larger one (``A``) to ensure
compatible shapes. In this case, the ``mtimes`` operator
multiply each variable in ``A`` by the variable in ``B``,
observation by observation. If ``B`` is a double scalar, then
``mtimes`` will multiply all observations and variables in
``A`` by ``B``. If ``B`` is a row vector of length
:math:`N_A`, then the ``mtimes`` method will multiply all the
observations of variable ``i`` by ``B(i)``, for
:math:`i=1,...,N_A`. If ``B`` is a column vector of length
:math:`T_A`, then the ``mtimes`` method will perform a
multiplication of all the variables by ``B``, element by
element.
:math:`N_A`, then ``mtimes`` will multiply each observation of
variable ``i`` by ``B(i)``, for :math:`i=1,...,N_A`. If ``B``
is a column vector of length :math:`T_A`, then ``mtimes``
will perform an element-wise multiplication of all variables by
``B``.
.. dseriesmethod:: B = nanmean (A[, geometric])
|br| Overloads the MATLAB/Octave ``nanmean`` function for
``dseries`` objects. Returns the mean of each variable in
``dseries`` object ``A`` ignoring the NaN values. If the
second argument is ``true`` the geometric mean is computed,
otherwise (default) the arithmetic mean is reported.
``dseries`` objects. Computes the mean of each variable in the
``dseries`` object ``A``, excluding NaN values. If the second
argument is ``true``, the geometric mean is calculated;
otherwise, the default is to report the arithmetic mean.
.. dseriesmethod:: B = nanstd (A[, geometric])
|br| Overloads the MATLAB/Octave ``nanstd`` function for
``dseries`` objects. Returns the standard deviation of each
variable in ``dseries`` object ``A`` ignoring the NaN
values. If the second argument is ``true`` the geometric std
is computed, default value of the second argument is
``dseries`` objects. This function calculates the standard
deviation for each variable within the ``dseries`` object
``A``, while disregarding any NaN values. If the second
argument is set to ``true``, the geometric standard deviation
will be computed; the default value for the second argument is
``false``.
.. dseriesmethod:: C = ne (A, B)
|br| Overloads the MATLAB/Octave ``ne`` (not equal, ``~=``)
operator. ``dseries`` objects ``A`` and ``B`` must have the
same number of observations (say, :math:`T`) and variables
(:math:`N`). The returned argument is a :math:`T` by :math:`N`
matrix of zeros and ones. Element :math:`(i,j)` of ``C`` is
equal to ``1`` if and only if observation :math:`i` for
variable :math:`j` in ``A`` and ``B`` are not equal.
operator. The ``dseries`` objects ``A`` and ``B`` must contain
the same number of observations (denoted as :math:`T`) and
variables (denoted as :math:`N`). The output is a :math:`T` by
:math:`N` matrix consisting of zeros and ones. The element
:math:`(i,j)` of the matrix ``C`` is equal to ``1`` if and
only if observation :math:`i` for variable :math:`j` in ``A``
and ``B`` are not equal.
*Example*
......@@ -2392,25 +2697,25 @@ The dseries class
.. dseriesmethod:: B = onesidedhpcycle (A[, lambda[, init]])
onesidedhpcycle_ (A[, lambda[, init]])
onesidedhpcycle_ ([lambda[, init]])
|br| Extracts the cycle component from a ``dseries`` ``A``
object using a one sided HP filter (with a Kalman filter) and
returns a ``dseries`` object, ``B``. The default value for
``lambda``, the smoothing parameter, is ``1600``. By default,
if ``ìnit`` is not provided, the initial value is based on the
first two observations.
object using a one-sided HP filter (implemented with a Kalman
filter) and returns a ``dseries`` object, ``B``. The default
value for ``lambda``, the smoothing parameter, is set to
``1600``. By default, if ``init`` is not provided, the initial
value is determined from the first two observations.
.. dseriesmethod:: B = onesidedhptrend (A[, lambda[, init]])
onesidedhptrend_ (A[, lambda[, init]])
|br| Extracts the trend component from a ``dseries`` ``A``
object using a one sided HP filter (with a Kalman filter) and
returns a ``dseries`` object, ``B``. The default value for
``lambda``, the smoothing parameter, is ``1600``. By default,
if ``ìnit`` is not provided, the initial value is based on the
first two observations.
object using a one-sided HP filter (implemented with a Kalman
filter) and returns a ``dseries`` object, ``B``. The default
value for ``lambda``, the smoothing parameter, is set to
``1600``. By default, if ``init`` is not provided, the initial
value is derived from the first two observations.
.. dseriesmethod:: h = plot (A)
......@@ -2418,27 +2723,28 @@ The dseries class
h = plot (A[, ...])
h = plot (A, B[, ...])
|br| Overloads MATLAB/Octave’s ``plot`` function for
``dseries`` objects. Returns a MATLAB/Octave plot handle, that
can be used to modify the properties of the plotted time
series. If only one ``dseries`` object, ``A``, is passed as
argument, then the plot function will put the associated dates
on the x-abscissa. If this ``dseries`` object contains only
one variable, additional arguments can be passed to modify the
properties of the plot (as one would do with the
MATLAB/Octave’s version of the plot function). If ``dseries``
object ``A`` contains more than one variable, it is not
possible to pass these additional arguments and the properties
of the plotted time series must be modified using the returned
plot handle and the MATLAB/Octave ``set`` function (see
example below). If two ``dseries`` objects, ``A`` and ``B``,
are passed as input arguments, the plot function will plot the
variables in ``A`` against the variables in ``B`` (the number
of variables in each object must be the same otherwise an
error is issued). Again, if each object contains only one
variable, additional arguments can be passed to modify the
properties of the plotted time series, otherwise the
MATLAB/Octave ``set`` command has to be used.
|br| Overloads the MATLAB/Octave ``plot`` function for
``dseries`` objects. This function returns a MATLAB/Octave
plot handle, which can be utilized to modify the properties of
the plotted time series. If a single ``dseries`` object,
``A``, is provided as an argument, the plot function will
place the corresponding dates on the x-axis. If this
``dseries`` object contains only one variable, additional
arguments can be included to adjust the plot properties,
similar to how one would with MATLAB/Octave's original plot
function. However, if the ``dseries`` object ``A`` has more
than one variable, additional arguments cannot be passed, and
modifications to the plotted time series properties must be
done using the returned plot handle alongside the
MATLAB/Octave ``set`` function (refer to the example
below). When two ``dseries`` objects, ``A`` and ``B``, are
passed as input arguments, the plot function will display the
variables in ``A`` against those in ``B`` (it is essential
that both objects contain the same number of variables;
otherwise, an error will occur). Once more, if each object
includes only one variable, additional arguments can be
utilized to alter the plotted time series properties;
otherwise, the MATLAB/Octave ``set`` command must be employed.
*Example*
......@@ -2479,7 +2785,7 @@ The dseries class
.. dseriesmethod:: C = plus (A, B)
|br| Overloads the MATLAB/Octave ``plus`` (``+``) operator for
``dseries`` objects, element by element addition. If both
``dseries`` objects, allowing for element-wise addition. When both
``A`` and ``B`` are ``dseries`` objects, they do not need to
be defined over the same time ranges. If ``A`` and ``B`` are
``dseries`` objects with :math:`T_A` and :math:`T_B`
......@@ -2488,28 +2794,28 @@ The dseries class
:math:`N_B` must be equal to :math:`N_A` or :math:`1`. If
:math:`T_A=T_B`, ``isequal(A.init,B.init)`` returns ``1`` and
:math:`N_A=N_B`, then the ``plus`` operator will compute for
each couple :math:`(t,n)`, with :math:`1\le t\le T_A` and
each pair :math:`(t,n)`, with :math:`1\le t\le T_A` and
:math:`1\le n\le N_A`,
``C.data(t,n)=A.data(t,n)+B.data(t,n)``. If :math:`N_B` is
equal to :math:`1` and :math:`N_A>1`, the smaller ``dseries``
object (``B``) is “broadcast” across the larger ``dseries``
(``A``) so that they have compatible shapes, the plus operator
object (``B``) is “broadcasted” across the larger ``dseries``
(``A``) to ensure compatible shapes, the plus operator
will add the variable defined in ``B`` to each variable in
``A``. If ``B`` is a double scalar, then the method ``plus``
will add ``B`` to all the observations/variables in ``A``. If
``B`` is a row vector of length :math:`N_A`, then the ``plus``
method will add ``B(i)`` to all the observations of variable
``i``, for :math:`i=1,...,N_A`. If ``B`` is a column vector of
``i``, for :math:`i=1,\ldots,N_A`. If ``B`` is a column vector of
length :math:`T_A`, then the ``plus`` method will add ``B`` to
all the variables.
.. dseriesmethod:: C = pop (A[, B])
pop_ (A[, B])
pop_ ([B])
|br| Removes variable ``B`` from ``dseries`` object ``A``. By
default, if the second argument is not provided, the last
variable is removed.
|br| Removes the variable ``B`` from the ``dseries`` object
``A``. By default, if the second argument is not specified, the
last variable is removed.
*Example*
......@@ -2528,26 +2834,25 @@ The dseries class
.. dseriesmethod:: A = projection (A, info, periods)
|br| Projects variables in dseries object ``A``. ``info`` is
is a :math:`n \times 3` cell array. Each row provides
informations necessary to project a variable. The first column
contains the name of variable (row char array). the second
column contains the name of the method used to project the
associated variable (row char array), possible values are
``'Trend'``, ``'Constant'``, and ``'AR'``. Last column
provides quantitative information about the projection. If the
second column value is ``'Trend'``, the third column value is
the growth factor of the (exponential) trend. If the second
column value is ``'Constant'``, the third column value is the
level of the variable. If the second column value is ``'AR'``,
the third column value is the autoregressive parameter. The
variables can be projected with an AR(p) model, if the third
column contains a 1×p vector of doubles. The stationarity of
the AR(p) model is not tested. The case of the constant
projection, using the last value of the variable, is covered
with 'Trend' and a growth factor equal to 1, or 'AR' with an
autoregressive parameter equal to one (random walk). This
projection routine only deals with exponential trends.
|br| Projects variables in the dseries object ``A``. The
``info`` variable is a :math:`n \times 3` cell array, where
each row contains essential information for projecting a
variable. The first column holds the variable name (as a
character array), while the second column indicates the
projection method used (also a character array). The possible
values for this column are ``'Trend'``, ``'Constant'``, and
``'AR'``. The third column provides quantitative details
related to the projection: if the second column is
``'Trend'``, the third column specifies the growth factor of
the (exponential) trend; if ``'Constant'``, it indicates the
variable's level; and if ``'AR'``, it denotes the
autoregressive parameter. Variables can be projected using an
AR(p) model if the third column contains a 1×p vector of
doubles. Note that the stationarity of the AR(p) model is not
tested. For constant projections, one can use either `'Trend'`
with a growth factor of 1 or `'AR'` with an autoregressive
parameter of one (indicating a random walk). This projection
routine solely addresses exponential trends.
*Example*
......@@ -2561,8 +2866,8 @@ The dseries class
.. dseriesmethod:: B = qdiff (A)
B = qgrowth (A)
qdiff_ (A)
qgrowth_ (A)
qdiff_ ()
qgrowth_ ()
|br| Computes quarterly differences or growth rates.
......@@ -2596,12 +2901,14 @@ The dseries class
.. dseriesmethod:: C = remove (A, B)
remove_ (A, B)
remove_ (B)
|br| If ``B`` is a row char array, the name of a variable, these methods
are aliases for ``pop`` and ``pop_`` methods with two arguments. They
remove variable ``B`` from ``dseries`` object ``A``. To remove more than
one variable, one can pass a cell of row char arrays for ``B``.
|br| If ``B`` is a row character array representing the name
of a variable, these methods serve as aliases for the ``pop``
and ``pop_`` methods that accept two arguments. They remove
the variable ``B`` from the ``dseries`` object ``A``. To
remove multiple variables, you can pass a cell array of row
character arrays for ``B``.
*Example*
......@@ -2617,11 +2924,11 @@ The dseries class
2Y | 1 | 1
3Y | 1 | 1
A shorter syntax is available: ``remove(ts,'Variable_2')``
is equivalent to ``ts{'Variable_2'} = []`` (``[]`` can be
replaced by any empty object). This alternative syntax is
useful if more than one variable has to be removed. For
instance::
A more concise syntax is available: ``remove(ts,
'Variable_2')``, which is equivalent to ``ts{'Variable_2'}
= []`` (where ``[]`` can be substituted with any empty
object). This alternative syntax proves useful when
removing multiple variables. For example::
ts{'Variable_@2,3,4@'} = [];
......@@ -2632,12 +2939,13 @@ The dseries class
.. dseriesmethod:: B = rename (A, oldname, newname)
rename_ (A, oldname, newname)
rename_ (oldname, newname)
|br| Rename variable ``oldname`` to ``newname`` in ``dseries``
object ``A``. Returns a ``dseries`` object. If more than one
variable needs to be renamed, it is possible to pass cells of
char arrays as second and third arguments.
|br| Renames the variable ``oldname`` to ``newname`` in the
``dseries`` object ``A``. This function returns a ``dseries``
object. If multiple variables need to be renamed, you can
provide cell arrays of row character arrays as the second and
third arguments.
*Example*
......@@ -2654,12 +2962,12 @@ The dseries class
.. dseriesmethod:: C = rename (A, newname)
rename_ (A, newname)
rename_ (newname)
|br| Replace the names in ``A`` with those passed in the cell
string array ``newname``. ``newname`` must have the same
number of elements as ``dseries`` object ``A`` has
variables. Returns a ``dseries`` object.
|br| Replace the names in ``A`` with those specified in the
cell of row character arrays ``newname``. The cell ``newname`` must contain
the same number of elements as there are variables in the
``dseries`` object ``A``.
*Example*
......@@ -2686,12 +2994,12 @@ The dseries class
.. dseriesmethod:: B = round (A[, n])
round_ (A[, n])
round_ ([n])
|br| Rounds to the nearest decimal or integer. ``n`` is the
precision parameter (number of decimals), default value is 0
meaning that that by default the method rounds to the nearest
integer.
|br| Rounds each value to the nearest decimal or integer. The
parameter ``n`` specifies the precision (number of decimal
places), with a default value of 0, indicating that the method
will round to the nearest integer by default.
*Example*
......@@ -2715,11 +3023,12 @@ The dseries class
.. dseriesmethod:: save (A, basename[, format])
|br| Overloads the MATLAB/Octave ``save`` function and saves
``dseries`` object ``A`` to disk. Possible formats are ``mat``
(this is the default), ``m`` (MATLAB/Octave script), and
``csv`` (MATLAB binary data file). The name of the file
without extension is specified by ``basename``.
|br| Overloads the MATLAB/Octave ``save`` function to save the
``dseries`` object ``A`` to disk. The available formats
include ``mat`` (default, MATLAB binary data file), ``m``
(MATLAB/Octave script), and ``csv`` (comma-separated values
file). The base name of the file, excluding the extension, is
specified by ``basename``.
*Example*
......@@ -2766,13 +3075,14 @@ The dseries class
.. dseriesmethod:: B = set_names(A, s1, s2, ...)
|br| Renames variables in ``dseries`` object ``A`` and returns
a ``dseries`` object ``B`` with new names ``s1``, ``s2``,
... The number of input arguments after the first one
(``dseries`` object ``A``) must be equal to ``A.vobs`` (the
number of variables in ``A``). ``s1`` will be the name of the
first variable in ``B``, ``s2`` the name of the second
variable in ``B``, and so on.
|br| Renames the variables in the ``dseries`` object ``A`` and
returns a new ``dseries`` object ``B`` with the updated names
``s1``, ``s2``, and so forth. The number of input arguments
following the first one (the ``dseries`` object ``A``) must be
equal to ``A.vobs`` (the total number of variables in
``A``). The name ``s1`` will correspond to the first variable
in ``B``, ``s2`` to the second variable in ``B``, and this
pattern continues for the remaining variables.
*Example*
......@@ -2789,13 +3099,13 @@ The dseries class
.. dseriesmethod:: [T, N ] = size(A[, dim])
Overloads the MATLAB/Octave’s ``size`` function. Returns the
number of observations in ``dseries`` object ``A``
(i.e. ``A.nobs``) and the number of variables
(i.e. ``A.vobs``). If a second input argument is passed, the
``size`` function returns the number of observations if
``dim=1`` or the number of variables if ``dim=2`` (for all
other values of ``dim`` an error is issued).
Overloads the MATLAB/Octave ``size`` function to return the
number of observations in the ``dseries`` object ``A`` (i.e.,
``A.nobs``) as well as the number of variables (i.e.,
``A.vobs``). If a second input argument is provided, the
``size`` function will return the number of observations when
``dim=1`` or the number of variables when ``dim=2``. An error
will be issued for any other values of ``dim``.
*Example*
......@@ -2812,18 +3122,20 @@ The dseries class
.. dseriesmethod:: B = std (A[, geometric])
|br| Overloads the MATLAB/Octave ``std`` function for
``dseries`` objects. Returns the standard deviation of each
variable in ``dseries`` object ``A``. If the second argument
is ``true`` the geometric standard deviation is computed
(default value of the second argument is ``false``).
``dseries`` objects. This function returns the standard
deviation of each variable within the ``dseries`` object
``A``. If the second argument is set to ``true``, the
geometric standard deviation is calculated (the default value
for the second argument is ``false``).
.. dseriesmethod:: B = subsample (A, d1, d2)
|br| Returns a subsample, for periods between ``dates`` ``d1``
and ``d2``. The same can be achieved by indexing a
``dseries`` object with a ``dates`` object, but the
``subsample`` method is easier to use programmatically.
|br| Returns a subsample for the period between ``d1`` and
``d2``. While you can achieve the same result by indexing a
``dseries`` object with a ``dates`` object, the ``subsample``
method offers a more straightforward approach for programmatic
use.
*Example*
......@@ -2842,7 +3154,7 @@ The dseries class
.. dseriesmethod:: A = tag (A, a[, b, c])
|br| Add a tag to a variable in ``dseries`` object ``A``.
|br| Adds a tag to a variable in ``dseries`` object ``A``.
*Example*
......@@ -2857,23 +3169,24 @@ The dseries class
.. dseriesmethod:: B = tex_rename (A, name, newtexname)
B = tex_rename (A, newtexname)
tex_rename_ (A, name, newtexname)
tex_rename_ (A, newtexname)
tex_rename_ (name, newtexname)
tex_rename_ (newtexname)
|br| Redefines the tex name of variable ``name`` to
``newtexname`` in ``dseries`` object ``A``. Returns a
``dseries`` object.
|br| Updates the TeX name of the variable ``name`` to
``newtexname`` in the ``dseries`` object ``A``. Returns an
updated ``dseries`` object.
With only two arguments ``A`` and ``newtexname``, it redefines
the tex names of the ``A`` to those contained in
``newtexname``. Here, ``newtexname`` is a cell string array
with the same number of entries as variables in ``A``.
With just two arguments, ``A`` and ``newtexname``, this
function redefines the TeX names of the entries in ``A`` to
those specified in ``newtexname``. The ``newtexname`` argument
must be a cell row character arrays containing the same number of
entries as there are variables in ``A``.
.. dseriesmethod:: B = uminus(A)
|br| Overloads ``uminus`` (``-``, unary minus) for ``dseries``
object.
|br| Overloads the ``uminus`` operator (``-``, unary minus)
for the ``dseries`` object.
*Example*
......@@ -2896,13 +3209,13 @@ The dseries class
.. dseriesmethod:: D = vertcat (A, B[, ...])
|br| Overloads the ``vertcat`` MATLAB/Octave method for
``dseries`` objects. This method is used to append more
observations to a ``dseries`` object. Returns a ``dseries``
object ``D`` containing the variables in ``dseries`` objects
passed as inputs. All the input arguments must be ``dseries``
objects with the same variables defined on different time
ranges.
|br| Overloads the ``vertcat`` method in MATLAB/Octave for
``dseries`` objects. This method facilitates the appending of
additional observations to a ``dseries`` object. It returns a
new ``dseries`` object, ``D``, which contains the variables
from the input ``dseries`` objects. All input arguments must
be ``dseries`` objects that share the same variables but are
defined over different time ranges.
*Example*
......@@ -2923,8 +3236,7 @@ The dseries class
.. dseriesmethod:: B = vobs (A)
|br| Returns the number of variables in ``dseries`` object
``A``.
|br| Returns the count of variables in the ``dseries`` object ``A``.
*Example*
......@@ -2940,10 +3252,10 @@ The dseries class
.. dseriesmethod:: B = ydiff (A)
B = ygrowth (A)
ydiff_ (A)
ygrowth_ (A)
ydiff_ ()
ygrowth_ ()
|br| Computes yearly differences or growth rates.
|br| Calculates annual differences or growth rates.
.. _x13-members:
......
# -*- coding: utf-8 -*-
# Copyright © 2018-2019 Dynare Team
# Copyright © 2018-2024 Dynare Team
#
# This file is part of Dynare.
#
......@@ -80,9 +80,7 @@ class DynObject(ObjectDescription):
signode += addnodes.desc_name(name, name)
if self.has_arguments:
if not arglist:
signode += addnodes.desc_parameterlist()
else:
if arglist:
signode += addnodes.desc_addname(arglist,arglist)
return fullname, prefix
......@@ -99,7 +97,7 @@ class DynObject(ObjectDescription):
self.state_machine.reporter.warning(
'duplicate object description of %s, ' % fullname +
'other instance in ' +
self.env.doc2path(objects[fullname][0]),line=self.lineno)
str(self.env.doc2path(objects[fullname][0])),line=self.lineno)
objects[fullname] = (self.env.docname, self.objtype)
indextext = self.get_index_text(fullname,name_obj)
......@@ -244,7 +242,7 @@ class DynSimpleObject(ObjectDescription):
self.state_machine.reporter.warning(
'duplicate object description of %s, ' % fullname +
'other instance in ' +
self.env.doc2path(objects[fullname][0]), line=self.lineno)
str(self.env.doc2path(objects[fullname][0])), line=self.lineno)
objects[fullname] = self.env.docname, self.objtype
indextext = self.get_index_text(fullname,name_obj)
......
......@@ -60,7 +60,7 @@ class DynareLexer(RegexLexer):
"addSeries","addParagraph","addVspace","write","compile")
operators = (
"STEADY_STATE","EXPECTATION","var_expectation","pac_expectation")
"STEADY_STATE","EXPECTATION","var_expectation","pac_expectation","pac_target_nonstationary")
macro_dirs = (
"@#includepath", "@#include", "@#define", "@#if",
......@@ -83,7 +83,8 @@ class DynareLexer(RegexLexer):
'osr_params_bounds','ramsey_constraints','irf_calibration',
'moment_calibration','identification','svar_identification',
'matched_moments','occbin_constraints','surprise','overwrite','bind','relax',
'verbatim','end','node','cluster','paths','hooks'), prefix=r'\b', suffix=r'\s*\b'),Keyword.Reserved),
'verbatim','end','node','cluster','paths','hooks','target','pac_target_info','auxname_target_nonstationary',
'component', 'growth', 'auxname', 'kind'), prefix=r'\b', suffix=r'\s*\b'),Keyword.Reserved),
# FIXME: Commands following multiline comments are not highlighted properly.
(words(commands + report_commands,
......
function log_prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
% function prior_val=Gali_2015_prior_restrictions(M_, oo_, options_, dataset_, dataset_info);
function log_prior_val=Gali_2015_prior_restrictions(M_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, options_, dataset_, dataset_info);
% function prior_val=Gali_2015_prior_restrictions(M_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state, options_, dataset_, dataset_info);
% Example of a _prior_restrictions-file automatically called during
% estimation
% It imposes a prior of the slope of the New Keynesian Phillips Curve of
% 0.03. As the slope is a composite of other parameters with independent
% priors, a separate function is required to do this.
% Copyright © 2021 Dynare Team
% Copyright © 2021-2023 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -27,12 +27,16 @@
* conform with Dynare’s end of period stock notation, we use the
* predetermined_variables-command.
*
* The model has been implemented in detrended form, i.e. the \mu_{i,t} are actually
* the the growth rates of the original \mu_{i,t}^{orig} in the paper, i.e.
* log(\mu_{i,t})=log(\mu_{i,t}^{orig}/\mu_{i,t-1}^{orig})
*
* Please note that the following copyright notice only applies to this Dynare
* implementation of the model.
*/
/*
* Copyright © 2013-2020 Dynare Team
* Copyright © 2013-2023 Dynare Team
*
* This file is part of Dynare.
*
......@@ -151,12 +155,12 @@ gammmaPI =1.29;
PIbar = 1.01;
rhod = 0.12;
rhophi = 0.93;
sigma_A = -3.97;
sigma_d = -1.51;
sigma_A = exp(-3.97);
sigma_d = exp(-1.51);
sigma_phi =-2.36;
sigma_mu =-5.43;
sigma_m =-5.85;
sigma_phi =exp(-2.36);
sigma_mu =exp(-5.43);
sigma_m =exp(-5.85);
Lambdamu=3.4e-3;
LambdaA = 2.8e-3;
......@@ -214,7 +218,7 @@ mc=(1/(1-alppha))^(1-alppha)*(1/alppha)^alppha*w^(1-alppha)*r^alppha;
1=thetap*(PI(-1)^chi/PI)^(1-epsilon)+(1-thetap)*PIstar^(1-epsilon);
[name='Taylor Rule']
R/Rbar=(R(-1)/Rbar)^gammmaR*((PI/PIbar)^gammmaPI*((yd/yd(-1)*mu_z)/exp(LambdaYd))^gammmay)^(1-gammmaR)*exp(epsm);
R/Rbar=(R(-1)/Rbar)^gammmaR*((PI/PIbar)^gammmaPI*((yd/yd(-1)*mu_z)/exp(LambdaYd))^gammmay)^(1-gammmaR)*exp(sigma_m*epsm);
[name='Resource constraint']
yd=c+x+mu_z^(-1)*mu_I^(-1)*(gammma1*(u-1)+gammma2/2*(u-1)^2)*k;
......@@ -235,24 +239,24 @@ PIstarw=wstar/w;
//exogenous processes
[name='Preference Shock']
log(d)=rhod*log(d(-1))+epsd;
log(d)=rhod*log(d(-1))+sigma_d*epsd;
[name='Labor disutility Shock']
log(phi)=rhophi*log(phi(-1))+epsphi;
log(phi)=rhophi*log(phi(-1))+sigma_phi*epsphi;
[name='Investment specific technology']
log(mu_I)=Lambdamu+epsmu_I;
log(mu_I)=Lambdamu+sigma_mu*epsmu_I;
[name='Neutral technology']
log(mu_A)=LambdaA+epsA;
log(mu_A)=LambdaA+sigma_A*epsA;
[name='Defininition composite technology']
mu_z=mu_A^(1/(1-alppha))*mu_I^(alppha/(1-alppha));
end;
shocks;
var epsd; stderr exp(sigma_d);
var epsphi; stderr exp(sigma_phi);
var epsmu_I; stderr exp(sigma_mu);
var epsA; stderr exp(sigma_A);
var epsm; stderr exp(sigma_m);
var epsd; stderr 1;
var epsphi; stderr 1;
var epsmu_I; stderr 1;
var epsA; stderr 1;
var epsm; stderr 1;
end;
steady;
......
......@@ -15,7 +15,7 @@ function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
% - check [scalar] set to 0 if steady state computation worked and to
% 1 of not (allows to impose restrictions on parameters)
% Copyright © 2013-2020 Dynare Team
% Copyright © 2013-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -32,6 +32,10 @@ function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% make parameter explicitly known to Matlab to avoid naming conflicts; actual value is read out
% in next eval-loop
delta=0;
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
......@@ -52,8 +56,6 @@ u=1;
q=1;
d=1;
phi=1;
m=0;
zeta=1;
LambdaYd= (LambdaA+alppha*Lambdamu)/(1-alppha);
mu_z=exp(LambdaYd);
mu_I=exp(Lambdamu);
......
Assuming that the dynare++ binary is in your PATH, you can run the example by using the following command
in a Command Prompt Window:
... > dynare++ example1.mod
Please, read the manual (doc\dynare++\dynare++-tutorial.pdf) for a description of the generated output.
/*
* This Dynare++ mod-file implements the RBC model with time-to-build
* described in Kamenik (2011): "DSGE Models with Dynare++. A Tutorial."
* Note that Dynare++ uses the same stock-at-the-end-of-period timing convention
* as the regular Dynare
*/
var Y, C, K, A, H, B;
varexo EPS, NU;
parameters beta, rho, alpha, delta, theta, psi, tau;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 1/(1.03^0.25);
delta = 0.025;
psi = 0;
theta = 2.95;
model;
C*theta*H^(1+psi) = (1-alpha)*Y;
beta*exp(B)*C/exp(B(1))/C(1)*
(exp(B(1))*alpha*Y(1)/K(1)+1-delta) = 1;
Y = exp(A)*K^alpha*H^(1-alpha);
K = exp(B(-1))*(Y(-1)-C(-1)) + (1-delta)*K(-1);
A = rho*A(-1) + tau*B(-1) + EPS;
B = tau*A(-1) + rho*B(-1) + NU;
end;
initval;
A = 0;
B = 0;
H = ((1-alpha)/(theta*(1-(delta*alpha)/(1/beta-1+delta))))^(1/(1+psi));
Y = (alpha/(1/beta-1+delta))^(alpha/(1-alpha))*H;
K = alpha/(1/beta-1+delta)*Y;
C = Y - delta*K;
end;
vcov = [0.0002 0.00005;
0.00005 0.0001
];
order = 7;
\ No newline at end of file
......@@ -3,20 +3,20 @@
* in the paper) described in Frank Schorfheide (2000): "Loss function-based
* evaluation of DSGE models", Journal of Applied Econometrics, 15(6), 645-670.
*
* The data are in file "fsdat_simul.m", and have been artificially generated.
* They are therefore different from the original dataset used by Schorfheide.
* The data are taken from the replication package at
* http://dx.doi.org/10.15456/jae.2022314.0708799949
*
* The prior distribution follows the one originally specified in Schorfheide's
* paper, except for parameter rho. In the paper, the elicited beta prior for rho
* paper. Note that the elicited beta prior for rho in the paper
* implies an asymptote and corresponding prior mode at 0. It is generally
* recommended to avoid this extreme type of prior. Some optimizers, for instance
* mode_compute=12 (Mathworks' particleswarm algorithm) may find a posterior mode
* with rho equal to zero. We lowered the value of the prior standard deviation
* (changing .223 to .100) to remove the asymptote.
* recommended to avoid this extreme type of prior.
*
* Because the data are already logged and we use the loglinear option to conduct
* a full log-linearization, we need to use the logdata option.
*
* The equations are taken from J. Nason and T. Cogley (1994): "Testing the
* implications of long-run neutrality for monetary business cycle models",
* Journal of Applied Econometrics, 9, S37-S70.
* Journal of Applied Econometrics, 9, S37-S70, NC in the following.
* Note that there is an initial minus sign missing in equation (A1), p. S63.
*
* This implementation was originally written by Michel Juillard. Please note that the
......@@ -25,7 +25,7 @@
*/
/*
* Copyright © 2004-2017 Dynare Team
* Copyright © 2004-2023 Dynare Team
*
* This file is part of Dynare.
*
......@@ -43,33 +43,71 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/
var m P c e W R k d n l gy_obs gp_obs y dA;
varexo e_a e_m;
parameters alp bet gam mst rho psi del;
var m ${m}$ (long_name='money growth')
P ${P}$ (long_name='Price level')
c ${c}$ (long_name='consumption')
e ${e}$ (long_name='capital stock')
W ${W}$ (long_name='Wage rate')
R ${R}$ (long_name='interest rate')
k ${k}$ (long_name='capital stock')
d ${d}$ (long_name='dividends')
n ${n}$ (long_name='labor')
l ${l}$ (long_name='loans')
gy_obs ${\Delta \ln GDP}$ (long_name='detrended capital stock')
gp_obs ${\Delta \ln P}$ (long_name='detrended capital stock')
y ${y}$ (long_name='detrended output')
dA ${\Delta A}$ (long_name='TFP growth')
;
varexo e_a ${\epsilon_A}$ (long_name='TFP shock')
e_m ${\epsilon_M}$ (long_name='Money growth shock')
;
parameters alp ${\alpha}$ (long_name='capital share')
bet ${\beta}$ (long_name='discount factor')
gam ${\gamma}$ (long_name='long-run TFP growth')
logmst ${\log(m^*)}$ (long_name='long-run money growth')
rho ${\rho}$ (long_name='autocorrelation money growth')
phi ${\phi}$ (long_name='labor weight in consumption')
del ${\delta}$ (long_name='depreciation rate')
;
% roughly picked values to allow simulating the model before estimation
alp = 0.33;
bet = 0.99;
gam = 0.003;
mst = 1.011;
logmst = log(1.011);
rho = 0.7;
psi = 0.787;
phi = 0.787;
del = 0.02;
model;
[name='NC before eq. (1), TFP growth equation']
dA = exp(gam+e_a);
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
[name='NC eq. (2), money growth rate']
log(m) = (1-rho)*logmst + rho*log(m(-1))+e_m;
[name='NC eq. (A1), Euler equation']
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
[name='NC below eq. (A1), firm borrowing constraint']
W = l/n;
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
[name='NC eq. (A2), intratemporal labour market condition']
-(phi/(1-phi))*(c*P/(1-n))+l/n = 0;
[name='NC below eq. (A2), credit market clearing']
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
[name='NC eq. (A3), credit market optimality']
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
[name='NC eq. (18), aggregate resource constraint']
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
[name='NC eq. (19), money market condition']
P*c = m;
[name='NC eq. (20), credit market equilibrium condition']
m-1+d = l;
[name='Definition TFP shock']
e = exp(e_a);
[name='Implied by NC eq. (18), production function']
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
[name='Observation equation GDP growth']
gy_obs = dA*y/y(-1);
[name='Observation equation price level']
gp_obs = (P/P(-1))*m(-1)/dA;
end;
......@@ -81,19 +119,19 @@ end;
steady_state_model;
dA = exp(gam);
gst = 1/dA;
m = mst;
m = exp(logmst);
khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/m )^(-1);
nust = phi*m^2/( (1-alp)*(1-phi)*bet*gst^alp*khst^alp );
n = xist/(nust+xist);
P = xist + nust;
k = khst*n;
l = psi*mst*n/( (1-psi)*(1-n) );
c = mst/P;
d = l - mst + 1;
l = phi*m*n/( (1-phi)*(1-n) );
c = m/P;
d = l - m + 1;
y = k^alp*n^(1-alp)*gst^alp;
R = mst/bet;
R = m/bet;
W = l/n;
ist = y-c;
q = 1 - d;
......@@ -104,17 +142,18 @@ steady_state_model;
gy_obs = dA;
end;
steady;
steady;
check;
% Table 1 of Schorfheide (2000)
estimated_params;
alp, beta_pdf, 0.356, 0.02;
bet, beta_pdf, 0.993, 0.002;
gam, normal_pdf, 0.0085, 0.003;
mst, normal_pdf, 1.0002, 0.007;
rho, beta_pdf, 0.129, 0.100;
psi, beta_pdf, 0.65, 0.05;
logmst, normal_pdf, 0.0002, 0.007;
rho, beta_pdf, 0.129, 0.223;
phi, beta_pdf, 0.65, 0.05;
del, beta_pdf, 0.01, 0.005;
stderr e_a, inv_gamma_pdf, 0.035449, inf;
stderr e_m, inv_gamma_pdf, 0.008862, inf;
......@@ -122,14 +161,8 @@ end;
varobs gp_obs gy_obs;
estimation(order=1, datafile=fsdat_simul, nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8, mode_check);
/*
* The following lines were used to generate the data file. If you want to
* generate another random data file, comment the "estimation" line and uncomment
* the following lines.
*/
estimation(order=1, datafile=fs2000_data, loglinear,logdata, mode_compute=4, mh_replic=20000, nodiagnostic, mh_nblocks=2, mh_jscale=0.8, mode_check);
//stoch_simul(periods=200, order=1);
//datatomfile('fsdat_simul', {'gy_obs', 'gp_obs'});
%uncomment the following lines to generate LaTeX-code of the model equations
%write_latex_original_model(write_equation_tags);
%collect_latex_files;
%This file is a direct Matlab implementation of the loaddata.g and data.prn files
%of Schorfheide, Frank (2000): Loss function-based evaluation of DSGE models
%(replication data). Version: 1. Journal of Applied Econometrics. Dataset.
%http://dx.doi.org/10.15456/jae.2022314.0708799949
% Copyright: 2000-2022 Frank Schorfheide
% Copyright: 2023 Dynare Team
% License: CC BY 4.0
% (https://creativecommons.org/licenses/by/4.0/legalcode)
% Time series, extracted 05/04/00
% columms are quarterly data from 1949:IV to 1997:IV
% 1: GDPD = GROSS DOMESTIC PRODUCT:IMPLICIT PRICE DEFLATOR (INDEX,92=100)(T7.1)
% 2: GDPQ = GROSS DOMESTIC PRODUCT
% 3: GPOP = POPULATION, NIPA basis (THOUS.,NSA)
data_q=[18.02 1474.5 150.2
17.94 1538.2 150.9
18.01 1584.5 151.4
18.42 1644.1 152
18.73 1678.6 152.7
19.46 1693.1 153.3
19.55 1724 153.9
19.56 1758.2 154.7
19.79 1760.6 155.4
19.77 1779.2 156
19.82 1778.8 156.6
20.03 1790.9 157.3
20.12 1846 158
20.1 1882.6 158.6
20.14 1897.3 159.2
20.22 1887.4 160
20.27 1858.2 160.7
20.34 1849.9 161.4
20.39 1848.5 162
20.42 1868.9 162.8
20.47 1905.6 163.6
20.56 1959.6 164.3
20.62 1994.4 164.9
20.78 2020.1 165.7
21 2030.5 166.5
21.2 2023.6 167.2
21.33 2037.7 167.9
21.62 2033.4 168.7
21.71 2066.2 169.5
22.01 2077.5 170.2
22.15 2071.9 170.9
22.27 2094 171.7
22.29 2070.8 172.5
22.56 2012.6 173.1
22.64 2024.7 173.8
22.77 2072.3 174.5
22.88 2120.6 175.3
22.92 2165 176.045
22.91 2223.3 176.727
22.94 2221.4 177.481
23.03 2230.95 178.268
23.13 2279.22 179.694
23.22 2265.48 180.335
23.32 2268.29 181.094
23.4 2238.57 181.915
23.45 2251.68 182.634
23.51 2292.02 183.337
23.56 2332.61 184.103
23.63 2381.01 184.894
23.75 2422.59 185.553
23.81 2448.01 186.203
23.87 2471.86 186.926
23.94 2476.67 187.68
24 2508.7 188.299
24.07 2538.05 188.906
24.12 2586.26 189.631
24.29 2604.62 190.362
24.35 2666.69 190.954
24.41 2697.54 191.56
24.52 2729.63 192.256
24.64 2739.75 192.938
24.77 2808.88 193.467
24.88 2846.34 193.994
25.01 2898.79 194.647
25.17 2970.48 195.279
25.32 3042.35 195.763
25.53 3055.53 196.277
25.79 3076.51 196.877
26.02 3102.36 197.481
26.14 3127.15 197.967
26.31 3129.53 198.455
26.6 3154.19 199.012
26.9 3177.98 199.572
27.21 3236.18 199.995
27.49 3292.07 200.452
27.75 3316.11 200.997
28.12 3331.22 201.538
28.39 3381.86 201.955
28.73 3390.23 202.419
29.14 3409.65 202.986
29.51 3392.6 203.584
29.94 3386.49 204.086
30.36 3391.61 204.721
30.61 3422.95 205.419
31.02 3389.36 206.13
31.5 3481.4 206.763
31.93 3500.95 207.362
32.27 3523.8 208
32.54 3533.79 208.642
33.02 3604.73 209.142
33.2 3687.9 209.637
33.49 3726.18 210.181
33.95 3790.44 210.737
34.36 3892.22 211.192
34.94 3919.01 211.663
35.61 3907.08 212.191
36.29 3947.11 212.708
37.01 3908.15 213.144
37.79 3922.57 213.602
38.96 3879.98 214.147
40.13 3854.13 214.7
41.05 3800.93 215.135
41.66 3835.21 215.652
42.41 3907.02 216.289
43.19 3952.48 216.848
43.69 4044.59 217.314
44.15 4072.19 217.776
44.77 4088.49 218.338
45.57 4126.39 218.917
46.32 4176.28 219.427
47.07 4260.08 219.956
47.66 4329.46 220.573
48.63 4328.33 221.201
49.42 4345.51 221.719
50.41 4510.73 222.281
51.27 4552.14 222.933
52.35 4603.65 223.583
53.51 4605.65 224.152
54.65 4615.64 224.737
55.82 4644.93 225.418
56.92 4656.23 226.117
58.18 4678.96 226.754
59.55 4566.62 227.389
61.01 4562.25 228.07
62.59 4651.86 228.689
64.15 4739.16 229.155
65.37 4696.82 229.674
66.65 4753.02 230.301
67.87 4693.76 230.903
68.86 4615.89 231.395
69.72 4634.88 231.906
70.66 4612.08 232.498
71.44 4618.26 233.074
72.08 4662.97 233.546
72.83 4763.57 234.028
73.48 4849 234.603
74.19 4939.23 235.153
75.02 5053.56 235.605
75.58 5132.87 236.082
76.25 5170.34 236.657
76.81 5203.68 237.232
77.63 5257.26 237.673
78.25 5283.73 238.176
78.76 5359.6 238.789
79.45 5393.57 239.387
79.81 5460.83 239.861
80.22 5466.95 240.368
80.84 5496.29 240.962
81.45 5526.77 241.539
82.09 5561.8 242.009
82.68 5618 242.52
83.33 5667.39 243.12
84.09 5750.57 243.721
84.67 5785.29 244.208
85.56 5844.05 244.716
86.66 5878.7 245.354
87.44 5952.83 245.966
88.45 6010.96 246.46
89.39 6055.61 247.017
90.13 6087.96 247.698
90.88 6093.51 248.374
92 6152.59 248.928
93.18 6171.57 249.564
94.14 6142.1 250.299
95.11 6078.96 251.031
96.27 6047.49 251.65
97 6074.66 252.295
97.7 6090.14 253.033
98.31 6105.25 253.743
99.13 6175.69 254.338
99.79 6214.22 255.032
100.17 6260.74 255.815
100.88 6327.12 256.543
101.84 6327.93 257.151
102.35 6359.9 257.785
102.83 6393.5 258.516
103.51 6476.86 259.191
104.13 6524.5 259.738
104.71 6600.31 260.351
105.39 6629.47 261.04
106.09 6688.61 261.692
106.75 6717.46 262.236
107.24 6724.2 262.847
107.75 6779.53 263.527
108.29 6825.8 264.169
108.91 6882 264.681
109.24 6983.91 265.258
109.74 7020 265.887
110.23 7093.12 266.491
111 7166.68 266.987
111.43 7236.5 267.545
111.76 7311.24 268.171
112.08 7364.63 268.815];
%Compute growth rates: from 1950:I to 1997:IV
gy_obs=1000*data_q(:,2)./data_q(:,3); %real GDP per capita
gy_obs=diff(log(gy_obs));
gp_obs = diff(log(data_q(:,1))); %GDP deflator inflation
// --+ options: json=compute, stochastic +--
var y x z v;
varexo ex ey ez ;
parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters
parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters
a_y_1 = .2;
a_y_2 = .3;
b_y_1 = .1;
b_y_2 = .4;
b_x_1 = -.1;
b_x_2 = -.2;
d_y = .5;
beta = .9;
e_c_m = .1;
c_z_1 = .7;
c_z_2 = -.3;
var_model(model_name=toto, eqtags=['eq:x', 'eq:y']);
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
pac_target_info(pacman);
target v;
auxname_target_nonstationary vns;
component y;
auxname pv_y_;
kind ll;
component x;
growth diff(x(-1));
auxname pv_dx_;
kind dd;
end;
model;
[name='eq:y']
y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ;
[name='eq:x']
diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ;
[name='eq:v']
v = x + d_y*y ; // Composite target, no residuals here only variables defined in the auxiliary VAR model.
[name='zpac']
diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
end;
shocks;
var ex = .10;
var ey = .15;
var ez = .05;
end;
// Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
pac.initialize('pacman');
// Update the parameters of the PAC expectation model (h0 and h1 vectors).
pac.update.expectation('pacman');
/*
**
** Simulate artificial dataset
**
*/
// Set initial conditions to zero.
initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
// Simulate the model for 5000 periods
TrueData = simul_backward_model(initialconditions, 5000);
/*
**
** Estimate PAC equation (using the artificial data)
**
*/
// Provide initial conditions for the estimated parameters
clear eparams
eparams.e_c_m = .9;
eparams.c_z_1 = .5;
eparams.c_z_2 = .2;
edata = TrueData; // Set the dataset used for estimation
edata.ez = dseries(NaN, 2000Q1); // Remove residuals for the PAC equation from the database.
pac.estimate.nls('zpac', eparams, edata, 2005Q1:2005Q1+4000, 'fmincon'); // Should produce a table with the estimates (close to the calibration given in lines 21-23)
/*
* This file presents a baseline RBC model with government spending shocks where the persistence of the
* government spending shock is estimated via impulse response function (IRF) matching.
*
* Notes:
* - The empirical IRFs were estimated using the Blanchard/Perotti (2002) approach, see
* https://github.com/JohannesPfeifer/DSGE_mod/blob/master/RBC_IRF_matching/get_empirical_IRFs.m
* - They are given in the csv file rbc_irf_matching_data.csv, the first two columns contain
* the empirical IRFs of G and Y, while the third and fourth column contain the corresponding
* variances of the IRFs from a bootstrap approach.
* Importantly: this mod file does not show how to get the empirical IRFs from a SVAR model,
* but takes these as "data".
* - Of course the RBC model is not capable of generating the consumption increase
* after a government spending shock. For that reason, this mod-file only targets the IRFs for G and Y.
* - The weighting matrix uses a diagonal matrix with the inverse of the pointwise IRF variances on the main diagonal.
* - The empirical IRFs and model IRFs use an impulse size of 1 percent. Thus, there is no uncertainty about the
* initial impact. The IRF matching therefore only targets the G-response starting in the second period.
* - Note that for the current model, the number of IRFs exceeds the number of VAR parameters. Therefore,
* the distribution of the estimator will be non-standard, see Guerron-Quintana/Inoue/Kilian (2016),
* http://dx.doi.org/10.1016/j.jeconom.2016.09.009
* - The mod-file also shows how to estimate an AR(2)-process by working with the roots of the autoregressive
* process instead of the coefficients. This allows for easily restricting the process to the stability region and
* would allow specifying e.g. a beta prior for both roots as was done in Born/Peter/Pfeifer (2013), Fiscal news
* and macroeconomic volatility, https://doi.org/10.1016/j.jedc.2013.06.011
*
* Please note that the following copyright notice only applies to this Dynare
* implementation of the model.
*/
/*
* Copyright (C) 2016-17 Johannes Pfeifer,
* Copyright (C) 2024 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/
%----------------------------------------------------------------
% define variables
%----------------------------------------------------------------
@#define IRF_periods=80
var y ${y}$ (long_name='output')
c ${c}$ (long_name='consumption')
k ${k}$ (long_name='capital')
l ${l}$ (long_name='hours')
z ${z}$ (long_name='TFP')
ghat ${\hat g}$ (long_name='government spending')
r ${r}$ (long_name='annualized interest rate')
w ${w}$ (long_name='real wage')
invest ${i}$ (long_name='investment')
log_y ${\log(y)}$ (long_name='log output')
log_k ${\log(k)}$ (long_name='log capital stock')
log_c ${\log(c)}$ (long_name='log consumption')
log_l ${\log(l)}$ (long_name='log labor')
log_w ${\log(w)}$ (long_name='log real wage')
log_invest ${\log(i)}$ (long_name='log investment')
;
varexo eps_z ${\varepsilon_z}$ (long_name='TFP shock')
eps_g ${\varepsilon_g}$ (long_name='government spending shock')
;
%----------------------------------------------------------------
% define parameters
%----------------------------------------------------------------
parameters
beta ${\beta}$ (long_name='discount factor')
psi ${\psi}$ (long_name='labor disutility parameter')
sigma ${\sigma}$ (long_name='risk aversion')
delta ${\delta}$ (long_name='depreciation rate')
alpha ${\alpha}$ (long_name='capital share')
rhoz ${\rho_z}$ (long_name='persistence TFP shock')
root_g_1 ${\rho_g}$ (long_name='first root of AR(2) G process')
root_g_2 ${\rho_g}$ (long_name='second root of AR(2) G process')
gammax ${\gamma_x}$ (long_name='composite growth rate')
gshare ${\frac{G}{Y}}$ (long_name='government spending share')
n ${n}$ (long_name='population growth')
x ${x}$ (long_name='technology growth (per capita output growth)')
i_y ${\frac{I}{Y}}$ (long_name='investment-output ratio')
k_y ${\frac{K}{Y}}$ (long_name='capital-output ratio')
g_ss ${\bar G}$ (long_name='government spending in steady state')
l_ss ${\bar L}$ (long_name='labor in steady state')
;
%----------------------------------------------------------------
% model equations
%----------------------------------------------------------------
model;
# rho_g_1= (root_g_1+root_g_2);
# rho_g_2= - root_g_1*root_g_2;
[name='Euler equation']
c^(-sigma)=beta/gammax*c(+1)^(-sigma)*
(alpha*exp(z(+1))*(k/l(+1))^(alpha-1)+(1-delta));
[name='Labor FOC']
psi*c^sigma*1/(1-l)=w;
[name='Law of motion capital']
gammax*k=(1-delta)*k(-1)+invest;
[name='resource constraint']
y=invest+c+g_ss*exp(ghat);
[name='production function']
y=exp(z)*k(-1)^alpha*l^(1-alpha);
[name='real wage/firm FOC labor']
w=(1-alpha)*y/l;
[name='annualized real interst rate/firm FOC capital']
r=4*alpha*y/k(-1);
[name='exogenous TFP process']
z=rhoz*z(-1)+eps_z;
[name='government spending process']
ghat=rho_g_1*ghat(-1)+rho_g_2*ghat(-2)+eps_g;
[name='Definition log output']
log_y = log(y);
[name='Definition log capital']
log_k = log(k);
[name='Definition log consumption']
log_c = log(c);
[name='Definition log hours']
log_l = log(l);
[name='Definition log wage']
log_w = log(w);
[name='Definition log investment']
log_invest = log(invest);
end;
%----------------------------------------------------------------
% set steady state values
%---------------------------------------------------------------
steady_state_model;
gammax = (1+n)*(1+x);
delta = i_y/k_y-x-n-n*x;
beta = (1+x)*(1+n)/(alpha/k_y+(1-delta));
l = l_ss;
k = ((1/beta*(1+n)*(1+x)-(1-delta))/alpha)^(1/(alpha-1))*l;
invest = (x+n+delta+n*x)*k;
y = k^alpha*l^(1-alpha);
g = gshare*y;
g_ss = g;
c = (1-gshare)*k^(alpha)*l^(1-alpha)-invest;
psi = (1-alpha)*(k/l)^alpha*(1-l)/c^sigma;
w = (1-alpha)*y/l;
r = 4*alpha*y/k;
log_y = log(y);
log_k = log(k);
log_c = log(c);
log_l = log(l);
log_w = log(w);
log_invest = log(invest);
z = 0;
ghat =0;
end;
%----------------------------------------------------------------
% calibration
%----------------------------------------------------------------
sigma = 1;
alpha = 0.33;
i_y = 0.25;
k_y = 10.4;
x = 0.0055;
n = 0.0027;
rhoz = 0.97;
root_g_1 = 0.9602;
root_g_2 = 0;
gshare = 0.2038;
l_ss = 1/3;
shocks;
var eps_g = 1;
end;
steady;
check;
varobs ghat log_y y; // you need to specify observables
%----------------------------------------------------------------
% IRF matching example 1:
% - different ways to MANUALLY enter values and weights
% - Maximum likelihood estimation
%----------------------------------------------------------------
estimated_params;
root_g_1 , 0.90 , 0, 1;
root_g_2 , 0.10 , 0, 1;
end;
xx = [1.007,1.117,1.092];
ww = [51,52];
matched_irfs;
var log_y ; varexo eps_g ; periods 1, 2 ; values 0.20, 0.17 ; weights 360, 140 ;
var ghat ; varexo eps_g ; periods 2 3:5 ; values 1.01, (xx) ; weights 50, 20 ;
var y ; varexo eps_g ; periods 10:11 ; values (log(1.05)) ; weights (ww) ;
end;
method_of_moments(mom_method = irf_matching, mode_compute = 5, additional_optimizer_steps=[4]);
%----------------------------------------------------------------
% IRF matching example 2
% - use all IRFs given in MATLAB objects
% - use Bayesian Slice sampler
%----------------------------------------------------------------
estimated_params(overwrite);
root_g_1 , 0.50 , 0, 1, beta_pdf , 0.50 , 0.20;
root_g_2 , 0.10 , 0, 1, beta_pdf , 0.50 , 0.20;
end;
% get data
irfs_data = importdata('rbc_irf_matching_data.csv');
irfs_ghat_eps_g = irfs_data.data(2:80,1); % start in t=2 due to identification restrictions in SVAR
irfs_log_y_eps_g = irfs_data.data(1:80,2);
weights_ghat_eps_g = 1./irfs_data.data(2:80,3);
weights_log_y_eps_g = 1./irfs_data.data(1:80,4);
matched_irfs(overwrite);
var ghat ; varexo eps_g; periods 2:80; values (irfs_ghat_eps_g); weights (weights_ghat_eps_g);
var log_y; varexo eps_g; periods 1:80; values (irfs_log_y_eps_g); weights (weights_log_y_eps_g);
end;
method_of_moments(mom_method = irf_matching
,order = 1
,mh_nblocks = 2, mh_replic = 50
,posterior_sampling_method = 'slice'
,plot_priors = 1
);
%----------------------------------------------------------------
% IRF matching example 3:
% - use anonymous function to access IRFs more flexibly
% - showcase how to use irf_matching_file
% - find posterior mode
%----------------------------------------------------------------
% get data
irfs_data = importdata('rbc_irf_matching_data.csv');
% use anonymous function (or MATLAB function) to have more flexibility, but inputs can only be numerical
% we also take 100 just for illustration that you can do any required transformation in an irf_matching_file
irfs_vals = @(j) 100.*(irfs_data.data(2:80,j));
irfs_weights = @(j) 1./(irfs_data.data(2:80,j));
matched_irfs(overwrite);
var ghat ; varexo eps_g; periods 2:80; values (irfs_vals(1)); weights (irfs_weights(3));
var log_y; varexo eps_g; periods 2:80; values (irfs_vals(2)); weights (irfs_weights(4));
end;
% we use the irf_matching_file to transform variable y to log(y) so the model
% variable aligns with the variable from the given empirical SVAR
method_of_moments(mom_method = irf_matching
,irf_matching_file = rbc_irf_matching_transformations
,mh_replic = 0,plot_priors = 0
);
\ No newline at end of file
G,Y,var_G,var_Y
1,0.208070478344545,1.12054105855257e-33,0.0027602236508546
1.01463693816715,0.166450236530301,0.00583152879723266,0.00679133276154495
1.00764238152471,0.230433660500946,0.0111184998994349,0.00952654639548326
1.11696510115769,0.215252336067127,0.0164663222282161,0.0113464752654877
1.09223998892147,0.222958847463141,0.0216966728235886,0.013533420700953
1.03736643322521,0.243972174559692,0.0257004687001329,0.0151053406229588
1.01711112212948,0.261016995864984,0.0303544421773506,0.0162405771811019
0.967577038730636,0.269060130173636,0.0339076793971577,0.0171352445593892
0.912649802559854,0.278584624341349,0.03620212016322,0.0179592573395723
0.867058516612021,0.283001682449059,0.038151205713992,0.0187783728830758
0.820597806619289,0.283598412003388,0.0396511019185971,0.0194594651103199
0.77563492323912,0.281760898055785,0.0403347277351183,0.0198713886600475
0.735846344956036,0.277110769410598,0.0407036832985301,0.0198800923047385
0.698850036380633,0.269931336693529,0.0407917065478011,0.0194569744071588
0.664596916513962,0.261143278620547,0.0405012612908696,0.0186271529903141
0.633528960929983,0.251064751428521,0.0400022455114944,0.0174559567202935
0.604912703413876,0.240132445806634,0.0393594337883548,0.0160603819816583
0.578360605178466,0.228823340604282,0.0385445703756185,0.0145721875285327
0.55371549942988,0.217458827167635,0.0376075435183867,0.0130962012473614
0.530621264922238,0.206298301306342,0.0365729915386994,0.0117094186557471
0.508813730835084,0.195562831928213,0.0354403165776896,0.010461528435305
0.488125279535286,0.185390333897221,0.0342268285355491,0.00937102041748079
0.468386758403429,0.175863201796663,0.0329491563166573,0.00843340667968603
0.449471041462416,0.167022878990409,0.0316223984500399,0.00763260719022832
0.431296406103216,0.158870322365946,0.0302644814355948,0.00694575471751527
0.413799596231625,0.151377829877172,0.0288934660918837,0.00634988691182681
0.396937751823371,0.144499570770831,0.0275270293690654,0.00582564616104379
0.380685985677042,0.13817717429653,0.0261806418593218,0.00535836547483349
0.365028340579903,0.132346351995696,0.0248665732796567,0.00493799567463183
0.349954881191496,0.126942318129237,0.0235951459469029,0.0045584177486503
0.335459383987806,0.121903145354258,0.022373467574597,0.00421578980579863
0.321536118675061,0.117172332783573,0.021205727363848,0.00390754150917342
0.308178316488601,0.112700463782387,0.0200943664605458,0.00363147379277453
0.295377351869768,0.108445858384018,0.019040123479836,0.00338513596160304
0.283122066100135,0.104374632848495,0.0180423053448312,0.00316565728079348
0.271398650164465,0.100460305211796,0.0170995738403303,0.0029698495549103
0.260190863606074,0.0966830386847356,0.0162100638803249,0.00279435029276752
0.249480370591311,0.0930286987898092,0.0153715252985084,0.00263589300567087
0.239247213436084,0.0894878338463341,0.0145815957210218,0.002491545439791
0.229470346306504,0.0860546497623421,0.0138378615720872,0.00235884935269597
0.220128148976686,0.0827260491927552,0.0131378639605267,0.00223588384965084
0.211198902955524,0.0795007779016462,0.0124791808709379,0.00212125323555392
0.20266120682353,0.0763786992809964,0.0118594333328108,0.0020139945677632
0.194494311443246,0.0733602078340912,0.0112762767066973,0.00191345670528973
0.186678374172779,0.0704457804639186,0.0107274179119509,0.0018191767154505
0.179194635081175,0.0676356552603192,0.0102106211287206,0.00173077210770515
0.172025520775263,0.064929622999291,0.00972370794405955,0.0016478667536602
0.165154686254735,0.0623269135604257,0.00926457432688479,0.00157005669764952
0.158567006362608,0.0598261581740075,0.00883120737460965,0.00149690646906453
0.152248528236286,0.0574254089705774,0.00842170119327602,0.00142796690804853
0.146186396016794,0.0551221987689224,0.00803427530290723,0.0013628024472437
0.140368757967879,0.0529136261066764,0.00766728912012237,0.00130101642649392
0.134784664597338,0.0507964530245216,0.00731924890008266,0.00124226770384004
0.129423964825334,0.0487672057100314,0.00698880917814805,0.00118627695274624
0.124277205618631,0.046822270602385,0.00667476765058639,0.00113282353216918
0.119335538941298,0.0449579808540134,0.0063760543634253,0.0010817364372413
0.11459063850232,0.0431706900378893,0.00609171803409054,0.00103288330782315
0.110034627608638,0.0414568316344016,0.00582091131964085,0.000986160390158817
0.105660018476945,0.0398129641266707,0.00556287623442419,0.000941484872060258
0.101459662633845,0.0382358024894679,0.00531693108962639,0.000898789756847698
0.0974267115198392,0.0367222375053657,0.00508245926485931,0.000858020371449084
0.0935545860830807,0.0352693447261226,0.00485889955647229,0.000819131356725285
0.0898369539782651,0.0338743850644921,0.00464573784815541,0.00078208329876107
0.0862677129419094,0.0325347989994978,0.00444249975285543,0.000746838714885712
0.0828409789666302,0.0312481962526895,0.00424874389794858,0.000713357679487274
0.0795510780159448,0.0300123425850257,0.00406405581698042,0.000681593780987298
0.076392540182423,0.0288251451088667,0.00388804253930626,0.000651491166504331
0.0733600953745436,0.0276846372357925,0.00372032800246882,0.000622983230006533
0.070448669804769,0.0265889641106603,0.00356054943074244,0.000595993138422716
0.0676533827305797,0.0255363691313685,0.0034083547518209,0.00057043599416774
0.064969543062731,0.024525181932661,0.00326340099829315,0.00054622212266834
0.0623926455954874,0.0235538080267355,0.00312535355830137,0.000523260827093126
0.0599183667294525,0.0226207201454146,0.00299388608378455,0.000501463968548093
0.0575425596484649,0.0217244512173301,0.00286868083997892,0.000480748874949654
0.055261248979131,0.0208635888360229,0.00274942930127684,0.000461040295246497
0.0530706250072852,0.0200367710268393,0.00263583284298659,0.000442271333040507
0.0509670375530574,0.0192426830970757,0.00252760342283966,0.000424383467067322
0.0489469896186406,0.0184800553498327,0.00242446418777184,0.000407325873359123
0.0470071309236527,0.0177476614525368,0.0023261499716701,0.000391054302991331
0.0451442514353558,0.0170443172715253,0.00223240766511842,0.000375529754828271
function [modelIrf, error_indicator] = rbc_irf_matching_transformations(modelIrf, M_, options_mom_, ys_)
% -------------------------------------------------------------------------
% This file manipulates model IRFs to be consistent with empirical IRFS
% -------------------------------------------------------------------------
% INPUTS
% - modelIrf: [options_mom_.irf by M_.endo_nbr by M_.exo_nbr]
% array of IRFs for all model variables and all shocks
% - M_: [structure] Dynare model structure
% - options_mom_: [structure] Dynare options structure
% - ys_: [double] steady state values of all endogenous variables
% -------------------------------------------------------------------------
% OUTPUTS
% - modelIrf: [options_mom_.irf by M_.endo_nbr by M_.exo_nbr]
% modified array of IRFs for all model variables and all shocks
% - error_indicator: [boolean] indicator of success (0) or failure (1)
% -------------------------------------------------------------------------
% This function is called by
% - mom.run
% -------------------------------------------------------------------------
% Copyright © 2024 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
% initialize error indicator
error_indicator = 0;
% get indices of variables
idx_ghat = find(ismember(M_.endo_names,'ghat'));
idx_log_y = find(ismember(M_.endo_names,'log_y'));
idx_eps_g = find(ismember(M_.exo_names,'eps_g'));
% manipulate the model IRFs to match the empirical IRFs (e.g. cumsum, common scaling, trends, ratios, etc.)
modelIrf(:,idx_ghat,idx_eps_g) = 100.*modelIrf(:,idx_ghat,idx_eps_g);
modelIrf(:,idx_log_y,idx_eps_g) = 100.*modelIrf(:,idx_log_y,idx_eps_g);
end
\ No newline at end of file
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Dynare
Upstream-Contact: Dynare Team, whose members in 2023 are:
Upstream-Contact: Dynare Team, whose members in 2025 are:
- Stéphane Adjemian <stephane.adjemian@univ-lemans.fr>
- Michel Juillard <michel.juillard@mjui.fr>
- Frédéric Karamé <frederic.karame@univ-lemans.fr>
......@@ -23,7 +23,7 @@ Upstream-Contact: Dynare Team, whose members in 2023 are:
Source: https://www.dynare.org
Files: *
Copyright: 1996-2023 Dynare Team
Copyright: 1996-2025 Dynare Team
License: GPL-3+
Files: matlab/+occbin/IVF_core.m
......@@ -64,7 +64,7 @@ License: public-domain-occbin
dynamic models with occasionally binding constraints easily"
Journal of Monetary Economics 70, 22-38
Files: matlab/AIM/SP*
Files: matlab/AIM/*
Copyright: none
License: public-domain-aim
This code is in the public domain and may be used freely.
......@@ -86,18 +86,18 @@ License: public-domain-aim
Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3,
pages 472-489
Files: matlab/optimization/bfgsi1.m matlab/csolve.m matlab/optimization/csminit1.m matlab/optimization/numgrad2.m
Files: matlab/optimization/bfgsi1.m matlab/optimization/csolve.m matlab/optimization/csminit1.m matlab/optimization/numgrad2.m
matlab/optimization/numgrad3.m matlab/optimization/numgrad3_.m matlab/optimization/numgrad5.m
matlab/optimization/numgrad5_.m matlab/optimization/csminwel1.m matlab/+bvar/density.m
matlab/+bvar/toolbox.m matlab/partial_information/PI_gensys.m matlab/partial_information/qzswitch.m
matlab/partial_information/qzdiv.m
matlab/+bvar/toolbox.m matlab/partial_information/PI_gensys.m matlab/partial_information/PI_qzswitch.m
matlab/partial_information/PI_qzdiv.m
Copyright: 1993-2009 Christopher Sims
2006-2023 Dynare Team
2006-2024 Dynare Team
License: GPL-3+
Files: matlab/optimization/cmaes.m
Copyright: 2001-2012 Nikolaus Hansen
2012-2017 Dynare Team
2012-2023 Dynare Team
License: GPL-3+
Files: matlab/optimization/solvopt.m
......@@ -113,22 +113,31 @@ Copyright: 1995 E.G.Tsionas
2015-2017 Dynare Team
License: GPL-3+
Files: matlab/endogenous_prior.m
Files: matlab/estimation/endogenous_prior.m
Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin
2013-2017 Dynare Team
License: GPL-3+
Files: matlab/estimation/smc/logsumexp.m
Copyright: 2020 Nicholas J. Higham
License: BSD-2-clause
Files: matlab/one_sided_hp_filter.m
Copyright: 2010-2015 Alexander Meyer-Gohde
2015-2017 Dynare Team
License: GPL-3+
Files: matlab/collapse_figures_in_tabgroup.m
Copyright: 2023 Eduard Benet Cerda
2024 Dynare Team
License: GPL-3+
Files: matlab/convergence_diagnostics/raftery_lewis.m
Copyright: 2016 Benjamin Born and Johannes Pfeifer
2016-2017 Dynare Team
License: GPL-3+
Files: matlab/commutation.m matlab/duplication.m
Files: matlab/+pruned_SS/commutation.m matlab/+pruned_SS/duplication.m
Copyright: 1997 Tom Minka <minka@microsoft.com>
2019-2020 Dynare Team
License: GPL-3+
......@@ -141,7 +150,7 @@ Comment: The original author gave authorization to change
the license from BSD-2-clause to GPL-3+ and redistribute
it under GPL-3+ with Dynare.
Files: matlab/uperm.m
Files: matlab/+pruned_SS/uperm.m
Copyright: 2014 Bruno Luong <brunoluong@yahoo.com>
2020 Dynare Team
License: GPL-3+
......@@ -149,9 +158,9 @@ Comment: The original author gave authorization to change
the license from BSD-2-clause to GPL-3+ and redistribute
it under GPL-3+ with Dynare.
Files: matlab/prodmom.m matlab/bivmom.m
Files: matlab/+pruned_SS/prodmom.m matlab/+pruned_SS/bivmom.m
Copyright: 2008-2015 Raymond Kan <kan@chass.utoronto.ca>
2019-2020 Dynare Team
2019-2023 Dynare Team
License: GPL-3+
Comment: The author gave authorization to redistribute
these functions under GPL-3+ with Dynare and would
......@@ -161,57 +170,37 @@ Comment: The author gave authorization to redistribute
Journal of Multivariate Analysis, 2008, vol. 99, issue 3,
pages 542-554.
Files: matlab/gsa/Morris_Measure_Groups.m
matlab/gsa/Sampling_Function_2.m
Files: matlab/+gsa/Morris_Measure_Groups.m
matlab/+gsa/Sampling_Function_2.m
Copyright: 2005 European Commission
2012-2017 Dynare Team
2012-2023 Dynare Team
License: GPL-3+
Comment: Written by Jessica Cariboni and Francesca Campolongo
Joint Research Centre, The European Commission,
Files: matlab/gsa/cumplot.m
matlab/gsa/filt_mc_.m
matlab/gsa/gsa_plotmatrix.m
matlab/gsa/gsa_skewness.m
matlab/gsa/gsa_speed.m
matlab/gsa/log_trans_.m
matlab/gsa/map_calibration.m
matlab/gsa/map_ident_.m
matlab/gsa/mcf_analysis.m
matlab/gsa/myboxplot.m
matlab/gsa/myprctilecol.m
matlab/gsa/prior_draw_gsa.m
matlab/gsa/read_data.m
matlab/gsa/redform_map.m
matlab/gsa/redform_screen.m
matlab/gsa/scatter_mcf.m
matlab/gsa/smirnov.m
matlab/gsa/stab_map_.m
matlab/gsa/stab_map_1.m
matlab/gsa/stab_map_2.m
matlab/gsa/stand_.m
matlab/gsa/tcrit.m
matlab/gsa/teff.m
matlab/gsa/trank.m
Files: matlab/+gsa/cumplot.m
matlab/+gsa/monte_carlo_filtering.m
matlab/+gsa/skewness.m
matlab/+gsa/log_transform.m
matlab/+gsa/map_calibration.m
matlab/+gsa/map_identification.m
matlab/+gsa/monte_carlo_filtering_analysis.m
matlab/+gsa/boxplot.m
matlab/+gsa/prior_draw.m
matlab/+gsa/reduced_form_mapping.m
matlab/+gsa/reduced_form_screening.m
matlab/+gsa/scatter_mcf.m
matlab/+gsa/smirnov_test.m
matlab/+gsa/stability_mapping.m
matlab/+gsa/stability_mapping_univariate.m
matlab/+gsa/stability_mapping_bivariate.m
matlab/+gsa/standardize_columns.m
matlab/+gsa/tcrit.m
matlab/+gsa/teff.m
Copyright: 2011-2018 European Commission
2011-2018 Dynare Team
2011-2023 Dynare Team
License: GPL-3+
Files: matlab/gsa/pick.m
Copyright: none
License: public-domain-jrc
This software has been developed at the Joint Research Centre of European Commission
by officers in the course of their official duties. This software is not subject to copyright
protection and is in the public domain. It is an experimental system. The Joint Research Centre
of European Commission assumes no responsibility whatsoever for its use by other parties
and makes no guarantees, expressed or implied, about its quality, reliability, or any other
characteristic. We would appreciate acknowledgement if the software is used.
Comment: This file is part of GLUEWIN.
The program has been developed by M. Ratto, European Commission, Joint Research Centre,
Institute for the Protection and Security of The Citizen, Technological and Economic Risk Management,
Applied Statistics, as a deliverable of the IMPACT project
(EC Fifth Framework Programme, SCA Project, IST-1999-11313, DG-INFSO).
Files: matlab/optimization/simpsa.m matlab/optimization/simpsaget.m matlab/optimization/simpsaset.m
Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se
2006 Brecht Donckels, BIOMATH, brecht.donckels@ugent.be
......@@ -231,14 +220,14 @@ License: GPL-3+
Files: matlab/missing/stats/quantile.m
Copyright: 2014-2016 Christopher Hummersone
2016-2017 Dynare Team
2016-2023 Dynare Team
License: GPL-3+
Files: matlab/missing/stats/corr.m
Copyright: 1993-1996 Kurt Hornik
1996-2015 John W. Eaton
2013-2015 Julien Bect
2016-2017 Dynare Team
2016-2023 Dynare Team
License: GPL-3+
Files: matlab/lmmcp/catstruct.m
......@@ -262,11 +251,16 @@ License: BSD-2-clause
Files: matlab/utilities/graphics/colorspace.m
Copyright: 2005-2010 Pascal Getreuer
2017 Dynare Team
2017-2023 Dynare Team
License: BSD-2-clause
Files: examples/fs2000_data.m
Copyright: 2000-2022 Frank Schorfheide
2023 Dynare Team
License: CC-BY-SA-4.0
Files: doc/*.rst doc/*.tex doc/*.svg doc/*.pdf doc/*.bib
Copyright: 1996-2022 Dynare Team
Copyright: 1996-2025 Dynare Team
License: GFDL-NIV-1.3+
Files: doc/dr.tex doc/dr.bib
......@@ -284,14 +278,14 @@ License: GPL-3+
Files: scripts/dynare.el
Copyright: 2010 Yannick Kalantzis
2019-2023 Dynare Team
2019-2025 Dynare Team
License: GPL-3+
Files: mex/sources/gensylv/gensylv.cc
mex/sources/libkorder/kord/* mex/sources/libkorder/sylv/*
mex/sources/libkorder/tl/* mex/sources/libkorder/utils/*
Copyright: 2004-2011 Ondra Kamenik
2019-2023 Dynare Team
2019-2025 Dynare Team
License: GPL-3+
Files: mex/sources/sobol/sobol.f08
......@@ -299,41 +293,14 @@ Copyright: 2004-2009 John Burkardt
2023 Dynare Team
License: LGPL-3+
Files: macOS/brewfiles/*
Copyright: 2009-2019 Homebrew contributors
2019-2021 Dynare Team
License: BSD-2-clause
Files: preprocessor/doc/macroprocessor/*
Copyright: 2008-2021 Dynare Team
Copyright: 2008-2024 Dynare Team
License: CC-BY-SA-4.0
Files: preprocessor/doc/preprocessor/*
Copyright: 2007-2019 Dynare Team
Copyright: 2007-2023 Dynare Team
License: CC-BY-SA-4.0
Files: contrib/jsonlab/*
Copyright: 2011-2020 Qianqian Fang <q.fang at neu.edu>
2016 Bastian Bechtold
License: GPL-3+ or BSD-3-clause
Files: contrib/jsonlab/base64decode.m
contrib/jsonlab/base64encode.m
contrib/jsonlab/gzipdecode.m
contrib/jsonlab/gzipencode.m
contrib/jsonlab/zlibdecode.m
contrib/jsonlab/zlibencode.m
Copyright: 2012 Kota Yamaguchi
2011-2020 Qianqian Fang <q.fang at neu.edu>
License: GPL-3+ or BSD-2-clause
Files: contrib/jsonlab/loadjson.m
Copyright: 2011-2020 Qianqian Fang
2009 Nedialko Krouchev
2009 François Glineur
2008 Joel Feenstra
License: GPL-3+ or BSD-2-clause or BSD-3-clause
Files: contrib/ms-sbvar/utilities_dw/*
Copyright: 1996-2011 Daniel Waggoner
License: GPL-3+
......@@ -440,32 +407,6 @@ License: BSD-2-clause
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
License: BSD-3-clause
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
.
* Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License: GFDL-NIV-1.3+
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
......
......@@ -15,22 +15,28 @@
# You should have received a copy of the GNU General Public License
# along with Dynare. If not, see <https://www.gnu.org/licenses/>.
.PHONY: all deps clean-deps clean clean-all build
ARCHS = arm64 x86_64
BUILDS = $(addprefix build-, $(ARCHS))
DEPS = $(addprefix deps-, $(ARCHS))
CLEAN_DEPS = $(addprefix clean-deps-, $(ARCHS))
CLEAN_ALL = $(addprefix clean-all-, $(ARCHS))
NTHREADS=$(shell sysctl -n hw.ncpu)
.PHONY: all $(BUILDS) $(DEPS) clean-pkg $(CLEAN_DEPS) $(CLEAN_ALL) clean-all
all: build
all: $(BUILDS)
deps:
make -C deps -j$(NTHREADS)
$(BUILDS): build-%: deps-%
./build.sh $*
clean-deps:
make -C deps clean-all
$(DEPS): deps-%:
make -C deps DEPS_ARCH=$*
clean:
$(CLEAN_DEPS): clean-deps-%:
make -C deps clean-all DEPS_ARCH=$*
clean-pkg:
rm -rf pkg
clean-all: clean-deps clean
$(CLEAN_ALL): clean-all-%: clean-deps-% clean-pkg
build: deps
./build.sh
clean-all: $(CLEAN_ALL)
class Gcc < Formula
desc "GNU compiler collection"
homepage "https://gcc.gnu.org/"
license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" }
head "https://gcc.gnu.org/git/gcc.git", branch: "master"
stable do
url "https://ftp.gnu.org/gnu/gcc/gcc-13.1.0/gcc-13.1.0.tar.xz"
mirror "https://ftpmirror.gnu.org/gcc/gcc-13.1.0/gcc-13.1.0.tar.xz"
sha256 "61d684f0aa5e76ac6585ad8898a2427aade8979ed5e7f85492286c4dfc13ee86"
# Branch from the Darwin maintainer of GCC, with a few generic fixes and
# Apple Silicon support, located at https://github.com/iains/gcc-13-branch
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/5c206c47/gcc/gcc-13.1.0.diff"
sha256 "cb4e8a89387f748a744da0273025d0dc2e3c76780cc390b18ada704676afea11"
end
end
livecheck do
url :stable
regex(%r{href=["']?gcc[._-]v?(\d+(?:\.\d+)+)(?:/?["' >]|\.t)}i)
end
bottle do
sha256 cellar: :any, arm64_ventura: "d2b21a257c73e9b8f9c6bc03e6330ea8ba9fb3e7cdb9eb945d7ff7d96ba9708c"
sha256 cellar: :any, arm64_monterey: "5405f3b1ecdabb68e161308f35d72af907af21694a0e2b67f10edb25b2dd8f90"
sha256 cellar: :any, arm64_big_sur: "cc92fced3516bc72b69e31b0495fe416f206b540be02f1c817db96afbcc38f28"
sha256 cellar: :any, ventura: "3abd8c2c88a8e74b5df5c44f9c151ff7e760cf705307ecf3c95762492e777f1e"
sha256 cellar: :any, monterey: "f9cbc7eb14781df9228518a2d02590941206947e7dc419c0b232d523f39b1475"
sha256 cellar: :any, big_sur: "2eb458ed309ea4fa9451ab547fa3d797bd523ba4f50f01d5c997212109b74e5e"
sha256 cellar: :any_skip_relocation, x86_64_linux: "cca77a5d6625d3bb711ce40551751974d4cb5c74306329fc2fc8cdcade2ef564"
end
# The bottles are built on systems with the CLT installed, and do not work
# out of the box on Xcode-only systems due to an incorrect sysroot.
pour_bottle? only_if: :clt_installed
depends_on "gmp"
depends_on "isl"
depends_on "libmpc"
depends_on "mpfr"
depends_on "zstd"
uses_from_macos "zlib"
on_linux do
depends_on "binutils"
end
# GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib
cxxstdlib_check :skip
def version_suffix
if build.head?
"HEAD"
else
version.major.to_s
end
end
def install
# GCC will suffer build errors if forced to use a particular linker.
ENV.delete "LD"
# We avoiding building:
# - Ada and D, which require a pre-existing GCC to bootstrap
# - Go, currently not supported on macOS
# - BRIG
languages = %w[c c++ objc obj-c++ fortran]
pkgversion = "Homebrew GCC #{pkg_version} #{build.used_options*" "}".strip
# Use `lib/gcc/current` to provide a path that doesn't change with GCC's version.
args = %W[
--prefix=#{opt_prefix}
--libdir=#{opt_lib}/gcc/current
--disable-nls
--enable-checking=release
--with-gcc-major-version-only
--enable-languages=#{languages.join(",")}
--program-suffix=-#{version_suffix}
--with-gmp=#{Formula["gmp"].opt_prefix}
--with-mpfr=#{Formula["mpfr"].opt_prefix}
--with-mpc=#{Formula["libmpc"].opt_prefix}
--with-isl=#{Formula["isl"].opt_prefix}
--with-zstd=#{Formula["zstd"].opt_prefix}
--with-pkgversion=#{pkgversion}
--with-bugurl=#{tap.issues_url}
--with-system-zlib
]
if OS.mac?
cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64"
args << "--build=#{cpu}-apple-darwin#{OS.kernel_version.major}"
# System headers may not be in /usr/include
sdk = MacOS.sdk_path_if_needed
args << "--with-sysroot=#{sdk}" if sdk
else
# Fix cc1: error while loading shared libraries: libisl.so.15
args << "--with-boot-ldflags=-static-libstdc++ -static-libgcc #{ENV.ldflags}"
# Fix Linux error: gnu/stubs-32.h: No such file or directory.
args << "--disable-multilib"
# Enable to PIE by default to match what the host GCC uses
args << "--enable-default-pie"
# Change the default directory name for 64-bit libraries to `lib`
# https://stackoverflow.com/a/54038769
inreplace "gcc/config/i386/t-linux64", "m64=../lib64", "m64="
end
mkdir "build" do
system "../configure", *args
system "make"
# Do not strip the binaries on macOS, it makes them unsuitable
# for loading plugins
install_target = OS.mac? ? "install" : "install-strip"
# To make sure GCC does not record cellar paths, we configure it with
# opt_prefix as the prefix. Then we use DESTDIR to install into a
# temporary location, then move into the cellar path.
system "make", install_target, "DESTDIR=#{Pathname.pwd}/../instdir"
mv Dir[Pathname.pwd/"../instdir/#{opt_prefix}/*"], prefix
end
bin.install_symlink bin/"gfortran-#{version_suffix}" => "gfortran"
# Provide a `lib/gcc/xy` directory to align with the versioned GCC formulae.
# We need to create `lib/gcc/xy` as a directory and not a symlink to avoid `brew link` conflicts.
(lib/"gcc"/version_suffix).install_symlink (lib/"gcc/current").children
# Only the newest brewed gcc should install gfortan libs as we can only have one.
lib.install_symlink lib.glob("gcc/current/libgfortran.*") if OS.linux?
# Handle conflicts between GCC formulae and avoid interfering
# with system compilers.
# Rename man7.
man7.glob("*.7") { |file| add_suffix file, version_suffix }
# Even when we disable building info pages some are still installed.
info.rmtree
# Work around GCC install bug
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105664
rm_rf bin.glob("*-gcc-tmp")
end
def add_suffix(file, suffix)
dir = File.dirname(file)
ext = File.extname(file)
base = File.basename(file, ext)
File.rename file, "#{dir}/#{base}-#{suffix}#{ext}"
end
def post_install
if OS.linux?
gcc = bin/"gcc-#{version_suffix}"
libgcc = Pathname.new(Utils.safe_popen_read(gcc, "-print-libgcc-file-name")).parent
raise "command failed: #{gcc} -print-libgcc-file-name" if $CHILD_STATUS.exitstatus.nonzero?
glibc = Formula["glibc"]
glibc_installed = glibc.any_version_installed?
# Symlink system crt1.o and friends where gcc can find it.
crtdir = if glibc_installed
glibc.opt_lib
else
Pathname.new(Utils.safe_popen_read("/usr/bin/cc", "-print-file-name=crti.o")).parent
end
ln_sf Dir[crtdir/"*crt?.o"], libgcc
# Create the GCC specs file
# See https://gcc.gnu.org/onlinedocs/gcc/Spec-Files.html
# Locate the specs file
specs = libgcc/"specs"
ohai "Creating the GCC specs file: #{specs}"
specs_orig = Pathname.new("#{specs}.orig")
rm_f [specs_orig, specs]
system_header_dirs = ["#{HOMEBREW_PREFIX}/include"]
if glibc_installed
# https://github.com/Linuxbrew/brew/issues/724
system_header_dirs << glibc.opt_include
else
# Locate the native system header dirs if user uses system glibc
target = Utils.safe_popen_read(gcc, "-print-multiarch").chomp
raise "command failed: #{gcc} -print-multiarch" if $CHILD_STATUS.exitstatus.nonzero?
system_header_dirs += ["/usr/include/#{target}", "/usr/include"]
end
# Save a backup of the default specs file
specs_string = Utils.safe_popen_read(gcc, "-dumpspecs")
raise "command failed: #{gcc} -dumpspecs" if $CHILD_STATUS.exitstatus.nonzero?
specs_orig.write specs_string
# Set the library search path
# For include path:
# * `-isysroot #{HOMEBREW_PREFIX}/nonexistent` prevents gcc searching built-in
# system header files.
# * `-idirafter <dir>` instructs gcc to search system header
# files after gcc internal header files.
# For libraries:
# * `-nostdlib -L#{libgcc} -L#{glibc.opt_lib}` instructs gcc to use
# brewed glibc if applied.
# * `-L#{libdir}` instructs gcc to find the corresponding gcc
# libraries. It is essential if there are multiple brewed gcc
# with different versions installed.
# Noted that it should only be passed for the `gcc@*` formulae.
# * `-L#{HOMEBREW_PREFIX}/lib` instructs gcc to find the rest
# brew libraries.
# Note: *link will silently add #{libdir} first to the RPATH
libdir = HOMEBREW_PREFIX/"lib/gcc/current"
specs.write specs_string + <<~EOS
*cpp_unique_options:
+ -isysroot #{HOMEBREW_PREFIX}/nonexistent #{system_header_dirs.map { |p| "-idirafter #{p}" }.join(" ")}
*link_libgcc:
#{glibc_installed ? "-nostdlib -L#{libgcc} -L#{glibc.opt_lib}" : "+"} -L#{libdir} -L#{HOMEBREW_PREFIX}/lib
*link:
+ --dynamic-linker #{HOMEBREW_PREFIX}/lib/ld.so -rpath #{libdir}
*homebrew_rpath:
-rpath #{HOMEBREW_PREFIX}/lib
EOS
inreplace(specs, " %o ", "\\0%(homebrew_rpath) ")
end
end
test do
(testpath/"hello-c.c").write <<~EOS
#include <stdio.h>
int main()
{
puts("Hello, world!");
return 0;
}
EOS
system "#{bin}/gcc-#{version_suffix}", "-o", "hello-c", "hello-c.c"
assert_equal "Hello, world!\n", shell_output("./hello-c")
(testpath/"hello-cc.cc").write <<~EOS
#include <iostream>
struct exception { };
int main()
{
std::cout << "Hello, world!" << std::endl;
try { throw exception{}; }
catch (exception) { }
catch (...) { }
return 0;
}
EOS
system "#{bin}/g++-#{version_suffix}", "-o", "hello-cc", "hello-cc.cc"
assert_equal "Hello, world!\n", shell_output("./hello-cc")
(testpath/"test.f90").write <<~EOS
integer,parameter::m=10000
real::a(m), b(m)
real::fact=0.5
do concurrent (i=1:m)
a(i) = a(i) + fact*b(i)
end do
write(*,"(A)") "Done"
end
EOS
system "#{bin}/gfortran", "-o", "test", "test.f90"
assert_equal "Done\n", shell_output("./test")
end
end