diff --git a/doc/manual.xml b/doc/manual.xml index fd7229291..64f360aa8 100644 --- a/doc/manual.xml +++ b/doc/manual.xml @@ -14,7 +14,7 @@ -1996, 2008 Dynare Team +1996-2008Dynare Team @@ -2677,10 +2677,92 @@ In Matlab, variables saved with the dynasave command can be r Misc commands + + + + + save_params_and_steady_state + + + + save_params_and_steady_state + saves the values of the parameters and of the computed steady-state in a file + + + + + save_params_and_steady_state + FILENAME + ; + + + + + Description + 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 ) in a setup where + the variable types are different. + 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). + 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 save_params_and_steady_state. + In a second file designed to perform the actual simulations, you would use 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). + 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 and statements. + Also note that you can take advantage of the directive to share the model equations between the two files. + + + + + + load_params_and_steady_state + + + + load_params_and_steady_state + loads the values of the parameters and of the steady-state from a file + + + + + load_params_and_steady_state + FILENAME + ; + + + + + Description + 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 + + This function is used in conjunction with ; + see the documentation of that function for more information. + + + bvar_density diff --git a/matlab/load_params_and_steady_state.m b/matlab/load_params_and_steady_state.m new file mode 100644 index 000000000..ac023d589 --- /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 . + + 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 000000000..6c3c29fe5 --- /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 . + + 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');