Merge branch 'discretion' into 'master'

evaluate_planner_objective.m: fix output for linear-quadratic problems solved at second order

See merge request Dynare/dynare!2056
mr#2067
Sébastien Villemot 2022-07-26 13:03:45 +00:00
commit b93d04646e
1 changed files with 264 additions and 268 deletions

View File

@ -59,7 +59,7 @@ function planner_objective_value = evaluate_planner_objective(M_,options_,oo_)
% In the deterministic case, resorting to approximations for welfare is no longer required as it is possible to simulate the model given initial conditions for pre-determined variables and terminal conditions for forward-looking variables, whether these initial and terminal conditions are explicitly or implicitly specified. Assuming that the number of simulated periods is high enough for the new steady-state to be reached, the new unconditional welfare is thus the last period's welfare. As for the conditional welfare, it can be derived using backward recursions on the equation W = U + beta*W(+1) starting from the final unconditional steady-state welfare.
% Copyright © 2007-2021 Dynare Team
% Copyright © 2007-2022 Dynare Team
%
% This file is part of Dynare.
%
@ -90,8 +90,7 @@ if beta>=1
fprintf('evaluate_planner_objective: the planner discount factor is not strictly smaller than 1. Unconditional welfare will not be finite.\n')
end
if options_.ramsey_policy
if oo_.gui.ran_perfect_foresight
if options_.ramsey_policy && oo_.gui.ran_perfect_foresight
T = size(oo_.endo_simul,2);
[U_term] = feval([M_.fname '.objective.static'],oo_.endo_simul(:,T-M_.maximum_lead),oo_.exo_simul(T-M_.maximum_lead,:), M_.params);
EW = U_term/(1-beta);
@ -104,11 +103,11 @@ if options_.ramsey_policy
else
planner_objective_value = struct('conditional', struct('zero_initial_multiplier', 0., 'steady_initial_multiplier', 0.), 'unconditional', 0.);
if isempty(oo_.dr) || ~isfield(oo_.dr,'ys')
error('evaluate_planner_objective requires decision rules to have previously been computed (e.g. by stoch_simul)')
error('evaluate_planner_objective requires decision rules to have previously been computed (e.g. by stoch_simul or discretionary_policy)')
else
ys = oo_.dr.ys;
end
if options_.order == 1 || M_.hessian_eq_zero
if options_.order == 1 && ~options_.discretionary_policy
[U,Uy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
Gy = dr.ghx(nstatic+(1:nspred),:);
@ -137,7 +136,7 @@ if options_.ramsey_policy
planner_objective_value.conditional.steady_initial_multiplier = W_L_SS;
planner_objective_value.conditional.zero_initial_multiplier = W_L_0;
elseif options_.order == 2 && ~M_.hessian_eq_zero
elseif options_.order == 2 && ~M_.hessian_eq_zero %full second order approximation
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
Gy = dr.ghx(nstatic+(1:nspred),:);
@ -228,52 +227,7 @@ if options_.ramsey_policy
planner_objective_value.conditional.steady_initial_multiplier = W_L_SS;
planner_objective_value.conditional.zero_initial_multiplier = W_L_0;
else
% Computes the welfare decision rule
[W] = k_order_welfare(dr,M_,options_);
% Appends the welfare decision rule to the endogenous variables decision
% rule
for i=0:options_.order
dr.(['g_' num2str(i)]) = [dr.(['g_' num2str(i)]); W.(['W_' num2str(i)])];
end
% Amends the steady-state vector accordingly
[U] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
ysteady = [ys(oo_.dr.order_var); U/(1-beta)];
% Generates the sequence of shocks to compute unconditional welfare
i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0));
nxs = length(i_exo_var);
chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var));
exo_simul = zeros(M_.exo_nbr,options_.ramsey.periods);
if ~isempty(M_.Sigma_e)
exo_simul(i_exo_var,:) = chol_S*randn(nxs,options_.ramsey.periods);
end
yhat_start = zeros(M_.endo_nbr+1,1);
[moment] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, options_.ramsey.drop, yhat_start, exo_simul, ysteady, dr);
% Stores the result for unconditional welfare
planner_objective_value.unconditional = moment(end);
% Conditional welfare
% Gets initial values
[yhat_L_SS,yhat_L_0, u] = get_initial_state(ys,M_,dr,oo_);
% Conditional welfare (i) with Lagrange multipliers set to their
% steady-state values
yhat_start(M_.nstatic+1:M_.nstatic+M_.npred+M_.nboth) = yhat_L_SS;
[~,sim] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, 0, yhat_start, u, ysteady, dr);
planner_objective_value.conditional.steady_initial_multiplier = sim(end,1);
% Conditional welfare (ii) with Lagrange multipliers set to 0
yhat_start(M_.nstatic+1:M_.nstatic+M_.npred+M_.nboth) = yhat_L_0;
[~,sim] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, 0, yhat_start, u, ysteady, dr);
planner_objective_value.conditional.zero_initial_multiplier = sim(end,1);
end
end
elseif options_.discretionary_policy
ys = oo_.dr.ys;
planner_objective_value = struct('conditional', struct('zero_initial_multiplier', 0., 'steady_initial_multiplier', 0.), 'unconditional', 0.);
elseif (options_.order == 2 && M_.hessian_eq_zero) || options_.discretionary_policy %linear quadratic problem
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
Gy = dr.ghx(nstatic+(1:nspred),:);
@ -341,7 +295,50 @@ elseif options_.discretionary_policy
planner_objective_value.conditional.steady_initial_multiplier = W_L_SS;
planner_objective_value.conditional.zero_initial_multiplier = W_L_0;
elseif options_.order > 2 || ~options_.discretionary_policy
% Computes the welfare decision rule
[W] = k_order_welfare(dr,M_,options_);
% Appends the welfare decision rule to the endogenous variables decision
% rule
for i=0:options_.order
dr.(['g_' num2str(i)]) = [dr.(['g_' num2str(i)]); W.(['W_' num2str(i)])];
end
% Amends the steady-state vector accordingly
[U] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
ysteady = [ys(oo_.dr.order_var); U/(1-beta)];
% Generates the sequence of shocks to compute unconditional welfare
i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0));
nxs = length(i_exo_var);
chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var));
exo_simul = zeros(M_.exo_nbr,options_.ramsey.periods);
if ~isempty(M_.Sigma_e)
exo_simul(i_exo_var,:) = chol_S*randn(nxs,options_.ramsey.periods);
end
yhat_start = zeros(M_.endo_nbr+1,1);
[moment] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, options_.ramsey.drop, yhat_start, exo_simul, ysteady, dr);
% Stores the result for unconditional welfare
planner_objective_value.unconditional = moment(end);
% Conditional welfare
% Gets initial values
[yhat_L_SS,yhat_L_0, u] = get_initial_state(ys,M_,dr,oo_);
% Conditional welfare (i) with Lagrange multipliers set to their
% steady-state values
yhat_start(M_.nstatic+1:M_.nstatic+M_.npred+M_.nboth) = yhat_L_SS;
[~,sim] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, 0, yhat_start, u, ysteady, dr);
planner_objective_value.conditional.steady_initial_multiplier = sim(end,1);
% Conditional welfare (ii) with Lagrange multipliers set to 0
yhat_start(M_.nstatic+1:M_.nstatic+M_.npred+M_.nboth) = yhat_L_0;
[~,sim] = k_order_mean(options_.order, M_.nstatic, M_.npred, M_.nboth, M_.nfwrd+1, M_.exo_nbr, 1, 0, yhat_start, u, ysteady, dr);
planner_objective_value.conditional.zero_initial_multiplier = sim(end,1);
end
end
if ~options_.noprint
if options_.ramsey_policy
if oo_.gui.ran_perfect_foresight
@ -406,4 +403,3 @@ if ~isempty(M_.det_shocks)
else
u = oo_.exo_simul(1,:)'; %first value of simulation series (set by simult.m if periods>0), 1 otherwise
end