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

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
Show changes
Commits on Source (200)
Showing
with 1609 additions and 474 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
......@@ -19,9 +25,12 @@ BreakInheritanceList: AfterColon
Cpp11BracedListStyle: true
DeriveLineEnding: false
IndentPPDirectives: AfterHash
InsertNewlineAtEOF: true
PackConstructorInitializers: NextLine
PPIndentWidth: 1
PointerAlignment: Left
# 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"
......@@ -184,6 +184,17 @@ test_clang_format:
- ninja -C build-clang-format clang-format-check
needs: []
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-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
needs: []
when: manual
# For the sign and deploy jobs, we don’t use the “needs” keyword, since we
# don’t want those jobs to start before the “test” and “pkg” stages have
# succeeded. Hence we stick to the “dependencies” keyword.
......
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)
===========================================
......
......@@ -104,13 +104,13 @@ If you want a certain version (e.g. 5.x) , then add `--single-branch --branch 5.
If you want to compile for MATLAB, please run the following (after adapting the path to MATLAB):
```sh
meson setup -Dmatlab_path=/usr/local/MATLAB/R2023b -Dbuildtype=debugoptimized build-matlab
meson setup -Dmatlab_path=/usr/local/MATLAB/R2023b --buildtype=debugoptimized build-matlab
```
The build directory will thus be `build-matlab`.
Or for Octave:
```sh
meson setup -Dbuild_for=octave -Dbuildtype=debugoptimized build-octave
meson setup -Dbuild_for=octave --buildtype=debugoptimized build-octave
```
The build directory will thus be `build-octave`.
......@@ -273,7 +273,7 @@ Now use the following commands if using MATLAB (adapt them for Octave, see above
cd /home/$USER/dynare
git clone --recurse-submodules https://git.dynare.org/dynare/dynare.git unstable
cd unstable
meson setup -Dmatlab_path=/usr/local/MATLAB/R2023b -Dfortran_args="[ '-B', '/home/$USER/dynare/slicot']" -Dbuildtype=debugoptimized build-matlab
meson setup -Dmatlab_path=/usr/local/MATLAB/R2023b -Dfortran_args="[ '-B', '/home/$USER/dynare/slicot']" --buildtype=debugoptimized build-matlab
meson compile -C build-matlab
```
......@@ -318,7 +318,7 @@ cd dynare
```
- Configure Dynare from the source directory (adjust `matlab_path` if you use a different version than R2024a):
```sh
meson setup -Dmatlab_path=/usr/local/MATLAB/R2024a -Dbuildtype=debugoptimized build-matlab
meson setup -Dmatlab_path=/usr/local/MATLAB/R2024a --buildtype=debugoptimized build-matlab
```
- Compile:
```sh
......@@ -362,7 +362,7 @@ cd dynare
```
- Configure Dynare from the source directory:
```sh
meson setup -Dmatlab_path=<…> -Dbuildtype=debugoptimized -Dprefer_static=true -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
......@@ -520,7 +520,7 @@ If you want a certain version (e.g. 5.x) , then add `--single-branch --branch 5.
```sh
export BUILDDIR=build-matlab
export MATLABPATH=/Applications/MATLAB_R2023b.app
arch -$ARCH meson setup --native-file macOS/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH -Dbuildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
arch -$ARCH meson setup --native-file macOS/homebrew-native-$ARCH.ini -Dmatlab_path=$MATLABPATH --buildtype=debugoptimized -Dfortran_args="['-B','$DYNAREDIR/slicot/lib']" $BUILDDIR
```
where you need to adapt the path to MATLAB.
Similarly, if you want to compile for Octave, replace the `-Dmatlab_path` option by `-Dbuild_for=octave`, and change the build directory to `build-octave`.
......
......@@ -65,7 +65,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.
......
......@@ -8,14 +8,14 @@ Software requirements
=====================
Packaged versions of Dynare are available for Windows (10 and 11), several
GNU/Linux distributions (Debian, Ubuntu, Linux Mint, Arch Linux), macOS (13
Ventura), and FreeBSD. Dynare should work on other systems, but some
GNU/Linux distributions (Debian, Ubuntu, Linux Mint, Arch Linux), macOS (15
“Sequoia”), and FreeBSD. Dynare should work on other systems, but some
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.
......@@ -23,8 +23,17 @@ In order to run Dynare, you need one of the following:
The following optional extensions are also useful to benefit from
extra features, but are in no way required:
* If under MATLAB: the Optimization Toolbox, the Statistics Toolbox,
the Control System Toolbox;
* If under MATLAB: the
* Optimization Toolbox (providing various optimizers
like ``fminsearch``, ``fmincon``, or ``fminunc``, used in e.g. ``mode_compute``,
``opt_algo`` or ``ALGO``),
* Statistics Toolbox (for faster and sometimes more robust implementations of
statistical distributions),
* Global Optimization Toolbox (for ``particleswarm`` and ``simulannealbnd``, used in
e.g. ``mode_compute``, ``opt_algo`` or ``ALGO``)
* Control System Toolbox (for the Lyapunov solver ``dlyapchol`` triggered with ``lyapunov=square_root_solver``)
* Parallel Computing Toolbox (to speed up the ``dime`` sampler)
* If under Octave, the following `Octave-Forge`_ packages: ``optim``, ``io``,
``control``.
......@@ -91,6 +100,18 @@ 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
^^^^^^^^^^^
......@@ -100,15 +121,6 @@ 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`).
......@@ -133,6 +145,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
----------
......@@ -325,3 +339,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
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/*
......
......@@ -70,7 +70,7 @@ ln -s "$BREWDIR"/opt/gcc/lib/gcc/"$GCC_VERSION"/libquadmath.a "$QUADMATH_DIR"
cd "$ROOTDIR"
# NB: the addition of -Wl,-ld_classic is a workaround for https://github.com/mesonbuild/meson/issues/12282 (see also the native file)
common_meson_opts=(-Dbuild_for=matlab -Dbuildtype=release -Dprefer_static=true -Dfortran_args="[ '-B', '$LIB64/Slicot/' ]" \
common_meson_opts=(-Dbuild_for=matlab --buildtype=release --prefer-static -Dfortran_args="[ '-B', '$LIB64/Slicot/' ]" \
-Dc_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dcpp_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" -Dfortran_link_args="[ '-Wl,-ld_classic', '-L$QUADMATH_DIR' ]" \
--native-file macOS/homebrew-native-$PKG_ARCH.ini)
......
......@@ -15,7 +15,7 @@ function write(M_)
% REMARKS
% - The trends are assumed to be multiplicative.
% Copyright © 2019-2023 Dynare Team
% Copyright © 2019-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -84,37 +84,40 @@ fprintf(fid, 'y = z(1:%u);\n\n', M_.endo_nbr);
fprintf(fid, 'g = z(%u:%u);\n', M_.endo_nbr+1, 2*M_.endo_nbr);
% Define the point where the dynamic model is to be evaluated.
fprintf(fid, 'Y = zeros(%u, 1);\n', 2*(n0+n1+n2));
% In period t, then in period t+1
fprintf(fid, 'Y0 = NaN(%u, 1);\n', 3*M_.endo_nbr);
fprintf(fid, 'Y1 = NaN(%u, 1);\n', 3*M_.endo_nbr);
for i=1:length(I0) % period t equations, lagged variables.
if I0(i)
fprintf(fid, 'Y(%u) = y(%u);\n', I0(i), i);
fprintf(fid, 'Y0(%u) = y(%u);\n', i+(purely_forward_model*M_.endo_nbr), i);
end
end
for i=1:length(I1) % period t equations, current variables.
if I1(i)
fprintf(fid, 'Y(%u) = y(%u)*g(%u);\n', I1(i), i, i);
fprintf(fid, 'Y0(%u) = y(%u)*g(%u);\n', i+M_.endo_nbr+(purely_forward_model*M_.endo_nbr), i, i);
end
end
for i=1:length(I2) % period t equations, leaded variables.
if I2(i)
fprintf(fid, 'Y(%u) = y(%u)*g(%u)*g(%u);\n', I2(i), i, i, i);
fprintf(fid, 'Y0(%u) = y(%u)*g(%u)*g(%u);\n', i+2*M_.endo_nbr, i, i, i);
end
end
for i=1:length(I0) % period t+1 equations lagged variables.
if I0(i)
fprintf(fid, 'Y(%u) = y(%u)*g(%u);\n', n0+n1+n2+I0(i), i, i);
fprintf(fid, 'Y1(%u) = y(%u)*g(%u);\n', i+(purely_forward_model*M_.endo_nbr), i, i);
end
end
for i=1:length(I1) % period t+1 equations current variables.
if I1(i)
fprintf(fid, 'Y(%u) = y(%u)*g(%u)*g(%u);\n', n0+n1+n2+I1(i), i, i, i);
fprintf(fid, 'Y1(%u) = y(%u)*g(%u)*g(%u);\n', i+M_.endo_nbr+(purely_forward_model*M_.endo_nbr), i, i, i);
end
end
for i=1:length(I2) % period t+1 equations leaded variables.
if I2(i)
fprintf(fid, 'Y(%u) = y(%u)*g(%u)*g(%u)*g(%u);\n', n0+n1+n2+I2(i), i, i, i, i);
fprintf(fid, 'Y1(%u) = y(%u)*g(%u)*g(%u)*g(%u);\n', i+2*M_.endo_nbr, i, i, i, i);
end
end
fprintf(fid, '\n');
% Define the vector of parameters.
......@@ -131,19 +134,36 @@ fprintf(fid, 'F = NaN(%u, 1);\n', 2*M_.endo_nbr);
fprintf(fid, 'x = zeros(1, %u);\n\n', M_.exo_nbr);
% Evaluate the residuals and jacobian of the dynamic model in periods t and t+1.
fprintf(fid, '[F(1:%u), T0_order, T0] = %s.sparse.dynamic_resid(Y0, x, p, y);\n', M_.endo_nbr, M_.fname);
fprintf(fid, '[F(%u:%u), T1_order, T1] = %s.sparse.dynamic_resid(Y1, x, p, y);\n', M_.endo_nbr+1, 2*M_.endo_nbr, M_.fname);
fprintf(fid, 'if nargout>1\n');
fprintf(fid, ' sparse_rowval = [');
fprintf(fid, '%u ', M_.dynamic_g1_sparse_rowval);
fprintf(fid, '];\n');
fprintf(fid, ' sparse_colval = [');
fprintf(fid, '%u ', M_.dynamic_g1_sparse_colval);
fprintf(fid, '];\n');
fprintf(fid, ' sparse_colptr = [');
fprintf(fid, '%u ', M_.dynamic_g1_sparse_colptr);
fprintf(fid, '];\n');
fprintf(fid, ' J0 = %s.sparse.dynamic_g1(Y0, x, p, y, sparse_rowval, sparse_colval, sparse_colptr, T0_order, T0);\n', M_.fname);
fprintf(fid, ' J1 = %s.sparse.dynamic_g1(Y1, x, p, y, sparse_rowval, sparse_colval, sparse_colptr, T1_order, T1);\n', M_.fname);
% Transform back the Jacobians J0 and J1 in the legacy format (non-sparse)
% NB: it is probably possible to simplify the rest of this file, but maintaining
% decent performance does not seem straightforward.
lli = find(M_.lead_lag_incidence');
if purely_forward_model
lli = lli + M_.endo_nbr;
end
fprintf(fid, ' lli = [');
fprintf(fid, '%u ', lli);
fprintf(fid, '];\n');
fprintf(fid, ' J = zeros(%u, %u);\n', 2*M_.endo_nbr, n0+n1+n2+M_.endo_nbr);
fprintf(fid, ' [F(1:%u), tmp] = %s.dynamic(Y(1:%u), x, p, y, 1);\n', M_.endo_nbr, M_.fname, n0+n1+n2);
fprintf(fid, ' J(1:%u,1:%u) = tmp(:,1:%u);\n', M_.endo_nbr, n0+n1+n2, n0+n1+n2);
fprintf(fid, ' [F(%u:%u), tmp] = %s.dynamic(Y(1+%u:%u), x, p, y, 1);\n', M_.endo_nbr+1, 2*M_.endo_nbr, M_.fname, n0+n1+n2, 2*(n0+n1+n2));
fprintf(fid, ' J(%u:%u,1:%u) = tmp(:,1:%u);\n', M_.endo_nbr+1, 2*M_.endo_nbr, n0+n1+n2, n0+n1+n2);
fprintf(fid, 'else\n');
fprintf(fid, ' F(1:%u) = %s.dynamic(Y(1:%u), x, p, y, 1);\n', M_.endo_nbr, M_.fname, n0+n1+n2);
fprintf(fid, ' F(%u:%u) = %s.dynamic(Y(1+%u:%u), x, p, y, 1);\n', M_.endo_nbr+1, 2*M_.endo_nbr, M_.fname, n0+n1+n2, 2*(n0+n1+n2));
fprintf(fid, 'end\n\n');
fprintf(fid, ' J(1:%u,1:%u) = full(J0(:,lli));\n', M_.endo_nbr, n0+n1+n2);
fprintf(fid, ' J(%u:%u,1:%u) = full(J1(:,lli));\n', M_.endo_nbr+1, 2*M_.endo_nbr, n0+n1+n2);
% Compute the jacobian if required.
fprintf(fid, 'if nargout>1\n');
fprintf(fid, ' JAC = zeros(%u,%u);\n', 2*M_.endo_nbr, 2*M_.endo_nbr);
% Compute the derivatives of the first block of equations (period t)
......@@ -279,7 +299,7 @@ else
end
% Compute the derivatives of the second block of equations (period t+1)
% with respect to the endogenous variables.
% with respect to the growth factors.
if purely_backward_model || purely_forward_model
for i=M_.eq_nbr+1:2*M_.eq_nbr
for j=1:M_.endo_nbr
......@@ -328,4 +348,4 @@ end
fprintf(fid, ' JAC(:,%u:%u) = J(:,%u:%u);\n', M_.endo_nbr+1, 2*M_.endo_nbr, n0+n1+n2+1, n0+n1+n2+M_.endo_nbr);
fprintf(fid,'end\n');
fclose(fid);
\ No newline at end of file
fclose(fid);
......@@ -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);
......
......@@ -13,7 +13,7 @@ function run(json)
% SPECIAL REQUIREMENTS
% none
% Copyright © 2019-2023 Dynare Team
% Copyright © 2019-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -103,7 +103,6 @@ if ~isempty(jm.anticipated_transitory_shocks)
'periods', s.start_date:s.end_date, ...
'value', s.value)];
end
M_.exo_det_length = 0;
end
%% Make unanticipated shock map
......
......@@ -13,7 +13,7 @@ function read(json)
% SPECIAL REQUIREMENTS
% none
% Copyright © 2019-2020 Dynare Team
% Copyright © 2019-2024 Dynare Team
%
% This file is part of Dynare.
%
......@@ -36,7 +36,6 @@ global M_ options_ oo_
jm = loadjson_(json, 'SimplifyCell', 1);
data2json=struct();
M_.exo_det_length = 0;
for nshocks = 1:length(jm.stochasticshocksdescription)
covartype=jm.stochasticshocksdescription{nshocks}.shockattributevalue;
thisshock=(jm.stochasticshocksdescription{nshocks}.shockindex)+1;
......
% 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
function err = linear_approximation_accuracy(options_, M_, oo_)
% Evaluates the accuracy of the linear approximation when solving perfect foresight models, by
% reporting the max absolute value of the dynamic residuals.
%
% INPUTS
% - options_ [struct] contains various options.
% - M_ [struct] contains a description of the model.
% - oo_ [struct] contains results.
%
% OUTPUTS
% - err [double] n*1 vector, evaluation of the accuracy (n is the number of equations).
% Copyright © 2015-2017 Dynare Team
% Copyright © 2025 Dynare Team
%
% This file is part of Dynare.
%
......@@ -26,30 +14,24 @@ function err = linear_approximation_accuracy(options_, M_, oo_)
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
lead_lag_incidence = M_.lead_lag_incidence;
ny = M_.endo_nbr;
maximum_lag = M_.maximum_lag;
periods = options_.periods;
steady_state = oo_.steady_state;
params = M_.params;
endo_simul = oo_.endo_simul;
exo_simul = oo_.exo_simul;
model_dynamic = str2func([M_.fname,'.dynamic']);
residuals = zeros(ny,periods);
Y = endo_simul(:);
i_cols = find(lead_lag_incidence')+(maximum_lag-1)*ny;
for it = (maximum_lag+1):(maximum_lag+periods)
residuals(:,it-1) = model_dynamic(Y(i_cols), exo_simul, params, steady_state,it);
i_cols = i_cols + ny;
end
err = transpose(max(abs(transpose(residuals))));
\ No newline at end of file
%
% 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