diff --git a/doc/manual.xml b/doc/manual.xml index fd7229291611bce07733dd829efce8ba5f133e53..64f360aa85e31095cba34092dee4fa354019869c 100644 --- a/doc/manual.xml +++ b/doc/manual.xml @@ -14,7 +14,7 @@ </address> </author> -<copyright><year>1996, 2008</year><holder> Dynare Team</holder> +<copyright><year>1996-2008</year><holder>Dynare Team</holder> </copyright> <legalnotice> @@ -2677,10 +2677,92 @@ In Matlab, variables saved with the <command>dynasave</command> command can be r <sect1><title>Misc commands</title> <itemizedlist> + <listitem><para><xref linkend="save_params_and_steady_state"/></para></listitem> + <listitem><para><xref linkend="load_params_and_steady_state"/></para></listitem> <listitem><para><xref linkend="bvar_density"/></para></listitem> <listitem><para><xref linkend="bvar_forecast"/></para></listitem> </itemizedlist> +<refentry id="save_params_and_steady_state"> + <refmeta> + <refentrytitle>save_params_and_steady_state</refentrytitle> + </refmeta> + + <refnamediv> + <refname>save_params_and_steady_state</refname> + <refpurpose>saves the values of the parameters and of the computed steady-state in a file</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>save_params_and_steady_state</command> + <arg choice="plain"><replaceable>FILENAME</replaceable></arg> + <arg choice="plain">;</arg> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + <para>For all parameters, endogenous and exogenous variables, stores + their value in a file, using a simple name/value associative array.</para> + <itemizedlist> + <listitem><para>for parameters, the value is taken from the last parameter + initialization</para></listitem> + <listitem><para>for exogenous, the value is taken from the last initval block</para></listitem> + <listitem><para>for endogenous, the value is taken from the last steady state computation + (or, if no steady state has been computed, from the last initval block)</para></listitem> + </itemizedlist> + <para>Note that no variable type is stored in the file, so that the values + can be reloaded (with <xref linkend="load_params_and_steady_state"/>) in a setup where + the variable types are different.</para> + <para>The typical usage of this function is to compute the steady-state of a + model by calibrating the steady-state value of some endogenous variables (which implies that some parameters must be endogeneized + during the steady-state computation).</para> + <para>You would then write a first .mod file which computes the steady-state and saves the result of the + computation at the end of the file, using <command>save_params_and_steady_state</command>.</para> + <para>In a second file designed to perform the actual simulations, you would use <xref linkend="load_params_and_steady_state"/> just after + your variable declarations, in order to load the steady-state previously computed (including the parameters which had been + endogeneized during the steady-state computation).</para> + <para>The need for two separate .mod files arises from the fact that the variable declarations differ between the files for + steady-state calibration and for simulation (the set of endogenous and parameters differ between the two); this leads + to different <xref linkend="var"/> and <xref linkend="parameters"/> statements.</para> + <para>Also note that you can take advantage of the <xref linkend="include"/> directive to share the model equations between the two files.</para> + </refsect1> +</refentry> + +<refentry id="load_params_and_steady_state"> + <refmeta> + <refentrytitle>load_params_and_steady_state</refentrytitle> + </refmeta> + + <refnamediv> + <refname>load_params_and_steady_state</refname> + <refpurpose>loads the values of the parameters and of the steady-state from a file</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <cmdsynopsis> + <command>load_params_and_steady_state</command> + <arg choice="plain"><replaceable>FILENAME</replaceable></arg> + <arg choice="plain">;</arg> + </cmdsynopsis> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + <para>For all parameters, endogenous and exogenous variables, loads + their value from a file created with save_params_and_steady_state.</para> + <itemizedlist> + <listitem><para>for parameters, their value will be initialized as if they + had been calibrated in the .mod file</para></listitem> + <listitem><para>for endogenous and exogenous, their value will be initialized + as they would have been from an initval block</para></listitem> + </itemizedlist> + <para>This function is used in conjunction with <xref linkend="save_params_and_steady_state"/>; + see the documentation of that function for more information.</para> + </refsect1> +</refentry> + <refentry id="bvar_density"> <refmeta> <refentrytitle>bvar_density</refentrytitle> diff --git a/matlab/load_params_and_steady_state.m b/matlab/load_params_and_steady_state.m new file mode 100644 index 0000000000000000000000000000000000000000..ac023d5899a14da20395b9c76120dc712c66f537 --- /dev/null +++ b/matlab/load_params_and_steady_state.m @@ -0,0 +1,65 @@ +function load_params_and_steady_state(filename) +% function load_params_and_steady_state(filename) +% +% For all parameters, endogenous and exogenous variables, loads +% their value from a file created with save_params_and_steady_state. +% * for parameters, their value will be initialized as if they +% had been calibrated in the .mod file +% * for endogenous and exogenous, their value will be initialized +% as they would have been from an initval block +% +% INPUTS +% filename: where to load from the saved values +% +% OUTPUTS +% none +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2008 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 <http://www.gnu.org/licenses/>. + + global M_ oo_ + + load(filename); + + if ~exist('stored_values') + error('LOAD_PARAMS_AND_INITVAL: filename provided was probably not created by save_params_and_initval') + end + + names = fieldnames(stored_values); + + for i = 1:size(names,1) + field = names{i}; + j = strmatch(field, M_.param_names, 'exact'); + if ~isempty(j) + M_.params(j) = stored_values.(field); + else + j = strmatch(field, M_.endo_names, 'exact'); + if ~isempty(j) + oo_.steady_state(j) = stored_values.(field); + else + j = strmatch(field, M_.exo_names, 'exact'); + if ~isempty(j) + oo_.exo_steady_state(j) = stored_values.(field); + else + warning(['LOAD_PARAMS_AND_INITVAL: Unknown symbol name: ', field]) + end + end + end + end diff --git a/matlab/save_params_and_steady_state.m b/matlab/save_params_and_steady_state.m new file mode 100644 index 0000000000000000000000000000000000000000..6c3c29fe5aba7bf59e25832ab1306f516b515443 --- /dev/null +++ b/matlab/save_params_and_steady_state.m @@ -0,0 +1,56 @@ +function save_params_and_steady_state(filename) +% function save_params_and_steady_state(filename) +% +% For all parameters, endogenous and exogenous variables, stores +% their value in a file, using a simple name/value associative array. +% * for parameters, the value is taken from the last parameter +% initialization +% * for exogenous, the value is taken from the last initval block +% * for endogenous, the value is taken from the last steady state +% computation (or, if no steady state has been computed, from the +% last initval block) +% Note that no variable type is stored in the file, so that the values +% can be reloaded (with load_params_and_steady_state) in a setup where +% the variable types are different. +% +% INPUTS +% filename: where to store the saved values +% +% OUTPUTS +% none +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2008 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 <http://www.gnu.org/licenses/>. + + global M_ oo_ + + for i = 1:M_.param_nbr + stored_values.(deblank(M_.param_names(i,:))) = M_.params(i); + end + + for i = 1:M_.endo_nbr + stored_values.(deblank(M_.endo_names(i,:))) = oo_.steady_state(i); + end + + for i = 1:M_.exo_nbr + stored_values.(deblank(M_.exo_names(i,:))) = oo_.exo_steady_state(i); + end + + save(filename, 'stored_values');