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
  • 4.3
  • 4.4
  • 4.5
  • 4.6
  • 5.x
  • 6.x
  • asm
  • aux_func
  • clang+openmp
  • dates-and-dseries-improvements
  • declare_vars_in_model_block
  • dmm
  • dragonfly
  • dynare_minreal
  • eigen
  • error_msg_undeclared_model_vars
  • estim_params
  • exo_steady_state
  • gpm-optimal-policy
  • julia
  • madysson
  • master
  • mex-GetPowerDeriv
  • penalty
  • precond
  • separateM_
  • slice
  • sphinx-doc-experimental
  • static_aux_vars
  • time-varying-information-set
  • various_fixes
  • 3.062
  • 3.063
  • 4.0.0
  • 4.0.1
  • 4.0.2
  • 4.0.3
  • 4.0.4
  • 4.1-alpha1
  • 4.1-alpha2
  • 4.1.0
  • 4.1.1
  • 4.1.2
  • 4.1.3
  • 4.2.0
  • 4.2.1
  • 4.2.2
  • 4.2.3
  • 4.2.4
  • 4.2.5
  • 4.3.0
  • 4.3.1
  • 4.3.2
  • 4.3.3
  • 4.4-beta1
  • 4.4.0
  • 4.4.1
  • 4.4.2
  • 4.4.3
  • 4.5.0
  • 4.5.1
  • 4.5.2
  • 4.5.3
  • 4.5.4
  • 4.5.5
  • 4.5.6
  • 4.5.7
  • 4.6-beta1
  • 4.6.0
  • 4.6.0-rc1
  • 4.6.0-rc2
  • 4.6.1
  • 4.6.2
  • 4.6.3
  • 4.6.4
  • 4.7-beta1
  • 4.7-beta2
  • 4.7-beta3
  • 5.0
  • 5.0-rc1
  • 5.1
  • 5.2
  • 5.3
  • 5.4
  • 5.5
  • 6-beta1
  • 6-beta2
  • 6.0
  • 6.1
  • 6.2
  • 6.3
91 results

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
  • 4.3
  • 4.4
  • 4.5
  • DSMH
  • OneStep2
  • SMC
  • SMCsamplers
  • aux_func
  • dates-and-dseries-improvements
  • declare_vars_in_model_block
  • dmm
  • dynamic-striated
  • eigen
  • error_msg_undeclared_model_vars
  • estim_params
  • exceptions
  • exo_steady_state
  • filter_initial_state
  • gpm-optimal-policy
  • julia
  • master
  • merge-initvalfile-fix
  • mex-GetPowerDeriv
  • new_ep
  • nlf-fixes
  • nonlinear-filter-fixes
  • occbin
  • online-filter-as-a-sampler
  • penalty
  • remove-@dates
  • remove-@dseries
  • remove-utilities-tests
  • rmExtraExo
  • separateM_
  • slice
  • smc-sampler
  • sphinx-doc-experimental
  • static_aux_vars
  • temporary_terms
  • 3.062
  • 3.063
  • 4.0.0
  • 4.0.1
  • 4.0.2
  • 4.0.3
  • 4.0.4
  • 4.1-alpha1
  • 4.1-alpha2
  • 4.1.0
  • 4.1.1
  • 4.1.2
  • 4.1.3
  • 4.2.0
  • 4.2.1
  • 4.2.2
  • 4.2.3
  • 4.2.4
  • 4.2.5
  • 4.3.0
  • 4.3.1
  • 4.3.2
  • 4.3.3
  • 4.4-beta1
  • 4.4.0
  • 4.4.1
  • 4.4.2
  • 4.4.3
  • 4.5.0
  • 4.5.1
  • 4.5.2
  • 4.5.3
  • 4.5.4
  • 4.5.5
  • 4.5.6
74 results
Show changes
Commits on Source (155)
Showing
with 1488 additions and 393 deletions
......@@ -8,6 +8,12 @@
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
# Effective configuration can be obtained with:
# clang-format --dump-config
# The RemoveParentheses and RemoveSemicolon option are not permanently set,
# because the clang-format manual (as of version 19) states that these
# options can lead to incorrect formatting and thus their result should be
# carefully reviewed.
Language: Cpp
Standard: c++20
ColumnLimit: 100
......@@ -23,7 +29,8 @@ InsertNewlineAtEOF: true
PackConstructorInitializers: NextLine
PPIndentWidth: 1
PointerAlignment: Left
RemoveSemicolon: true
# RemoveParentheses: ReturnStatement
# RemoveSemicolon: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: ControlStatements
SpaceBeforeCpp11BracedList: true
......@@ -107,7 +107,7 @@ pkg_macOS_x86_64:
script:
# Enforce the arm64 meson for rewrite, as a workaround to https://github.com/mesonbuild/meson/issues/12282
- env PATH="/opt/homebrew/bin:$PATH" meson rewrite kwargs set project / version "$VERSION"
- ln -s ~/tarballs macOS/deps/x86_64
- ln -s ~/tarballs macOS/deps/
- make -C macOS build-x86_64
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
......@@ -127,7 +127,7 @@ pkg_macOS_arm64:
script:
# Enforce the arm64 meson for rewrite, as a workaround to https://github.com/mesonbuild/meson/issues/12282
- env PATH="/opt/homebrew/bin:$PATH" meson rewrite kwargs set project / version "$VERSION"
- ln -s ~/tarballs macOS/deps/arm64
- ln -s ~/tarballs macOS/deps/
- make -C macOS build-arm64
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
......@@ -142,6 +142,20 @@ pkg_macOS_arm64:
expire_in: 3 days
needs: [ "build_doc" ]
pkg_matlab_online:
stage: pkg
script:
- meson rewrite kwargs set project / version "$VERSION"
- cd scripts/matlab-online && ./packageDynare.sh
tags:
- matlab-online
artifacts:
paths:
- scripts/matlab-online/*.mltbx
expire_in: 3 days
needs: []
when: manual
test_matlab:
stage: test
script:
......@@ -162,6 +176,7 @@ test_old_matlab:
paths:
- build-old-matlab/meson-logs/testlog.txt
when: always
needs: []
when: manual
test_octave:
......@@ -188,7 +203,7 @@ test_clang_tidy:
stage: test
script:
# Hack needed for meson < 1.6.0 which only looks for unversioned clang-tidy
- mkdir -p ~/.local/bin && ln -s /usr/bin/clang-tidy-16 ~/.local/bin/clang-tidy
- mkdir -p ~/.local/bin && ln -s /usr/bin/clang-tidy-19 ~/.local/bin/clang-tidy
- export PATH="$HOME/.local/bin:$PATH"
- meson setup -Dbuild_for=octave build-clang-tidy
- ninja -C build-clang-tidy clang-tidy
......
Announcement for Dynare 6.3 (on 2025-02-19)
===========================================
We are pleased to announce the release of Dynare 6.3.
This maintenance release fixes various bugs.
The Windows, macOS, MATLAB online and source packages are available for
download at [the Dynare website](https://www.dynare.org/download/).
This release is compatible with MATLAB versions ranging from 9.5 (R2018b) to
24.2 (R2024b), and with GNU Octave versions ranging from 7.1.0 to 9.4.0 (NB:
the Windows package requires version 9.4.0 specifically).
Here is a list of the problems identified in version 6.2 and that have been
fixed in version 6.3:
* OccBin with option `smoother_inversion_filter` would crash the MCMC
estimation if the `filtered_variables` or `filter_step_ahead` options were
used
* OccBin with option `smoother_inversion_filter` would use the PKF if
`mh_replic>0`
* OccBin with option `smoothed_state_uncertainty` would crash Dynare if the
MCMC smoother was run after the classical one
* OccBin's smoother would crash when encountering an internal error due to the
output of the linear smoother not having been computed
* Calling `model_info` with `differentiate_forward_vars` would crash
* The `identification` command would compute the asymptotic Hessian via
simulation instead of via moments as intended
* The `identification` command would crash during prior sampling if the initial
draw did not solve the model
* The `gsa_sample_file` was broken
* Optimization algorithm `mode_compute=5` (`newrat`) would crash with
`analytic_derivation`
* The `discretionary_policy` command would crash if the model was purely
forward-looking
* The `dsample` command would crash
* The `conditional_forecast_paths` block did not accept vector inputs
* For MCMC chains with fewer than 6000 draws, the default number of `sub_draws`
used to compute posterior moments was incorrect
* Bi-annual dates (e.g. `2024S1` or `2024H1`) were not accepted within Dynare
statements
* Plotting `dseries` did not correctly show dates on the x-axis
Announcement for Dynare 6.2 (on 2024-09-25)
===========================================
......
......@@ -362,7 +362,7 @@ cd dynare
```
- Configure Dynare from the source directory:
```sh
meson setup -Dmatlab_path=<…> --buildtype=debugoptimized --prefer-static -Dfortran_args="['-B','/usr/local/lib']" build-matlab
meson setup -Dmatlab_path=<…> --buildtype=debugoptimized --prefer-static -Dfortran_args="['-B','C:/msys64/usr/local/lib']" build-matlab
```
where the path of MATLAB is specified. Note that you should use
the MSYS2 notation and not put spaces in the MATLAB path, so you probably want
......
......@@ -6,6 +6,7 @@ Bibliography
* Abramowitz, Milton and Irene A. Stegun (1964): “Handbook of Mathematical Functions”, Courier Dover Publications.
* Adjemian, Stéphane, Matthieu Darracq Parriès and Stéphane Moyen (2008): “Towards a monetary policy evaluation framework”, *European Central Bank Working Paper*, 942.
* Adjemian, Stéphane and Michel Juillard (2025): “Stochastic Extended Path”, *Dynare Working Papers*, 84, CEPREMAP.
* Aguiar, Mark and Gopinath, Gita (2004): “Emerging Market Business Cycles: The Cycle is the Trend,” *NBER* Working Paper, 10734.
* Amisano, Gianni and Tristani, Oreste (2010): “Euro area inflation persistence in an estimated nonlinear DSGE model”, *Journal of Economic Dynamics and Control*, 34(10), 1837–1858.
* Andreasen, Martin M., Jesús Fernández-Villaverde, and Juan Rubio-Ramírez (2018): “The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications,” *Review of Economic Studies*, 85(1), 1-49.
......@@ -65,7 +66,7 @@ Bibliography
* Koopman, S. J. and J. Durbin (2003): “Filtering and Smoothing of State Vector for Diffuse State Space Models,” *Journal of Time Series Analysis*, 24(1), 85–98.
* Kuntsevich, Alexei V. and Franz Kappel (1997): “SolvOpt - The solver for local nonlinear optimization problems (version 1.1, Matlab, C, FORTRAN)”, University of Graz, Graz, Austria.
* Laffargue, Jean-Pierre (1990): “Résolution d’un modèle macroéconomique avec anticipations rationnelles”, *Annales d’Économie et Statistique*, 17, 97–119.
* Liu, Jane and Mike West (2001): “Combined parameter and state estimation in simulation-based filtering”, in *Sequential Monte Carlo Methods in Practice*, Eds. Doucet, Freitas and Gordon, Springer Verlag.
* Liu, Jane and Mike West (2001): “Combined parameter and state estimation in simulation-based filtering”, in *Sequential Monte Carlo Methods in Practice*, Eds. Doucet, Freitas and Gordon, Springer Verlag, Chapter 10, 197-223.
* Murray, Lawrence M., Emlyn M. Jones and John Parslow (2013): “On Disturbance State-Space Models and the Particle Marginal Metropolis-Hastings Sampler”, *SIAM/ASA Journal on Uncertainty Quantification*, 1, 494–521.
* Mutschler, Willi (2015): “Identification of DSGE models - The effect of higher-order approximation and pruning“, *Journal of Economic Dynamics & Control*, 56, 34-54.
* Mutschler, Willi (2018): “Higher-order statistics for DSGE models”, *Econometrics and Statistics*, 6(C), 44-56.
......
# -*- coding: utf-8 -*-
# Copyright © 2018-2024 Dynare Team
# Copyright © 2018-2025 Dynare Team
#
# This file is part of Dynare.
#
......@@ -34,7 +34,7 @@ html_static_path = ['_static']
master_doc = 'index'
project = u'Dynare'
copyright = u'1996–2024 Dynare Team'
copyright = u'1996–2025 Dynare Team'
author = u'Dynare Team'
add_function_parentheses = False
......
......@@ -26,7 +26,7 @@ The following people used to be members of the team:
* Ferhat Mihoubi
* George Perendia
Copyright © 1996-2024, Dynare Team.
Copyright © 1996-2025, Dynare Team.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
......
......@@ -15,7 +15,7 @@ compilation steps are necessary in that case.
In order to run Dynare, you need one of the following:
* MATLAB, any version ranging from 9.5 (R2018b) to 24.2 (R2024b);
* GNU Octave, any version ranging from 7.1.0 to 9.2.0, with the ``statistics`` package
* GNU Octave, any version ranging from 7.1.0 to 9.4.0, with the ``statistics`` package
from `Octave-Forge`_. Note however that the Dynare installer for Windows
requires a more specific version of Octave, as indicated on the download
page.
......@@ -24,6 +24,7 @@ The following optional extensions are also useful to benefit from
extra features, but are in no way required:
* If under MATLAB: the
* Optimization Toolbox (providing various optimizers
like ``fminsearch``, ``fmincon``, or ``fminunc``, used in e.g. ``mode_compute``,
``opt_algo`` or ``ALGO``),
......@@ -99,6 +100,19 @@ Debian, Ubuntu and Linux Mint).
On macOS
--------
.. warning::
Installing into ``/Applications/dynare`` might fail if you have older versions of Dynare already installed in ``/Applications/Dynare``.
To fix this, modify the ownership by executing the following command in Terminal.app::
sudo chown -R "$USER":staff /Applications/Dynare
Alternatively, you can modify the installation path in the automated installed using *Customize* and *Location*.
After installation, the folder will contain several sub-directories, among which are ``matlab``, ``mex``, and ``doc``.
Several versions of Dynare can coexist (by default in ``/Applications/Dynare``),
as long as you correctly adjust your path settings (see :ref:`words-warning`).
With MATLAB
^^^^^^^^^^^
......@@ -108,19 +122,14 @@ and follow the instructions.
This installation does not require administrative privileges.
If for some reason admin rights are requested, use *Change Install Location* and select *Install for me only*.
The default installation directory is ``/Applications/Dynare/x.y-arch``.
Installing into ``/Applications/dynare`` might fail if you have older versions of Dynare already installed in ``/Applications/Dynare``.
To fix this, modify the ownership by executing the following command in Terminal.app::
sudo chown -R "$USER":staff /Applications/Dynare
Alternatively, you can modify the installation path in the automated installed using *Customize* and *Location*.
After installation, the folder will contain several sub-directories, among which are ``matlab``, ``mex``, and ``doc``.
Several versions of Dynare can coexist (by default in ``/Applications/Dynare``),
as long as you correctly adjust your path settings (see :ref:`words-warning`).
It is recommended to install the Xcode Command Line Tools (this is an Apple product)
and GCC via Homebrew_ (see :ref:`prerequisites-macos`).
To deinstall Dynare, simply delete the folder where you installed the program. The package installer does
not put any files anywhere else in the system.
With Octave
^^^^^^^^^^^
......@@ -141,6 +150,8 @@ once)::
octave:1> pkg install -forge io statistics control struct optim
If you want to use the `x13` functionality of `dseries`, you also need to build the `x13as` binary. [#fx13]_
On FreeBSD
----------
......@@ -333,3 +344,8 @@ Dynare unusable.
.. _Dynare wiki: https://git.dynare.org/Dynare/dynare/wikis
.. _Octave-Forge: https://octave.sourceforge.io/
.. _Homebrew: https://brew.sh
.. rubric:: Footnotes
.. [#fx13] See the instructions at `<https://forum.dynare.org/t/missing-installation-package/27350/4>`__.
\ No newline at end of file
......@@ -188,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
......
This diff is collapsed.
This diff is collapsed.
......@@ -97,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)
......@@ -242,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)
......
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Dynare
Upstream-Contact: Dynare Team, whose members in 2024 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 2024 are:
Source: https://www.dynare.org
Files: *
Copyright: 1996-2024 Dynare Team
Copyright: 1996-2025 Dynare Team
License: GPL-3+
Files: matlab/+occbin/IVF_core.m
......@@ -97,7 +97,7 @@ 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
......@@ -173,7 +173,7 @@ Comment: The author gave authorization to redistribute
Files: matlab/+gsa/Morris_Measure_Groups.m
matlab/+gsa/Sampling_Function_2.m
Copyright: 2005 European Commission
2012-2013 Dynare Team
2012-2023 Dynare Team
License: GPL-3+
Comment: Written by Jessica Cariboni and Francesca Campolongo
Joint Research Centre, The European Commission,
......@@ -220,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
......@@ -260,7 +260,7 @@ Copyright: 2000-2022 Frank Schorfheide
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
......@@ -278,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
......@@ -294,11 +294,11 @@ Copyright: 2004-2009 John Burkardt
License: LGPL-3+
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/ms-sbvar/utilities_dw/*
......
......@@ -40,11 +40,6 @@ else
fi
MATLAB_PATH=/Applications/"$PKG_ARCH"/MATLAB_R2024b.app
# Workaround for bug in Xcode 15.3 which does not include m4
# See https://github.com/Homebrew/homebrew-core/issues/165388
# and https://trac.macports.org/ticket/69639
path_prepend PATH "$BREWDIR"/opt/m4/bin
# Append texbin to PATH to access latexmk and friends
path_prepend PATH /Library/TeX/texbin
......
......@@ -360,7 +360,7 @@ if options_gsa.redform && ~isempty(options_gsa.namendo)
if isempty(options_gsa.threshold_redform) && ~(exist('gsa_sdp','file')==6 || exist('gsa_sdp','file')==2)
fprintf('\nThe "SS-ANOVA-R: MATLAB Toolbox for the estimation of Smoothing Spline ANOVA models with Recursive algorithms" is missing.\n')
fprintf('To obtain it, go to:\n\n')
fprintf('https://ec.europa.eu/jrc/en/macro-econometric-statistical-software/ss-anova-r-downloads \n\n')
fprintf('https://joint-research-centre.ec.europa.eu/system/files/2025-01/ss_anova_recurs.zip \n\n')
fprintf('and follow the instructions there.\n')
fprintf('After obtaining the files, you need to unpack them and set a Matlab Path to those files.\n')
error('SS-ANOVA-R Toolbox missing!')
......
......@@ -92,6 +92,10 @@ xparam1=[];
[~,~,~,lb,ub] = set_prior(estim_params_,M_,options_); %Prepare bounds
if ~isempty(bayestopt_) && any(bayestopt_.pshape > 0)
% Set prior bounds
if options_.prior_trunc==0
fprintf('\nstability_mapping: GSA with priors requires bounded support. Setting options_.prior_trunc=1e-10.\n')
options_.prior_trunc=1e-10;
end
bounds = prior_bounds(bayestopt_, options_.prior_trunc);
bounds.lb = max(bounds.lb,lb);
bounds.ub = min(bounds.ub,ub);
......
% Copyright © 2025 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/>.
%
% Compute the stochastic simulations of heterogeneus-agent models
%
% INPUTS
% - M_ [structure] Matlab's structure describing the model
% - options_ [structure] Matlab's structure describing the current options
% - ss [structure] Matlab's structure with the model steady-state
% information. It contains the following fields:
% - pol [structure] Matlab's structure containing the policy functions
% discretization
% - pol.grids [structure]: Matlab's structure containing the nodes of the
% state grids as column vectors.
% - pol.values [structure]: Matlab's structure containing the policy
% function as matrices. Row indices and column
% indices follow the lexicographic order
% specified in pol.shocks and pol.states
% - pol.shocks [array]: a list containing the order of shock/innovation
% variables used for the rows of pol.values. If not
% specified, it follows the declaration order in the
% var(heterogeneity=) statement (resp. varexo(heterogeneity=)
% statement) for discretizes AR(1) processes (resp.
% discretized gaussian i.i.d innovations).
% - pol.states [array]: a list containing the order of state variables
% used for the columns of pol.values. If not
% specified, it follows the declaration order in the
% var(heterogeneity=) statement.
% - shocks [structure]: Matlab's stucture describing the discretization of
% individual shocks or innovations:
% - shocks.grids [structure]: Matlab's structure containing the nodes of
% the shock grids
% - shocks.Pi [structure]: Matlab's structure containing the Markov
% matrices if the shock processes are discretized
% AR(1) processes. The field should be absent
% otherwise.
% - shocks.w [structure]: Matlab's structure containing the Gauss-Hermite
% weights if the i.i.d gaussian innovation
% processes are discretized
% - d [structure]: Matlab's structure describing the steady-state
% distribution
% - d.grids [structure]: structure containing the states grids as column
% vectors. If one of the states grid is not
% specified, it is assumed to be identical to
% its policy-function value stored in pol.grids
% - d.hist [matrix]: the histogram of the distribution as a matrix with
% shocks/innovation indices as rows and state indices
% as columns. Row and column indices follow the
% lexicographic order specified in d.shocks and
% d.states
% - d.shocks [array]: a list containing the order of shock/innovation
% variables used for the rows of d.hist. If it is not
% specified, it falls back to the value induced by
% pol.shocks.
% - d.states [array]: a list containing the order of state variables used
% for the columns of d.hist. If it is not
% specified, it falls back to the value induced by
% pol.states.
% - agg [structure]: Matlab's tructure containing the steady-state values of
% aggregate variables
% OUTPUTS
% - out_ss [structure]: validated and normalized steady-state input structure.
% It has a similar structure as the ss structure in inputs.
% - sizes [structure]: structure containing sizes information
% - n_e [integer]: number of shocks
% - N_e [integer]: total number of nodes in the shocks grids
% - shocks [structure]: number of nodes for each shock grid
% - n_a [integer]: number of states
% - pol [structure]:
% - pol.N_a [integer]: total number of nodes in the policy state grids
% - pol.states [structure]: number of nodes for each state grid
% - d [structure]:
% - d.states [structure]: number of nodes for each distribution state grid
% - d.N_a [integer]: total number of nodes in the distribution grids
% - n_pol [integer]: number of policy variables
% - agg [integer]: number of aggregate variables
function [out_ss, sizes] = check_steady_state_input(M_, options_, ss)
%% Checks
% Retrieve variables information from M_
state_symbs = M_.heterogeneity(1).endo_names(M_.heterogeneity(1).state_var);
pol_symbs= M_.heterogeneity(1).endo_names;
inn_symbs = M_.heterogeneity(1).exo_names;
agg_symbs = M_.endo_names(1:M_.orig_endo_nbr);
% Initialize output variables
sizes = struct;
out_ss = struct;
if ~isstruct(ss)
error('Misspecified steady-state input `ss`: the steady-state input `ss` is not a structure.')
end
%% Shocks
% Check that the field `ss.shocks` exists
check_isfield('shocks', ss, 'ss.shocks', ' Models without idiosyncratic shocks but with ex-post heterogeneity over individual state variables cannot be solved yet.')
shocks = ss.shocks;
% Check that `ss.shocks` is a structure
check_isstruct(shocks, 'ss.shocks');
% Check that the field `ss.shocks.grids` exists
check_isfield('grids', ss.shocks, 'ss.shocks.grids');
% Check that `ss.shocks.grids` is a structure
check_isstruct(shocks.grids, 'ss.shocks.grids');
shock_symbs = fieldnames(shocks.grids);
% Check the types of `ss.shocks.grids` values
check_fun(shocks.grids, 'ss.shocks.grids', shock_symbs, @(x) isnumeric(x) && isreal(x) && isvector(x) && ~issparse(x), 'are not dense real vectors');
% Make `ss.shocks.grids` values column vector in the output steady-state
% structure
for i=1:numel(shock_symbs)
s = shock_symbs{i};
if isrow(ss.shocks.grids.(s))
out_ss.shocks.grids.(s) = ss.shocks.grids.(s)';
else
out_ss.shocks.grids.(s) = ss.shocks.grids.(s);
end
end
% Check shock discretization
flag_ar1 = isfield(shocks, 'Pi');
flag_gh = isfield(shocks, 'w');
if ~flag_ar1 && ~flag_gh
error('Misspecified steady-state input `ss`: the `ss.shocks.Pi` and `ss.shocks.w` fields are both non-specified, while exactly one of them should be set.');
end
% Check that either individual AR(1) processes or i.i.d gaussion innovation
% processes are discretized
if flag_ar1 && flag_gh
error('Misspecified steady-state input `ss`: the `ss.shocks.Pi` and `ss.shocks.w` fields are both specified, while only one of them should be.');
end
% Case of discretized AR(1) exogenous processes
if flag_ar1
% Check that the grids specification for AR(1) shocks and the
% var(heterogeneity=) statement are compatible
check_consistency(shock_symbs, pol_symbs, 'ss.shocks.grids', 'M_.heterogeneity(1).endo_names');
% Check that shocks.Pi is a structure
check_isstruct(shocks.Pi, 'ss.shocks.Pi');
% Check that the grids specification for individual AR(1) shocks, the
% information in the M_ structure and the Markov transition matrices
% specification are compatible and display a warning if redundancies are
% detected
check_missingredundant(shocks.Pi, 'ss.shocks.Pi', shock_symbs, options_.hank.nowarningredundant);
% Store:
% - the number of shocks
sizes.n_e = numel(shock_symbs);
% - the size of the tensor product of the shock grids
grid_nb = cellfun(@(s) numel(shocks.grids.(s)), shock_symbs);
sizes.N_e = prod(grid_nb);
% - the size of each shock grid
for i=1:numel(shock_symbs)
s = shock_symbs{i};
sizes.shocks.(s) = numel(shocks.grids.(s));
end
% Check the type of shocks.Pi field values
check_fun(shocks.Pi, 'ss.shocks.Pi', shock_symbs, @(x) ismatrix(x) && isnumeric(x) && isreal(x) && ~issparse(x), 'are not dense real matrices');
% Check the internal size compatibility of discretized shocks processes
check_fun(shocks.Pi, 'ss.shocks.Pi', shock_symbs, @(x) size(x,1), 'have a number of rows that is not consistent with the size of their counterparts in `ss.shocks.grids`', grid_nb);
check_fun(shocks.Pi, 'ss.shocks.Pi', shock_symbs, @(x) size(x,2), 'have a number of columns that is not consistent with the size of their counterparts in `ss.shocks.grids`', grid_nb);
% Check that the matrices provided in shocks.Pi are Markov matrices:
% - all elements are non-negative
check_fun(shocks.Pi, 'ss.shocks.Pi', shock_symbs, @(x) all(x >= 0, 'all'), 'contain negative elements')
% - the sum of each row equals 1.
check_fun(shocks.Pi, 'ss.shocks.Pi', shock_symbs, @(x) all(abs(sum(x,2)-1) < options_.hank.tol_check_sum), 'have row sums different from 1.')
% Remove AR(1) shock processes from state and policy variables
state_symbs = setdiff(state_symbs, shock_symbs);
pol_symbs = setdiff(pol_symbs, shock_symbs);
% Copy relevant shock-related elements in out_ss
out_ss.shocks.Pi = ss.shocks.Pi;
end
% Case of discretized i.i.d gaussian innovations
if flag_gh
% Check that shocks.w is a structure
check_isstruct(shocks.w, 'shocks.w');
% Verify that the grids specification for individual i.i.d innovations and
% the varexo(heterogeneity=) statement are compatible
check_consistency(shock_symbs, inn_symbs, 'ss.shocks.grids', 'M_.heterogeneity(1).exo_names');
% Verify that the grids specification for individual i.i.d innovations and
% the Gauss-Hermite weights specification are compatible and display a
% warning if redundancies are detected
check_missingredundant(shocks.w, 'ss.shocks.w', shock_symbs, options_.hank.nowarningredundant);
% Check the type of `ss.shocks.w` elements
check_fun(shocks.w, 'ss.shocks.w', shock_symbs, @(x) isvector(x) && isnumeric(x) && isreal(x) && ~issparse(x), 'are not dense real vectors');
% Store:
% - the number of shocks
sizes.n_e = numel(shock_symbs);
% - the size of the tensor product of the shock grids
grid_nb = cellfun(@(s) numel(shocks.grids.(s)), shock_symbs);
sizes.N_e = prod(grid_nb);
% - the size of each shock grid
for i=1:numel(shock_symbs)
s = shock_symbs{i};
sizes.shocks.(s) = numel(shocks.grids.(s));
end
% Check the internal size compatibility of discretized shocks processes
check_fun(shocks.w, 'ss.shocks.w', shock_symbs, @(x) numel(x), 'have incompatible sizes with those of `ss.shocks.grids`', grid_nb);
% Check that the arrays provided in shocks.w have the properties of
% Gauss-Hermite weights:
% - all elements are non-negative
check_fun(shocks.w, 'ss.shocks.w', shock_symbs, @(x) all(x >= 0.), 'contain negative elements');
% - the sum of Gauss-Hermite weights is 1
check_fun(shocks.w, 'ss.shocks.w', shock_symbs, @(x) all(abs(sum(x)-1) < options_.hank.tol_check_sum), 'have sums different from 1.');
% Make `ss.shocks.w` values column vectors in the output steady-state
% structure
for i=1:numel(shock_symbs)
s = shock_symbs{i};
if isrow(ss.shocks.w.(s))
out_ss.shocks.w.(s) = ss.shocks.w.(s)';
else
out_ss.shocks.w.(s) = ss.shocks.w.(s);
end
end
end
%% Policy functions
% Check that the `ss.pol` field exists
check_isfield('pol', ss, 'ss.pol');
pol = ss.pol;
% Check that `ss.pol` is a structure
check_isstruct(ss.pol, 'ss.pol');
% Check that the `ss.pol`.grids field exists
check_isfield('grids', ss.pol, 'ss.pol.grids');
% Check that `ss.pol.grids` is a structure
check_isstruct(ss.pol.grids, 'ss.pol.grids');
% Check that the state grids specification and the var(heterogeneity=)
% statement are compatible
check_missingredundant(pol.grids, 'ss.pol.grids', state_symbs, options_.hank.nowarningredundant);
% Check that `ss.pol.grids` values are dense real vectors
check_fun(pol.grids, 'ss.pol.grids', state_symbs, @(x) isnumeric(x) && isreal(x) && isvector(x) && ~issparse(x), 'are not dense real vectors');
% Store:
% - the number of states
sizes.n_a = numel(state_symbs);
% - the size of the tensor product of the states grids
grid_nb = cellfun(@(s) numel(pol.grids.(s)), state_symbs);
sizes.pol.N_a = prod(grid_nb);
% - the size of each state grid
for i=1:numel(state_symbs)
s = state_symbs{i};
sizes.pol.states.(s) = numel(pol.grids.(s));
end
% Make `ss.shocks.grids` values column vector in the output steady-state
% structure
for i=1:numel(state_symbs)
s = state_symbs{i};
if isrow(ss.pol.grids.(s))
out_ss.pol.grids.(s) = ss.pol.grids.(s)';
else
out_ss.pol.grids.(s) = ss.pol.grids.(s);
end
end
% Check that the field `ss.pol.values` exists
check_isfield('values', pol, 'ss.pol.values');
% Check that `ss.pol.values` is a struct
check_isstruct(pol.values, 'ss.pol.values');
% Check the missing and redundant variables in `ss.pol.values`
check_missingredundant(pol.values, 'ss.pol.values', pol_symbs, options_.hank.nowarningredundant);
% Check that `ss.pol.values` values are dense real matrices
check_fun(pol.values, 'ss.pol.values', pol_symbs, @(x) isnumeric(x) && isreal(x) && ismatrix(x) && ~issparse(x), 'are not dense real matrices');
% Check the internal size compatibility of `ss.pol.values`
sizes.n_pol = numel(pol_symbs);
check_fun(pol.values, 'ss.pol.values', pol_symbs, @(x) size(x,1), 'have a number of rows that is not consistent with the sizes of `ss.shocks.grids` elements', sizes.N_e);
check_fun(pol.values, 'ss.pol.values', pol_symbs, @(x) size(x,2), 'have a number of columns that is not consistent with the sizes of `ss.pol.grids` elements', sizes.pol.N_a);
% Copy `ss.pol.values` in `out_ss`
out_ss.pol.values = ss.pol.values;
% Check the permutation of state variables for policy functions
[out_ss.pol.states] = check_permutation(pol, 'states', 'ss.pol', state_symbs);
% Check the permutation of shock variables for policy functions
[out_ss.pol.shocks] = check_permutation(pol, 'shocks', 'ss.pol', shock_symbs);
%% Distribution
% Check that the field `ss.d` exists
check_isfield('d', ss, 'ss.d');
d = ss.d;
% Check that the field `ss.d.hist` exists
check_isfield('hist', ss.d, 'ss.d.hist');
% Check the type of `ss.d.hist`
if ~(ismatrix(d.hist) && isnumeric(d.hist) && isreal(d.hist) && ~issparse(d.hist))
error('Misspecified steady-state input `ss`: `ss.d.hist` is not a dense real matrix.');
end
% Check the consistency of `ss.d.grids`
if ~isfield(d, 'grids')
if ~options_.hank.nowarningdgrids
warning('In the steady-state input `ss.d.grids`, no distribution-specific grid is set for states %s. The policy grids in `ss.pol.grids` shall be used.' , strjoin(state_symbs));
end
% Copy the relevant sizes from the pol field
sizes.d = sizes.pol;
out_ss.d.grids = out_ss.pol.grids;
else
% Check that `ss.d.grids` is a struct
check_isstruct(d.grids, 'ss.d.grids');
% Check redundant variables in `ss.d.grids`
d_grids_symbs = fieldnames(d.grids);
if isempty(d_grids_symbs)
if ~options_.hank.nowarningredundant
warning('In the steady-state input `ss.d.grids`, no distribution-specific grid is set for states %s. The policy grids in `ss.pol.grids` shall be used.' , strjoin(state_symbs));
end
% Copy the relevant sizes from the pol field
sizes.d = sizes.pol;
out_ss.d.grids = out_ss.pol.grids;
else
d_grids_symbs_in_states = ismember(d_grids_symbs, state_symbs);
if ~all(d_grids_symbs_in_states)
if ~options_.hank.nowarningredundant
warning('In the steady-state input `ss.d.states`, the following specification for the states grids in the distribution structure are not useful: %s', strjoin(d_grids_symbs(~d_grids_symbs_in_states)));
end
d_grids_symbs = d_grids_symbs(d_grids_symbs_in_states);
end
% Check the types of `ss.d.grids` elements
check_fun(pol.grids, 'ss.d.grids', d_grids_symbs, @(x) isnumeric(x) && isreal(x) && isvector(x) && ~issparse(x), 'are not dense real vectors');
% Store the size of the states grids for the distribution
for i=1:numel(d_grids_symbs)
s = d_grids_symbs{i};
sizes.d.states.(s) = numel(d.grids.(s));
out_ss.d.grids.(s) = d.grids.(s);
end
states_out_of_d = setdiff(state_symbs, d_grids_symbs);
if ~isempty(states_out_of_d)
if ~options_.hank.nowarningdgrids
warning('hank.bbeg.het_stoch_simul: in the steady-state structure, no distribution-specific grid set for states %s. The policy grids specified in pol.grids shall be used.', strjoin(states_out_of_d));
end
% Store the sizes of the unspecified states grids from the pol field
for i=1:numel(states_out_of_d)
s = states_out_of_d{i};
sizes.d.states.(s) = sizes.pol.states.(s);
out_ss.d.grids.(s) = pol.grids.(s);
end
end
end
end
% Check the internal size compatibility of the distribution histogram
if size(d.hist,1) ~= sizes.N_e
error('Misspecified steady-state input `ss`: the number of rows of the histogram matrix `ss.d.hist` is not consistent with the sizes of shocks grids `ss.shocks.grids`');
end
sizes.d.N_a = prod(structfun(@(x) x, sizes.d.states));
if size(d.hist,2) ~= sizes.d.N_a
error('Misspecified steady-state input `ss`: the number of columns of the histogram matrix `ss.d.hist` is not consistent with the sizes of states grids `ss.d.grids`/`ss.pol.grids`');
end
% Copy `ss.d.hist` in `out_ss`
out_ss.d.hist = ss.d.hist;
% Check the permutation of state variables in the distribution
[out_ss.d.states] = check_permutation(d, 'states', 'ss.d', state_symbs);
% Check the permutation of shock variables in the distribution
[out_ss.d.shocks] = check_permutation(d, 'shocks', 'ss.d', shock_symbs);
%% Aggregate variables
% Check that the field `ss.agg` exists
check_isfield('agg', ss, 'ss.agg');
agg = ss.agg;
% Check that `ss.agg` is a structure
check_isstruct(agg, 'ss.agg');
% Check that the aggregate variables specification and the var statement are
% compatible
check_missingredundant(agg, 'ss.agg', agg_symbs, options_.hank.nowarningredundant);
% Store the number of aggregate variables
sizes.agg = numel(fieldnames(agg));
% Check the types of `ss.agg` values
check_fun(agg, 'ss.agg', agg_symbs, @(x) isreal(x) && isscalar(x), 'are not real scalars');
% Copy `ss.agg` into `out_ss`
out_ss.agg = agg;
end
% Copyright © 2025 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/>.
%
% Check consistency between two sets of variable names.
%
% INPUTS
% - f1 [cell array of strings]: list of variable names to be checked for consistency
% - f2 [cell array of strings]: reference list of valid variable names
% - f1_name [char]: name of the first set (for error messages)
% - f2_name [char]: name of the second set (for error messages)
%
% OUTPUTS
% - (none) This function throws an error if there are elements in `f1` that are not present in `f2`.
%
% DESCRIPTION
% Checks that all elements of `f1` are included in `f2`. If not, throws a descriptive error
% mentioning the missing variables and the corresponding structure names for easier debugging.
function [] = check_consistency(f1, f2, f1_name, f2_name)
f1_in_f2 = ismember(f1,f2);
if ~all(f1_in_f2)
error('Misspecified steady-state input `ss`: the following variables are mentioned in `%s`, but are missing in `%s`: %s', f1_name, f2_name, strjoin(f1(~f1_in_f2)));
end
end
\ No newline at end of file
% Copyright © 2025 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/>.
%
% Apply a validation function to a set of fields within a structure.
%
% INPUTS
% - f [structure]: structure containing fields to be validated
% - f_name [char]: name of the structure (for error messages)
% - symbs [cell array of strings]: list of field names to validate
% - fun [function handle]: validation function applied to each field
% - text [char]: descriptive text for the error message in case of validation failure
% - eq [optional, scalar]: if provided, the output of `fun` is compared to `eq`
%
% OUTPUTS
% - (none) This function throws an error if any field fails the validation.
%
% DESCRIPTION
% For each symbol in `symbs`, applies the validation function `fun` to the
% corresponding field in `f`. If an optional `eq` argument is provided, the
% output of `fun` is compared to `eq`. Throws a descriptive error listing all
% fields that do not satisfy the validation criteria.
function [] = check_fun(f, f_name, symbs, fun, text, eq)
elt_check = cellfun(@(s) fun(f.(s)), symbs);
if nargin == 6
elt_check = elt_check == eq;
end
if ~all(elt_check)
error('Misspecified steady-state input `ss`: the following fields in `%s` %s: %s', f_name, text, strjoin(symbs(~elt_check)));
end
end
\ No newline at end of file
% Copyright © 2025 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/>.
%
% Check the existence of a field in a structure.
%
% INPUTS
% - f [char]: name of the field to check
% - s [structure]: structure in which the field should be present
% - f_name [optional, char]: name to display in the error message (defaults to `f`)
% - details [optional, char]: additional details to append to the error message
%
% OUTPUTS
% - (none) This function throws an error if the specified field is missing.
%
% DESCRIPTION
% Checks whether the field `f` exists in the structure `s`.
% If not, throws an error indicating the missing field.
% If provided, `details` is appended to the error message for additional context.
function [] = check_isfield(f, s, f_name, details)
if nargin < 4
details = '';
end
if nargin < 3
f_name = f;
end
if ~isfield(s, f)
error('Misspecified steady-state input `ss`: the `%s` field is missing.%s', f_name, details);
end
end
\ No newline at end of file