File: pfwee_marginal_linearization.mod

package info (click to toggle)
dynare 7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,248 kB
  • sloc: cpp: 82,011; ansic: 28,583; objc: 12,573; yacc: 5,105; pascal: 2,374; lex: 1,502; python: 1,118; sh: 1,116; makefile: 605; lisp: 162; xml: 18
file content (152 lines) | stat: -rw-r--r-- 5,726 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* Test that perfect foresight simulation with expectation errors gives correct
   results with marginal linearization. Homotopy is not really triggered, but
   the use of homotopy_max_completion_share is enough to test the computations.

   This test is similar to pfwee_homotopy_marginal_linearization.mod, except that
   the numerical values are different (the shock is smaller to facilitate computations).
   */

var Consumption, Capital, LoggedProductivity;

varexo LoggedProductivityInnovation;

parameters beta, alpha, delta, rho;

beta = .985;
alpha = 1/3;
delta = alpha/10;
rho = .4;

model;
  1/Consumption = beta/Consumption(1)*(alpha*exp(LoggedProductivity(1))*Capital^(alpha-1)+1-delta);
  Capital = exp(LoggedProductivity)*Capital(-1)^alpha+(1-delta)*Capital(-1)-Consumption;
  LoggedProductivity = rho*LoggedProductivity(-1)+LoggedProductivityInnovation;
end;

initval;
  LoggedProductivityInnovation = 0.1;
end;

steady;

endval;
  LoggedProductivityInnovation = 0.3;
end;

shocks(learnt_in = 5);
  var LoggedProductivityInnovation;
  periods 7;
  values -0.5;
end;

endval(learnt_in = 10);
  LoggedProductivityInnovation = 0.6;
end;

// Save initial steady state (it will be modified by pfwee)
orig_steady_state = oo_.steady_state;
orig_exo_steady_state = oo_.exo_steady_state;

perfect_foresight_with_expectation_errors_setup(periods = 50);
perfect_foresight_with_expectation_errors_solver(homotopy_max_completion_share = 0.8, homotopy_marginal_linearization_fallback, steady_solve_algo = 13);

verbatim;

if ~oo_.deterministic_simulation.status
   error('Perfect foresight simulation failed')
end

pfwee_endo_simul = oo_.endo_simul;
pfwee_exo_simul = oo_.exo_simul;

oo_.steady_state = orig_steady_state;
oo_.exo_steady_state = orig_exo_steady_state;

oo_ = make_ex_(M_,options_,oo_);
oo_ = make_y_(M_,options_,oo_);

options_.simul.homotopy_marginal_linearization_fallback = 0;
options_.simul.homotopy_max_completion_share = 1;
options_.solve_algo = 13;

%% Information arriving in period 1 (permanent shock now)
% Simulation at 80%
disp('*** info_period=1, share=80%')
oo_.exo_steady_state = 0.1+0.2*0.8;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:,end) = oo_.steady_state;
oo_.exo_simul(2:end,:) = oo_.exo_steady_state;
sim1_1 = perfect_foresight_solver(M_, options_, oo_);
% Simulation at 79%
disp('*** info_period=1, share=79%')
oo_.exo_steady_state = 0.1+0.2*0.79;
oo_.steady_state = evaluate_steady_state(oo_.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:,end) = oo_.steady_state;
oo_.exo_simul(2:end,:) = oo_.exo_steady_state;
sim2_1 = perfect_foresight_solver(M_, options_, oo_);

%% Information arriving in period 5 (temporary shock in period 7)
options_.periods = 46;
% Simulation at 80%
disp('*** info_period=5, share=80%')
oo_.endo_simul = sim1_1.endo_simul(:,5:end);
oo_.exo_simul = sim1_1.exo_simul(5:end,:);
oo_.steady_state = sim1_1.steady_state;
oo_.exo_steady_state = sim1_1.exo_steady_state;
oo_.exo_simul(4,1) = 0.1-0.6*0.8;
sim1_5 = perfect_foresight_solver(M_, options_, oo_);
% Simulation at 79%
disp('*** info_period=5, share=79%')
oo_.endo_simul = sim2_1.endo_simul(:,5:end);
oo_.exo_simul = sim2_1.exo_simul(5:end,:);
oo_.steady_state = sim2_1.steady_state;
oo_.exo_steady_state = sim2_1.exo_steady_state;
oo_.exo_simul(4,1) = 0.1-0.6*0.79;
sim2_5 = perfect_foresight_solver(M_, options_, oo_);

%% Information arriving in period 10 (permanent shock now)
options_.periods = 41;
% Simulation at 80%
disp('*** info_period=10, share=80%')
oo_.endo_simul = sim1_5.endo_simul(:,6:end);
oo_.exo_simul = sim1_5.exo_simul(6:end,:);
oo_.exo_steady_state = 0.1+0.5*0.8;
oo_.steady_state = evaluate_steady_state(sim1_5.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:,end) = oo_.steady_state;
oo_.exo_simul(2:end,:) = oo_.exo_steady_state;
sim1_10 = perfect_foresight_solver(M_, options_, oo_);
% Simulation at 79%
disp('*** info_period=10, share=79%')
oo_.endo_simul = sim2_5.endo_simul(:,6:end);
oo_.exo_simul = sim2_5.exo_simul(6:end,:);
oo_.exo_steady_state = 0.1+0.5*0.79;
oo_.steady_state = evaluate_steady_state(sim2_5.steady_state, oo_.exo_steady_state, M_, options_, true);
oo_.endo_simul(:,end) = oo_.steady_state;
oo_.exo_simul(2:end,:) = oo_.exo_steady_state;
sim2_10 = perfect_foresight_solver(M_, options_, oo_);

%% Reconstruct the two simulations
sim1_endo_simul = [ sim1_1.endo_simul(:,1:5), sim1_5.endo_simul(:,2:6), sim1_10.endo_simul(:,2:end);];
sim2_endo_simul = [ sim2_1.endo_simul(:,1:5), sim2_5.endo_simul(:,2:6), sim2_10.endo_simul(:,2:end);];
sim1_exo_simul = [ sim1_1.exo_simul(1:5,:); sim1_5.exo_simul(2:6,:); sim1_10.exo_simul(2:end,:);];
sim2_exo_simul = [ sim2_1.exo_simul(1:5,:); sim2_5.exo_simul(2:6,:); sim2_10.exo_simul(2:end,:);];

%% Compute marginal linearization
endo_simul = sim1_endo_simul + 20*(sim1_endo_simul - sim2_endo_simul);
exo_simul = sim1_exo_simul + 20*(sim1_exo_simul - sim2_exo_simul);

endo_abs_diff = max(max(abs(pfwee_endo_simul-endo_simul)));
endo_rel_diff = max(max(abs(endo_simul./pfwee_endo_simul-1)));

fprintf('Max absolute difference on endogenous: %g\nMax relative difference on endogenous: %g%%\n', endo_abs_diff, 100*endo_rel_diff)

exo_abs_diff = max(max(abs(pfwee_exo_simul-exo_simul)));
exo_rel_diff = max(max(abs(exo_simul./pfwee_exo_simul-1)));

fprintf('Max absolute difference on exogenous: %g\nMax relative difference on exogenous: %g%%\n', exo_abs_diff, 100*exo_rel_diff)

if endo_abs_diff > 1e-3 || endo_rel_diff > 3e-3 || exo_abs_diff > 1e-15 || exo_rel_diff > 1e-13
  error('perfect foresight with expectation errors + marginal linearization gives wrong result')
end

end; // verbatim