Rename ys0_ into oo_.initial_steady_state and ex0_ into oo_.initial_exo_steady_state

Also document these variables.
kalman-mex
Sébastien Villemot 2023-10-23 19:07:26 +02:00
parent 1334ae045a
commit 88ce107466
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
10 changed files with 61 additions and 48 deletions

View File

@ -4015,6 +4015,23 @@ speed-up on large models.
``1+M_.maximum_lag``, and the total number of rows is
``M_.maximum_lag+periods+M_.maximum_lead``.
.. matvar:: oo_.initial_steady_state
If a permanent shock is simulated through the use of both ``initval`` and
``endval`` blocks, this variable contains the initial steady state, as
determined by the ``initval`` block (when followed by a ``steady``
command). This variable has the same structure as :mvar:`oo_.steady_state`
(and this latter variable contains the terminal steady state, if the
``endval`` block is followed by a ``steady`` command).
.. matvar:: oo_.initial_exo_steady_state
If a permanent shock is simulated through the use of both ``initval`` and
``endval`` blocks, this variable contains the initial steady state of the
exogenous variables, as specified in the ``initval`` block. This variable
has the same structure as :mvar:`oo_.exo_steady_state` (and this latter
variable contains the terminal steady state of the exogenous variables).
.. matvar:: M_.maximum_lag
|br| The maximum number of lags in the model. Note that this value is

View File

@ -30,7 +30,7 @@ function run(json)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ options_ oo_ ys0_ ex0_
global M_ options_ oo_
%% Check Inputs
if nargin ~= 1 || ~ischar(json)
@ -64,12 +64,12 @@ end
%% ENDVAL instructions
% initialize exogenous shocks to zero and compute final ss unless there is a permanent shock
ys0_ = [];
ex0_ = [];
oo_.initial_steady_state = [];
oo_.initial_exo_steady_state = [];
M_.det_shocks = [];
if ~isempty(jm.anticipated_permanent_shocks) || ~isempty(jm.endval_endo)
ys0_= oo_.steady_state;
ex0_ = oo_.exo_steady_state;
oo_.initial_steady_state= oo_.steady_state;
oo_.initial_exo_steady_state = oo_.exo_steady_state;
for i = 1:length(jm.endval_endo)
oo_.steady_state(jm.endval_endo(i).id) = jm.endval_endo(i).value;
end
@ -152,10 +152,10 @@ end
% surprise shocks present
% in case there are unanticipated shocks...
if isempty(ys0_)
if isempty(oo_.initial_steady_state)
yy = oo_.steady_state;
else
yy = ys0_;
yy = oo_.initial_steady_state;
end
if mapkeys(1) ~= 1

View File

@ -11,7 +11,7 @@ function global_initialization()
% SPECIAL REQUIREMENTS
% none
% Copyright © 2003-2018 Dynare Team
% Copyright © 2003-2023 Dynare Team
%
% This file is part of Dynare.
%
@ -28,7 +28,7 @@ function global_initialization()
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global oo_ M_ options_ estim_params_ bayestopt_ estimation_info ex0_ ys0_ dataset_ dataset_info
global oo_ M_ options_ estim_params_ bayestopt_ estimation_info dataset_ dataset_info
estim_params_ = [];
bayestopt_ = [];
dataset_=[];
@ -86,13 +86,13 @@ estimation_info.joint_parameter = {'index','domain','interval','mean','median','
oo_.exo_simul = [];
oo_.endo_simul = [];
ys0_ = [];
ex0_ = [];
oo_.dr = [];
oo_.exo_steady_state = [];
oo_.exo_det_steady_state = [];
oo_.exo_det_simul = [];
oo_.initval_series = dseries();
oo_.initial_steady_state = [];
oo_.initial_exo_steady_state = [];
oo_.gui.ran_estimation = false;
oo_.gui.ran_stoch_simul = false;

View File

@ -10,7 +10,7 @@ function oo_ = make_ex_(M_, options_, oo_)
% OUTPUTS
% - oo_ [struct] Updated dynare results structure
% Copyright © 1996-2021 Dynare Team
% Copyright © 1996-2023 Dynare Team
%
% This file is part of Dynare.
%
@ -27,8 +27,6 @@ function oo_ = make_ex_(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global ex0_
if isempty(oo_.exo_steady_state)
oo_.exo_steady_state = zeros(M_.exo_nbr,1);
end
@ -39,13 +37,13 @@ end
% Initialize oo_.exo_simul
if isempty(oo_.initval_series)
if isempty(M_.exo_histval)
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1);
else
oo_.exo_simul = [ repmat(ex0_',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ];
oo_.exo_simul = [ repmat(oo_.initial_exo_steady_state',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ];
end
else
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
oo_.exo_simul = [M_.exo_histval'; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1)];
else
error('histval and endval cannot be used simultaneously')
@ -92,10 +90,10 @@ if isfield(M_, 'det_shocks')
case 'multiply_steady_state'
oo_.exo_simul(k,ivar) = oo_.exo_steady_state(ivar) * v;
case 'multiply_initial_steady_state'
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
error('Option relative_to_initval of mshocks block cannot be used without an endval block')
end
oo_.exo_simul(k,ivar) = ex0_(ivar) * v;
oo_.exo_simul(k,ivar) = oo_.initial_exo_steady_state(ivar) * v;
end
else
switch M_.det_shocks(i).type

View File

@ -10,7 +10,7 @@ function oo_=make_y_(M_, options_, oo_)
% OUTPUTS
% - oo_ [struct] Updated dynare results structure
% Copyright © 1996-2020 Dynare Team
% Copyright © 1996-2023 Dynare Team
%
% This file is part of Dynare.
%
@ -27,21 +27,19 @@ function oo_=make_y_(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global ys0_
if isempty(oo_.steady_state)
oo_.steady_state = zeros(M_.endo_nbr,1);
end
if isempty(oo_.initval_series)
if isempty(M_.endo_histval)
if isempty(ys0_)
if isempty(oo_.initial_steady_state)
oo_.endo_simul = repmat(oo_.steady_state, 1, M_.maximum_lag+options_.periods+M_.maximum_lead);
else
oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) repmat(oo_.steady_state, 1,options_.periods+M_.maximum_lead)];
oo_.endo_simul = [repmat(oo_.initial_steady_state, 1, M_.maximum_lag) repmat(oo_.steady_state, 1,options_.periods+M_.maximum_lead)];
end
else
if ~isempty(ys0_)
if ~isempty(oo_.initial_steady_state)
error('histval and endval cannot be used simultaneously')
end
% the first NaNs take care of the case where there are lags > 1 on
@ -54,7 +52,7 @@ else
oo_.endo_simul = y(M_.orig_maximum_lag - M_.maximum_lag + 1:M_.orig_maximum_lag + options_.periods + ...
M_.maximum_lead, :)';
if ~isempty(M_.endo_histval)
if ~isempty(ys0_)
if ~isempty(oo_.initial_steady_state)
error('histval and endval cannot be used simultaneously')
end
oo_.endo_simul(:,1:M_.maximum_lag) ...

View File

@ -31,7 +31,7 @@ function perfect_foresight_solver(no_error_if_learnt_in_is_present)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ options_ oo_ ys0_ ex0_
global M_ options_ oo_
check_input_arguments(options_, M_, oo_);
@ -103,13 +103,13 @@ lastperiods = M_.maximum_lag+periods+(1:M_.maximum_lead);
% Create base scenario for homotopy, which corresponds to the initial steady
% state (i.e. a known solution to the perfect foresight problem, assuming that
% oo_.steady_state/ys0_ effectively contains a steady state)
if isempty(ys0_)
% oo_.steady_state/oo_.initial_steady_state effectively contains a steady state)
if isempty(oo_.initial_steady_state)
endobase = repmat(oo_.steady_state, 1,M_.maximum_lag+periods+M_.maximum_lead);
exobase = repmat(oo_.exo_steady_state',M_.maximum_lag+periods+M_.maximum_lead,1);
else
endobase = repmat(ys0_, 1, M_.maximum_lag+periods+M_.maximum_lead);
exobase = repmat(ex0_', M_.maximum_lag+periods+M_.maximum_lead, 1);
endobase = repmat(oo_.initial_steady_state, 1, M_.maximum_lag+periods+M_.maximum_lead);
exobase = repmat(oo_.initial_exo_steady_state', M_.maximum_lag+periods+M_.maximum_lead, 1);
end
% Determine whether to recompute the final steady state (either because
@ -117,7 +117,7 @@ end
% terminal condition is a steady state)
if options_.simul.endval_steady
recompute_final_steady_state = true;
elseif ~isempty(ys0_)
elseif ~isempty(oo_.initial_steady_state)
recompute_final_steady_state = true;
for j = lastperiods
endval_resid = evaluate_static_model(oo_.endo_simul(:,j), oo_.exo_simul(j,:)', M_.params, M_, options_);
@ -398,7 +398,7 @@ function [steady_success, endo_simul, exo_simul, steady_state, exo_steady_state]
% steady_state [vector] steady state of endogenous corresponding to the scenario (equal to the input if terminal steady state not recomputed)
% exo_steady_state [vector] steady state of exogenous corresponding to the scenario (equal to the input if terminal steady state not recomputed)
global M_ options_ oo_ ys0_
global M_ options_ oo_
% Compute convex combination for the path of exogenous
exo_simul = exoorig*share + exobase*(1-share);
@ -432,10 +432,10 @@ if recompute_final_steady_state
[endo_simul(:, j), ~, info] = evaluate_steady_state(endo_simul(:, j), exo_simul(j, :)', M_, options_, true);
if info(1)
% If this fails, then try again using the initial steady state as guess value
if isempty(ys0_)
if isempty(oo_.initial_steady_state)
guess_value = oo_.steady_state;
else
guess_value = ys0_;
guess_value = oo_.initial_steady_state;
end
[endo_simul(:, j), ~, info] = evaluate_steady_state(guess_value, exo_simul(j, :)', M_, options_, true);
if info(1)

View File

@ -17,7 +17,7 @@ function perfect_foresight_with_expectation_errors_setup
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ oo_ options_ ys0_ ex0_
global M_ oo_ options_
if ~isempty(M_.endo_histval)
error('perfect_foresight_with_expectation_errors_setup: cannot be used in conjunction with histval')
@ -33,7 +33,7 @@ oo_.pfwee.terminal_info = NaN(M_.exo_nbr, periods); % 2nd dimension is informati
oo_.pfwee.shocks_info = NaN(M_.exo_nbr, periods, periods); % 2nd dimension is real time, 3rd dimension is informational time
if exist(options_.datafile, 'file')
if ~isempty(M_.det_shocks) || ~isempty(M_.learnt_shocks) || ~isempty(ys0_) || ~isempty(M_.learnt_endval)
if ~isempty(M_.det_shocks) || ~isempty(M_.learnt_shocks) || ~isempty(oo_.initial_steady_state) || ~isempty(M_.learnt_endval)
warning('perfect_foresight_with_expectation_errors_setup: since you passed the datafile option, the contents of shocks and endval blocks will be ignored')
end
%% Read CSV file
@ -81,10 +81,10 @@ else
case 'multiply_steady_state'
oo_.pfwee.shocks_info(exo_id, prds, 1) = oo_.exo_steady_state(exo_id) * v;
case 'multiply_initial_steady_state'
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
error('Option relative_to_initval of mshocks block cannot be used without an endval block')
end
oo_.pfwee.shocks_info(exo_id, prds, 1) = ex0_(exo_id) * v;
oo_.pfwee.shocks_info(exo_id, prds, 1) = oo_.initial_exo_steady_state(exo_id) * v;
end
end
end
@ -135,13 +135,13 @@ else
end
% Build initial paths for endos and exos (only initial conditions are set, the rest is NaN)
if isempty(ys0_)
if isempty(oo_.initial_steady_state)
oo_.endo_simul = repmat(oo_.steady_state, 1, M_.maximum_lag+periods+M_.maximum_lead);
else
oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) repmat(oo_.steady_state, 1, periods+M_.maximum_lead)];
oo_.endo_simul = [repmat(oo_.initial_steady_state, 1, M_.maximum_lag) repmat(oo_.steady_state, 1, periods+M_.maximum_lead)];
end
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
oo_.exo_simul = repmat(oo_.exo_steady_state', M_.maximum_lag+periods+M_.maximum_lead, 1);
else
oo_.exo_simul = [repmat(ex0_', M_.maximum_lag, 1); repmat(oo_.exo_steady_state', periods+M_.maximum_lead, 1)];
oo_.exo_simul = [repmat(oo_.initial_exo_steady_state', M_.maximum_lag, 1); repmat(oo_.exo_steady_state', periods+M_.maximum_lead, 1)];
end

View File

@ -17,7 +17,7 @@ function perfect_foresight_with_expectation_errors_solver
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ oo_ options_ ys0_
global M_ oo_ options_
% Same for periods (it will be modified before calling perfect_foresight_solver if constants_simulation_length option is false)
periods = options_.periods;

View File

@ -28,7 +28,7 @@ function steady()
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ oo_ options_ ex0_
global M_ oo_ options_
test_for_deep_parameters_calibration(M_);
@ -64,12 +64,12 @@ if options_.homotopy_mode ~= 0
% If the “from_initval_to_endval” option was passed to the “homotopy_setup” block, add the relevant homotopy information
if options_.homotopy_from_initval_to_endval
if isempty(ex0_)
if isempty(oo_.initial_exo_steady_state)
error('HOMOTOPY_SETUP: the from_initval_to_endval option cannot be used without an endval block')
end
for i = 1:M_.exo_nbr
if ~any(hv(:,1)==1 & hv(:,2)==i) % Do not overwrite information manually specified by the user
hv = vertcat(hv, [ 1 i ex0_(i) oo_.exo_steady_state(i)]);
hv = vertcat(hv, [ 1 i oo_.initial_exo_steady_state(i) oo_.exo_steady_state(i)]);
end
end
end

@ -1 +1 @@
Subproject commit 6235e6907526d468e2c35f14c38db1e308698bc9
Subproject commit 9b50a8a159b7f0904809a726a55fcd1ad0e4acfb