Merge branch 'evaluate_planner' into 'master'
evaluate_planner_objective.m: correctly rely on lag/lead structure for perfect foresight See merge request Dynare/dynare!1890trust-region-mex
commit
b34be496c5
|
@ -6,8 +6,8 @@ function planner_objective_value = evaluate_planner_objective(M_,options_,oo_)
|
||||||
% oo_: (structure) output results
|
% oo_: (structure) output results
|
||||||
% OUTPUT
|
% OUTPUT
|
||||||
% planner_objective_value (double)
|
% planner_objective_value (double)
|
||||||
%
|
%
|
||||||
%Returns a vector containing first order or second-order approximations of
|
%Returns a vector containing first order or second-order approximations of
|
||||||
% - the unconditional expectation of the planner's objective function
|
% - the unconditional expectation of the planner's objective function
|
||||||
% - the conditional expectation of the planner's objective function starting from the non-stochastic steady state and allowing for future shocks
|
% - the conditional expectation of the planner's objective function starting from the non-stochastic steady state and allowing for future shocks
|
||||||
% depending on the value of options_.order.
|
% depending on the value of options_.order.
|
||||||
|
@ -52,7 +52,7 @@ function planner_objective_value = evaluate_planner_objective(M_,options_,oo_)
|
||||||
% W(y,0,1) = Wbar + 0.5*Wss
|
% W(y,0,1) = Wbar + 0.5*Wss
|
||||||
|
|
||||||
% In the discretionary case, the model is assumed to be linear and the utility is assumed to be linear-quadratic. This changes 2 aspects of the results delinated above:
|
% In the discretionary case, the model is assumed to be linear and the utility is assumed to be linear-quadratic. This changes 2 aspects of the results delinated above:
|
||||||
% 1) the second-order derivatives of the policy and transition functions h and g are zero.
|
% 1) the second-order derivatives of the policy and transition functions h and g are zero.
|
||||||
% 2) the unconditional expectation of states coincides with its steady-state, which entails E(yhat) = 0
|
% 2) the unconditional expectation of states coincides with its steady-state, which entails E(yhat) = 0
|
||||||
% Therefore, the unconditional welfare can now be approximated as
|
% Therefore, the unconditional welfare can now be approximated as
|
||||||
% E(W) = (1 - beta)^{-1} ( Ubar + 0.5 ( U_xx h_y^2 E(yhat^2) + U_xx h_u^2 E(u^2) )
|
% E(W) = (1 - beta)^{-1} ( Ubar + 0.5 ( U_xx h_y^2 E(yhat^2) + U_xx h_u^2 E(u^2) )
|
||||||
|
@ -91,47 +91,47 @@ planner_objective_value = zeros(2,1);
|
||||||
if options_.ramsey_policy
|
if options_.ramsey_policy
|
||||||
if oo_.gui.ran_perfect_foresight
|
if oo_.gui.ran_perfect_foresight
|
||||||
T = size(oo_.endo_simul,2);
|
T = size(oo_.endo_simul,2);
|
||||||
[U_term] = feval([M_.fname '.objective.static'],oo_.endo_simul(:,T),oo_.exo_simul(T,:), M_.params);
|
[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);
|
EW = U_term/(1-beta);
|
||||||
W = EW;
|
W = EW;
|
||||||
for t=T:-1:2
|
for t=T-M_.maximum_lead:-1:1+M_.maximum_lag
|
||||||
[U] = feval([M_.fname '.objective.static'],oo_.endo_simul(:,t),oo_.exo_simul(t,:), M_.params);
|
[U] = feval([M_.fname '.objective.static'],oo_.endo_simul(:,t),oo_.exo_simul(t,:), M_.params);
|
||||||
W = U + beta*W;
|
W = U + beta*W;
|
||||||
end
|
end
|
||||||
planner_objective_value(1) = EW;
|
planner_objective_value(1) = EW;
|
||||||
planner_objective_value(2) = W;
|
planner_objective_value(2) = W;
|
||||||
else
|
else
|
||||||
ys = oo_.dr.ys;
|
ys = oo_.dr.ys;
|
||||||
if options_.order == 1 || M_.hessian_eq_zero
|
if options_.order == 1 || M_.hessian_eq_zero
|
||||||
[U] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
[U] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
||||||
planner_objective_value(1) = U/(1-beta);
|
planner_objective_value(1) = U/(1-beta);
|
||||||
planner_objective_value(2) = U/(1-beta);
|
planner_objective_value(2) = U/(1-beta);
|
||||||
elseif options_.order == 2 && ~M_.hessian_eq_zero
|
elseif options_.order == 2 && ~M_.hessian_eq_zero
|
||||||
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
||||||
|
|
||||||
Gy = dr.ghx(nstatic+(1:nspred),:);
|
Gy = dr.ghx(nstatic+(1:nspred),:);
|
||||||
Gu = dr.ghu(nstatic+(1:nspred),:);
|
Gu = dr.ghu(nstatic+(1:nspred),:);
|
||||||
Gyy = dr.ghxx(nstatic+(1:nspred),:);
|
Gyy = dr.ghxx(nstatic+(1:nspred),:);
|
||||||
Gyu = dr.ghxu(nstatic+(1:nspred),:);
|
Gyu = dr.ghxu(nstatic+(1:nspred),:);
|
||||||
Guu = dr.ghuu(nstatic+(1:nspred),:);
|
Guu = dr.ghuu(nstatic+(1:nspred),:);
|
||||||
Gss = dr.ghs2(nstatic+(1:nspred),:);
|
Gss = dr.ghs2(nstatic+(1:nspred),:);
|
||||||
|
|
||||||
gy(dr.order_var,:) = dr.ghx;
|
gy(dr.order_var,:) = dr.ghx;
|
||||||
gu(dr.order_var,:) = dr.ghu;
|
gu(dr.order_var,:) = dr.ghu;
|
||||||
gyy(dr.order_var,:) = dr.ghxx;
|
gyy(dr.order_var,:) = dr.ghxx;
|
||||||
gyu(dr.order_var,:) = dr.ghxu;
|
gyu(dr.order_var,:) = dr.ghxu;
|
||||||
guu(dr.order_var,:) = dr.ghuu;
|
guu(dr.order_var,:) = dr.ghuu;
|
||||||
gss(dr.order_var,:) = dr.ghs2;
|
gss(dr.order_var,:) = dr.ghs2;
|
||||||
|
|
||||||
Uyy = full(Uyy);
|
Uyy = full(Uyy);
|
||||||
|
|
||||||
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
|
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
|
||||||
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
|
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
|
||||||
|
|
||||||
%% Unconditional welfare
|
%% Unconditional welfare
|
||||||
|
|
||||||
old_noprint = options_.noprint;
|
old_noprint = options_.noprint;
|
||||||
|
|
||||||
if ~old_noprint
|
if ~old_noprint
|
||||||
options_.noprint = 1;
|
options_.noprint = 1;
|
||||||
end
|
end
|
||||||
|
@ -143,25 +143,25 @@ if options_.ramsey_policy
|
||||||
if ~old_noprint
|
if ~old_noprint
|
||||||
options_.noprint = 0;
|
options_.noprint = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
oo_.mean(isnan(oo_.mean)) = options_.huge_number;
|
oo_.mean(isnan(oo_.mean)) = options_.huge_number;
|
||||||
oo_.var(isnan(oo_.var)) = options_.huge_number;
|
oo_.var(isnan(oo_.var)) = options_.huge_number;
|
||||||
|
|
||||||
Ey = oo_.mean;
|
Ey = oo_.mean;
|
||||||
Eyhat = Ey - ys(dr.order_var(nstatic+(1:nspred)));
|
Eyhat = Ey - ys(dr.order_var(nstatic+(1:nspred)));
|
||||||
|
|
||||||
var_corr = Eyhat*Eyhat';
|
var_corr = Eyhat*Eyhat';
|
||||||
Eyhatyhat = oo_.var(:) + var_corr(:);
|
Eyhatyhat = oo_.var(:) + var_corr(:);
|
||||||
Euu = M_.Sigma_e(:);
|
Euu = M_.Sigma_e(:);
|
||||||
|
|
||||||
EU = U + Uy*gy*Eyhat + 0.5*((Uyygygy + Uy*gyy)*Eyhatyhat + (Uyygugu + Uy*guu)*Euu + Uy*gss);
|
EU = U + Uy*gy*Eyhat + 0.5*((Uyygygy + Uy*gyy)*Eyhatyhat + (Uyygugu + Uy*guu)*Euu + Uy*gss);
|
||||||
EW = EU/(1-beta);
|
EW = EU/(1-beta);
|
||||||
|
|
||||||
%% Conditional welfare starting from the non-stochastic steady-state
|
%% Conditional welfare starting from the non-stochastic steady-state
|
||||||
|
|
||||||
Wbar = U/(1-beta);
|
Wbar = U/(1-beta);
|
||||||
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
||||||
|
|
||||||
if isempty(options_.qz_criterium)
|
if isempty(options_.qz_criterium)
|
||||||
options_.qz_criterium = 1+1e-6;
|
options_.qz_criterium = 1+1e-6;
|
||||||
end
|
end
|
||||||
|
@ -171,7 +171,7 @@ if options_.ramsey_policy
|
||||||
Wuu = Uyygugu + Uy*guu + beta*(Wyygugu + Wy*Guu);
|
Wuu = Uyygugu + Uy*guu + beta*(Wyygugu + Wy*Guu);
|
||||||
Wss = (Uy*gss + beta*(Wy*Gss + Wuu*M_.Sigma_e(:)))/(1-beta);
|
Wss = (Uy*gss + beta*(Wy*Gss + Wuu*M_.Sigma_e(:)))/(1-beta);
|
||||||
W = Wbar + 0.5*Wss;
|
W = Wbar + 0.5*Wss;
|
||||||
|
|
||||||
planner_objective_value(1) = EW;
|
planner_objective_value(1) = EW;
|
||||||
planner_objective_value(2) = W;
|
planner_objective_value(2) = W;
|
||||||
else
|
else
|
||||||
|
@ -184,23 +184,23 @@ if options_.ramsey_policy
|
||||||
end
|
end
|
||||||
elseif options_.discretionary_policy
|
elseif options_.discretionary_policy
|
||||||
ys = oo_.dr.ys;
|
ys = oo_.dr.ys;
|
||||||
|
|
||||||
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
|
||||||
|
|
||||||
Gy = dr.ghx(nstatic+(1:nspred),:);
|
Gy = dr.ghx(nstatic+(1:nspred),:);
|
||||||
Gu = dr.ghu(nstatic+(1:nspred),:);
|
Gu = dr.ghu(nstatic+(1:nspred),:);
|
||||||
gy(dr.order_var,:) = dr.ghx;
|
gy(dr.order_var,:) = dr.ghx;
|
||||||
gu(dr.order_var,:) = dr.ghu;
|
gu(dr.order_var,:) = dr.ghu;
|
||||||
|
|
||||||
Uyy = full(Uyy);
|
Uyy = full(Uyy);
|
||||||
|
|
||||||
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
|
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
|
||||||
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
|
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
|
||||||
|
|
||||||
%% Unconditional welfare
|
%% Unconditional welfare
|
||||||
|
|
||||||
old_noprint = options_.noprint;
|
old_noprint = options_.noprint;
|
||||||
|
|
||||||
if ~old_noprint
|
if ~old_noprint
|
||||||
options_.noprint = 1;
|
options_.noprint = 1;
|
||||||
end
|
end
|
||||||
|
@ -209,36 +209,33 @@ elseif options_.discretionary_policy
|
||||||
if ~old_noprint
|
if ~old_noprint
|
||||||
options_.noprint = 0;
|
options_.noprint = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
oo_.mean(isnan(oo_.mean)) = options_.huge_number;
|
oo_.mean(isnan(oo_.mean)) = options_.huge_number;
|
||||||
oo_.var(isnan(oo_.var)) = options_.huge_number;
|
oo_.var(isnan(oo_.var)) = options_.huge_number;
|
||||||
|
|
||||||
Ey = oo_.mean;
|
Ey = oo_.mean;
|
||||||
Eyhat = Ey - ys(dr.order_var(nstatic+(1:nspred)));
|
Eyhat = Ey - ys(dr.order_var(nstatic+(1:nspred)));
|
||||||
|
|
||||||
var_corr = Eyhat*Eyhat';
|
var_corr = Eyhat*Eyhat';
|
||||||
Eyhatyhat = oo_.var(:) + var_corr(:);
|
Eyhatyhat = oo_.var(:) + var_corr(:);
|
||||||
Euu = M_.Sigma_e(:);
|
Euu = M_.Sigma_e(:);
|
||||||
|
|
||||||
EU = U + Uy*gy*Eyhat + 0.5*(Uyygygy*Eyhatyhat + Uyygugu*Euu);
|
EU = U + Uy*gy*Eyhat + 0.5*(Uyygygy*Eyhatyhat + Uyygugu*Euu);
|
||||||
EW = EU/(1-beta);
|
EW = EU/(1-beta);
|
||||||
|
|
||||||
|
|
||||||
%% Conditional welfare starting from the non-stochastic steady-state
|
%% Conditional welfare starting from the non-stochastic steady-state
|
||||||
|
|
||||||
Wbar = U/(1-beta);
|
Wbar = U/(1-beta);
|
||||||
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
Wy = Uy*gy/(eye(nspred)-beta*Gy);
|
||||||
|
|
||||||
if isempty(options_.qz_criterium)
|
|
||||||
options_.qz_criterium = 1+1e-6;
|
|
||||||
end
|
|
||||||
%solve Lyapunuv equation Wyy=gy'*Uyy*gy+beta*Gy'Wyy*Gy
|
%solve Lyapunuv equation Wyy=gy'*Uyy*gy+beta*Gy'Wyy*Gy
|
||||||
Wyy = reshape(lyapunov_symm(sqrt(beta)*Gy',reshape(Uyygygy,nspred,nspred),options_.lyapunov_fixed_point_tol,options_.qz_criterium,options_.lyapunov_complex_threshold, 3, options_.debug),1,nspred*nspred);
|
Wyy = reshape(lyapunov_symm(sqrt(beta)*Gy',reshape(Uyygygy,nspred,nspred),options_.lyapunov_fixed_point_tol,options_.qz_criterium,options_.lyapunov_complex_threshold, 3, options_.debug),1,nspred*nspred);
|
||||||
Wyygugu = A_times_B_kronecker_C(Wyy,Gu,Gu);
|
Wyygugu = A_times_B_kronecker_C(Wyy,Gu,Gu);
|
||||||
Wuu = Uyygugu + beta*Wyygugu;
|
Wuu = Uyygugu + beta*Wyygugu;
|
||||||
Wss = beta*Wuu*M_.Sigma_e(:)/(1-beta);
|
Wss = beta*Wuu*M_.Sigma_e(:)/(1-beta);
|
||||||
W = Wbar + 0.5*Wss;
|
W = Wbar + 0.5*Wss;
|
||||||
|
|
||||||
planner_objective_value(1) = EW;
|
planner_objective_value(1) = EW;
|
||||||
planner_objective_value(2) = W;
|
planner_objective_value(2) = W;
|
||||||
end
|
end
|
||||||
|
@ -250,7 +247,7 @@ if ~options_.noprint
|
||||||
else
|
else
|
||||||
fprintf('\nApproximated value of unconditional welfare: %10.8f\n', planner_objective_value(1))
|
fprintf('\nApproximated value of unconditional welfare: %10.8f\n', planner_objective_value(1))
|
||||||
fprintf('\nApproximated value of conditional welfare: %10.8f\n', planner_objective_value(2))
|
fprintf('\nApproximated value of conditional welfare: %10.8f\n', planner_objective_value(2))
|
||||||
end
|
end
|
||||||
elseif options_.discretionary_policy
|
elseif options_.discretionary_policy
|
||||||
fprintf('\nApproximated value of unconditional welfare with discretionary policy: %10.8f\n', planner_objective_value(1))
|
fprintf('\nApproximated value of unconditional welfare with discretionary policy: %10.8f\n', planner_objective_value(1))
|
||||||
fprintf('\nApproximated value of conditional welfare with discretionary policy: %10.8f\n', planner_objective_value(2))
|
fprintf('\nApproximated value of conditional welfare with discretionary policy: %10.8f\n', planner_objective_value(2))
|
||||||
|
|
|
@ -23,7 +23,7 @@ r=1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
histval;
|
histval;
|
||||||
r(0)=1;
|
a(0)=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
steady_state_model;
|
steady_state_model;
|
||||||
|
@ -42,4 +42,5 @@ end;
|
||||||
options_.dr_display_tol=0;
|
options_.dr_display_tol=0;
|
||||||
planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
|
planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
|
||||||
ramsey_model(planner_discount=0.99,instruments=(r));
|
ramsey_model(planner_discount=0.99,instruments=(r));
|
||||||
stoch_simul(order=1,periods=500);
|
stoch_simul(order=1);
|
||||||
|
evaluate_planner_objective;
|
Loading…
Reference in New Issue