2023-10-25 17:29:55 +02:00
|
|
|
function [steady_state, params, check] = dyn_ramsey_static(ys_init, exo_ss, M_, options_)
|
|
|
|
% [steady_state, params, check] = dyn_ramsey_static(ys_init, exo_ss, M_, options_)
|
2016-03-25 20:16:43 +01:00
|
|
|
% Computes the steady state for optimal policy
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
2023-03-28 19:22:23 +02:00
|
|
|
% When there is no steady state file, relies on the fact that Lagrange
|
|
|
|
% multipliers appear linearly in the system to be solved. Instead of directly
|
|
|
|
% solving for the Lagrange multipliers along with the other variables, the
|
|
|
|
% algorithms reduces the size of the problem by always computing the value of
|
|
|
|
% the multipliers that minimizes the residuals, given the other variables
|
|
|
|
% (using a minimum norm solution, easy to compute because of the linearity
|
|
|
|
% property).
|
2023-10-25 17:29:55 +02:00
|
|
|
%
|
2009-12-16 18:17:34 +01:00
|
|
|
% INPUTS
|
2016-03-25 20:16:43 +01:00
|
|
|
% ys_init: vector of endogenous variables or instruments
|
2023-06-07 17:18:18 +02:00
|
|
|
% exo_ss vector of exogenous steady state (incl. deterministic exogenous)
|
2023-10-25 17:29:55 +02:00
|
|
|
% M_: Dynare model structure
|
2016-03-25 20:16:43 +01:00
|
|
|
% options: Dynare options structure
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2009-12-16 18:17:34 +01:00
|
|
|
% OUTPUTS
|
2016-03-25 20:16:43 +01:00
|
|
|
% steady_state: steady state value
|
|
|
|
% params: parameters at steady state, potentially updated by
|
|
|
|
% steady_state file
|
2016-08-02 15:31:13 +02:00
|
|
|
% check: error indicator, 0 if everything is OK
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2023-01-10 16:05:33 +01:00
|
|
|
% Copyright © 2003-2023 Dynare Team
|
2009-12-16 18:17:34 +01:00
|
|
|
%
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2011-10-12 21:46:50 +02:00
|
|
|
|
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
params = M_.params;
|
2011-10-12 21:46:50 +02:00
|
|
|
check = 0;
|
2016-03-25 20:16:43 +01:00
|
|
|
options_.steadystate.nocheck = 1; %locally disable checking because Lagrange multipliers are not accounted for in evaluate_steady_state_file
|
2023-10-25 17:29:55 +02:00
|
|
|
nl_func = @(x) dyn_ramsey_static_1(x,exo_ss,ys_init,M_,options_);
|
2011-10-12 21:46:50 +02:00
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
if ~options_.steadystate_flag && check_static_model(ys_init,exo_ss,M_,options_)
|
2014-10-30 11:45:08 +01:00
|
|
|
steady_state = ys_init;
|
2014-03-11 13:22:04 +01:00
|
|
|
return
|
|
|
|
elseif options_.steadystate_flag
|
2011-10-12 21:46:50 +02:00
|
|
|
k_inst = [];
|
2012-04-21 21:16:57 +02:00
|
|
|
inst_nbr = size(options_.instruments,1);
|
2011-10-12 21:46:50 +02:00
|
|
|
for i = 1:inst_nbr
|
2023-10-25 17:29:55 +02:00
|
|
|
k_inst = [k_inst; strmatch(options_.instruments{i}, M_.endo_names, 'exact')];
|
2011-10-12 21:46:50 +02:00
|
|
|
end
|
|
|
|
if inst_nbr == 1
|
2015-05-25 10:06:13 +02:00
|
|
|
%solve for instrument, using univariate solver, starting at initial value for instrument
|
2016-08-02 17:09:18 +02:00
|
|
|
[inst_val, info1]= csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,options_.ramsey.maxit);
|
|
|
|
if info1==1 || info1==3
|
|
|
|
check=81;
|
|
|
|
end
|
|
|
|
if info1==4
|
|
|
|
check=87;
|
2017-05-16 15:10:20 +02:00
|
|
|
end
|
2011-10-12 21:46:50 +02:00
|
|
|
else
|
2015-05-26 15:50:55 +02:00
|
|
|
%solve for instrument, using multivariate solver, starting at
|
2023-03-28 19:22:23 +02:00
|
|
|
%initial value for instruments
|
2022-04-10 22:17:45 +02:00
|
|
|
o_jacobian_flag = options_.jacobian_flag;
|
|
|
|
options_.jacobian_flag = false;
|
|
|
|
[inst_val, errorflag] = dynare_solve(nl_func, ys_init(k_inst), options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, options_);
|
|
|
|
options_.jacobian_flag = o_jacobian_flag;
|
2022-04-10 15:51:55 +02:00
|
|
|
if errorflag
|
2016-08-02 17:09:18 +02:00
|
|
|
check=81;
|
|
|
|
end
|
2011-10-12 21:46:50 +02:00
|
|
|
end
|
2014-10-30 11:45:08 +01:00
|
|
|
ys_init(k_inst) = inst_val;
|
2023-10-25 17:29:55 +02:00
|
|
|
[xx,params] = evaluate_steady_state_file(ys_init,exo_ss,M_,options_,~options_.steadystate.nocheck); %run steady state file again to update parameters
|
2018-11-13 17:58:42 +01:00
|
|
|
[~,~,steady_state] = nl_func(inst_val); %compute and return steady state
|
2011-10-12 21:46:50 +02:00
|
|
|
else
|
2023-10-25 17:29:55 +02:00
|
|
|
xx = ys_init(1:M_.orig_endo_nbr);
|
2022-04-10 22:17:45 +02:00
|
|
|
o_jacobian_flag = options_.jacobian_flag;
|
|
|
|
options_.jacobian_flag = false;
|
|
|
|
[xx, errorflag] = dynare_solve(nl_func, xx, options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, options_);
|
|
|
|
options_.jacobian_flag = o_jacobian_flag;
|
2022-04-10 15:51:55 +02:00
|
|
|
if errorflag
|
2017-05-02 13:48:25 +02:00
|
|
|
check=81;
|
|
|
|
end
|
2018-11-13 17:58:42 +01:00
|
|
|
[~,~,steady_state] = nl_func(xx);
|
2011-10-12 21:46:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
function [resids,rJ,steady_state] = dyn_ramsey_static_1(x,exo_ss,ys_init,M_,options_)
|
2011-10-12 21:46:50 +02:00
|
|
|
resids = [];
|
|
|
|
rJ = [];
|
|
|
|
mult = [];
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
inst_nbr = M_.ramsey_orig_endo_nbr - M_.ramsey_orig_eq_nbr;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
|
|
|
if options_.steadystate_flag
|
|
|
|
k_inst = [];
|
2023-03-28 19:22:23 +02:00
|
|
|
for i = 1:size(options_.instruments,1)
|
2023-10-25 17:29:55 +02:00
|
|
|
k_inst = [k_inst; strmatch(options_.instruments{i}, M_.endo_names, 'exact')];
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2014-10-30 11:45:08 +01:00
|
|
|
ys_init(k_inst) = x; %set instrument, the only value required for steady state computation, to current value
|
2023-10-25 17:29:55 +02:00
|
|
|
[x,M_.params,check] = evaluate_steady_state_file(ys_init,... %returned x now has size endo_nbr as opposed to input size of n_instruments
|
2023-03-28 19:22:23 +02:00
|
|
|
exo_ss, ...
|
2023-10-25 17:29:55 +02:00
|
|
|
M_,options_,~options_.steadystate.nocheck);
|
|
|
|
if any(imag(x(1:M_.orig_endo_nbr))) %return with penalty
|
|
|
|
resids=ones(inst_nbr,1)+sum(abs(imag(x(1:M_.orig_endo_nbr)))); %return with penalty
|
|
|
|
steady_state=NaN(M_.endo_nbr,1);
|
2017-05-16 12:42:01 +02:00
|
|
|
return
|
2016-08-02 17:09:18 +02:00
|
|
|
end
|
2021-11-05 08:59:47 +01:00
|
|
|
if check(1) %return
|
2023-10-25 17:29:55 +02:00
|
|
|
resids=ones(inst_nbr,1)+sum(abs(x(1:M_.orig_endo_nbr))); %return with penalty
|
|
|
|
steady_state=NaN(M_.endo_nbr,1);
|
2020-03-06 18:55:01 +01:00
|
|
|
return
|
|
|
|
end
|
2011-10-12 21:46:50 +02:00
|
|
|
end
|
2011-07-24 20:52:28 +02:00
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
xx = zeros(M_.endo_nbr,1); %initialize steady state vector
|
|
|
|
xx(1:M_.orig_endo_nbr) = x(1:M_.orig_endo_nbr); %set values of original endogenous variables based on steady state file or initial value
|
2014-10-30 11:45:08 +01:00
|
|
|
|
2023-03-28 19:22:23 +02:00
|
|
|
% Determine whether other auxiliary variables will need to be updated
|
2023-10-25 17:29:55 +02:00
|
|
|
if any([M_.aux_vars.type] ~= 6) %auxiliary variables other than multipliers
|
2023-03-28 19:22:23 +02:00
|
|
|
needs_set_auxiliary_variables = true;
|
2023-10-25 17:29:55 +02:00
|
|
|
fh = str2func([M_.fname '.set_auxiliary_variables']);
|
|
|
|
s_a_v_func = @(z) fh(z, exo_ss, M_.params);
|
2012-02-02 12:04:15 +01:00
|
|
|
xx = s_a_v_func(xx);
|
2011-12-14 21:04:51 +01:00
|
|
|
else
|
2023-03-28 19:22:23 +02:00
|
|
|
needs_set_auxiliary_variables = false;
|
2011-12-14 21:04:51 +01:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2023-03-28 19:22:23 +02:00
|
|
|
% Compute the value of the Lagrange multipliers that minimizes the norm of the
|
|
|
|
% residuals, given the other endogenous
|
|
|
|
if options_.bytecode
|
2023-10-25 17:29:55 +02:00
|
|
|
res = bytecode('static', M_, options, xx, exo_ss, M_.params, 'evaluate');
|
2012-06-06 16:29:26 +02:00
|
|
|
else
|
2023-10-25 17:29:55 +02:00
|
|
|
res = feval([M_.fname '.sparse.static_resid'], xx, exo_ss, M_.params);
|
2012-06-06 16:29:26 +02:00
|
|
|
end
|
2023-10-25 17:29:55 +02:00
|
|
|
A = feval([M_.fname '.ramsey_multipliers_static_g1'], xx, exo_ss, M_.params, M_.ramsey_multipliers_static_g1_sparse_rowval, M_.ramsey_multipliers_static_g1_sparse_colval, M_.ramsey_multipliers_static_g1_sparse_colptr);
|
|
|
|
y = res(1:M_.ramsey_orig_endo_nbr);
|
2014-03-11 13:22:04 +01:00
|
|
|
mult = -A\y;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2014-03-11 13:22:04 +01:00
|
|
|
resids1 = y+A*mult;
|
2011-06-22 11:31:35 +02:00
|
|
|
if inst_nbr == 1
|
|
|
|
r1 = sqrt(resids1'*resids1);
|
|
|
|
else
|
|
|
|
[q,r,e] = qr([A y]');
|
2012-02-02 12:04:15 +01:00
|
|
|
k = size(A,1)+(1-inst_nbr:0);
|
|
|
|
r1 = r(end,k)';
|
2011-06-22 11:31:35 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
if options_.steadystate_flag
|
2011-06-22 11:31:35 +02:00
|
|
|
resids = r1;
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
2023-10-25 17:29:55 +02:00
|
|
|
resids = [res(M_.ramsey_orig_endo_nbr+(1:M_.orig_endo_nbr-inst_nbr)); r1];
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
2014-03-11 13:22:04 +01:00
|
|
|
if needs_set_auxiliary_variables
|
2023-10-25 17:29:55 +02:00
|
|
|
steady_state = s_a_v_func([xx(1:M_.ramsey_orig_endo_nbr); mult]);
|
2014-03-11 13:22:04 +01:00
|
|
|
else
|
2023-10-25 17:29:55 +02:00
|
|
|
steady_state = [xx(1:M_.ramsey_orig_endo_nbr); mult];
|
2014-03-11 13:22:04 +01:00
|
|
|
end
|
|
|
|
|
2023-10-25 17:29:55 +02:00
|
|
|
function result = check_static_model(ys,exo_ss,M_,options_)
|
2014-03-11 13:22:04 +01:00
|
|
|
result = false;
|
|
|
|
if (options_.bytecode)
|
2023-10-25 17:29:55 +02:00
|
|
|
[res, ~] = bytecode('static', M_, options, ys, exo_ss, M_.params, 'evaluate');
|
2014-03-11 13:22:04 +01:00
|
|
|
else
|
2023-10-25 17:29:55 +02:00
|
|
|
res = feval([M_.fname '.sparse.static_resid'], ys, exo_ss, M_.params);
|
2014-03-11 13:22:04 +01:00
|
|
|
end
|
|
|
|
if norm(res) < options_.solve_tolf
|
|
|
|
result = true;
|
|
|
|
end
|