2023-09-15 13:40:10 +02:00
|
|
|
function [dr, info, params]=discretionary_policy_1(M_, options_, dr, endo_steady_state, exo_steady_state, exo_det_steady_state)
|
2020-02-03 18:02:55 +01:00
|
|
|
% Higher-level function for solving discretionary optimal policy
|
2020-02-06 13:30:00 +01:00
|
|
|
% INPUTS
|
|
|
|
% - M_ [structure] Matlab's structure describing the model (M_).
|
|
|
|
% - options_ [structure] Matlab's structure describing the current options (options_).
|
2023-09-15 13:40:10 +02:00
|
|
|
% - dr [struct] Decision rules for stochastic simulations.
|
|
|
|
% - endo_steady_state [vector] steady state value for endogenous variables
|
|
|
|
% - exo_steady_state [vector] steady state value for exogenous variables
|
|
|
|
% - exo_det_steady_state [vector] steady state value for exogenous deterministic variables
|
2020-02-06 13:30:00 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% - dr [structure] Reduced form model.
|
|
|
|
% - info [integer] scalar or vector, error code.
|
2023-09-15 13:40:10 +02:00
|
|
|
% - params [double] vector of potentially updated parameters
|
2012-06-08 19:10:19 +02:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2007-2020 Dynare Team
|
2012-06-08 19:10:19 +02: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/>.
|
2012-06-08 19:10:19 +02:00
|
|
|
|
|
|
|
persistent Hold
|
|
|
|
|
2012-06-19 14:08:45 +02:00
|
|
|
info = 0;
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
beta = get_optimal_policy_discount_factor(M_.params, M_.param_names);
|
2012-06-08 19:10:19 +02:00
|
|
|
|
2016-06-23 20:50:17 +02:00
|
|
|
%call steady_state_file if present to update parameters
|
|
|
|
if options_.steadystate_flag
|
|
|
|
% explicit steady state file
|
2023-09-15 13:40:10 +02:00
|
|
|
[ys,M_.params,info] = evaluate_steady_state_file(endo_steady_state,[exo_steady_state; exo_det_steady_state],M_, ...
|
2020-02-11 18:14:05 +01:00
|
|
|
options_,false);
|
2020-02-12 13:37:36 +01:00
|
|
|
if info(1)
|
|
|
|
return;
|
|
|
|
end
|
2020-12-16 21:47:43 +01:00
|
|
|
else
|
|
|
|
ys=zeros(M_.endo_nbr,1);
|
2016-06-23 20:50:17 +02:00
|
|
|
end
|
2023-09-15 13:40:10 +02:00
|
|
|
params=M_.params;
|
|
|
|
|
2020-02-12 12:52:54 +01:00
|
|
|
[U,Uy,W] = feval([M_.fname,'.objective.static'],zeros(M_.endo_nbr,1),[], M_.params);
|
2019-02-05 09:14:20 +01:00
|
|
|
if any(any(isnan(Uy)))
|
2020-02-12 12:52:54 +01:00
|
|
|
info = 64 ; %the derivatives of the objective function contain NaN
|
|
|
|
return;
|
2019-02-05 09:14:20 +01:00
|
|
|
end
|
2012-06-08 19:10:19 +02:00
|
|
|
if any(any(Uy~=0))
|
2020-02-12 12:52:54 +01:00
|
|
|
if options_.debug
|
|
|
|
non_zero_derivs=find(any(Uy~=0));
|
|
|
|
for ii=1:length(non_zero_derivs)
|
|
|
|
non_zero_deriv_names{ii,1} = M_.endo_names{non_zero_derivs(ii)};
|
|
|
|
end
|
|
|
|
disp_string=[non_zero_deriv_names{1,:}];
|
|
|
|
for ii=2:size(non_zero_deriv_names,1)
|
|
|
|
disp_string=[disp_string,', ',non_zero_deriv_names{ii,:}];
|
|
|
|
end
|
|
|
|
fprintf('\nThe derivative of the objective function w.r.t. to variable(s) %s is not 0\n',disp_string);
|
2017-06-12 20:59:18 +02:00
|
|
|
end
|
2020-02-12 12:52:54 +01:00
|
|
|
info = 66;
|
|
|
|
return;
|
2012-06-08 19:10:19 +02:00
|
|
|
end
|
|
|
|
|
2020-02-12 12:52:54 +01:00
|
|
|
W=reshape(W,M_.endo_nbr,M_.endo_nbr);
|
2012-06-08 19:10:19 +02:00
|
|
|
|
2020-02-12 12:52:54 +01:00
|
|
|
klen = M_.maximum_lag + M_.maximum_lead + 1;
|
|
|
|
iyv=M_.lead_lag_incidence';
|
2012-06-08 19:10:19 +02:00
|
|
|
% Find the jacobian
|
2020-12-16 21:47:43 +01:00
|
|
|
z = repmat(ys,1,klen);
|
|
|
|
iyr0 = find(iyv(:)) ;
|
|
|
|
|
|
|
|
z = z(iyr0);
|
2020-02-12 12:52:54 +01:00
|
|
|
it_ = M_.maximum_lag + 1 ;
|
2012-06-08 19:10:19 +02:00
|
|
|
|
2023-09-15 13:40:10 +02:00
|
|
|
[junk,jacobia_] = feval([M_.fname '.dynamic'],z,zeros(M_.exo_nbr+M_.exo_det_nbr,klen), M_.params, ys, it_);
|
2020-12-16 21:47:43 +01:00
|
|
|
if max(abs(junk))>options_.solve_tolf
|
|
|
|
info = 65; %the model must be written in deviation form and not have constant terms or have a steady state provided
|
|
|
|
return;
|
2012-06-08 19:10:19 +02:00
|
|
|
end
|
|
|
|
|
2020-02-12 12:52:54 +01:00
|
|
|
Indices={'lag','contemp','lead'};
|
2012-06-08 19:10:19 +02:00
|
|
|
iter=1;
|
|
|
|
for j=1:numel(Indices)
|
2020-11-11 22:07:33 +01:00
|
|
|
A.(Indices{j})=zeros(M_.eq_nbr,M_.endo_nbr);
|
2020-02-12 12:52:54 +01:00
|
|
|
if strcmp(Indices{j},'contemp')||(strcmp(Indices{j},'lag') && M_.maximum_lag)||(strcmp(Indices{j},'lead') && M_.maximum_lead)
|
|
|
|
[~,row,col]=find(M_.lead_lag_incidence(iter,:));
|
|
|
|
A.(Indices{j})(:,row)=jacobia_(:,col);
|
2017-05-16 15:10:20 +02:00
|
|
|
iter=iter+1;
|
|
|
|
end
|
2012-06-08 19:10:19 +02:00
|
|
|
end
|
|
|
|
B=jacobia_(:,nnz(iyv)+1:end);
|
|
|
|
|
|
|
|
%%% MAIN ENGINE %%%
|
|
|
|
|
|
|
|
if ~isempty(Hold)
|
2020-02-12 12:52:54 +01:00
|
|
|
[H,G,info]=discretionary_policy_engine(A.lag,A.contemp,A.lead,B,W,M_.instr_id,beta,options_.dp.maxit,options_.discretionary_tol,options_.qz_criterium,Hold);
|
2012-06-08 19:10:19 +02:00
|
|
|
else
|
2020-02-12 12:52:54 +01:00
|
|
|
[H,G,info]=discretionary_policy_engine(A.lag,A.contemp,A.lead,B,W,M_.instr_id,beta,options_.dp.maxit,options_.discretionary_tol,options_.qz_criterium);
|
2012-06-08 19:10:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if info
|
|
|
|
return
|
|
|
|
else
|
2017-05-16 15:10:20 +02:00
|
|
|
Hold=H; %save previous solution
|
|
|
|
% Hold=[]; use this line if persistent command is not used.
|
2012-06-08 19:10:19 +02:00
|
|
|
end
|
|
|
|
|
2020-02-12 12:52:54 +01:00
|
|
|
%write back solution to dr
|
2020-12-16 21:47:43 +01:00
|
|
|
dr.ys =ys;
|
2023-10-08 22:08:57 +02:00
|
|
|
dr=set_state_space(dr,M_);
|
2020-02-12 12:52:54 +01:00
|
|
|
T=H(dr.order_var,dr.order_var);
|
|
|
|
dr.ghu=G(dr.order_var,:);
|
2020-12-16 21:47:43 +01:00
|
|
|
if M_.maximum_endo_lag
|
|
|
|
Selection=M_.lead_lag_incidence(1,dr.order_var)>0;%select state variables
|
|
|
|
end
|
2023-09-15 13:40:10 +02:00
|
|
|
dr.ghx=T(:,Selection);
|