-
Notifications
You must be signed in to change notification settings - Fork 0
/
NGDP_2024_nonlinear_SIM_transition_LAMBDA.m
274 lines (188 loc) · 8.33 KB
/
NGDP_2024_nonlinear_SIM_transition_LAMBDA.m
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
%NGDP_2024_nonlinear_sim_transition_LAMBDA
%Insert for the file NGDP_2024_nonlinear_transition_LOOP_LAMBDA.m which
%allows fast social welfare analysis for multiple social discount factors
%Nonlinear simulation of transition to NIT in the simple model (Algorithm in Supp Appendix).
%Written by Michael Hatcher ([email protected]). Any errors are my own.
pi = NaN(T_fin,1); tau = pi; c1 = pi; c2 = pi; Index = pi; Max_Resid = pi; Lambda_NIT = pi;
pi_prime = NaN(n_states^2,1); cprime = pi_prime; c_power = pi_prime; sdf_adj = pi_prime;
R = NaN(T_fin,1); EV = R; EV_reverse = R; Utility = R; U_IT = Utility; U_sum = R;
U_sum_1 = R; U_sum_2 = R; U_sum_3 = R; U_sum_4 = R; Resid_check = R;
Dummy_init = 1;
for t=1:T_sim
dummy_IT = 1;
if t==1
R_lag = R_init;
y_lag = y_init;
else
R_lag = R(t-1);
y_lag = y(t-1);
end
pi(t) = pistar*exp(e_vec(t))/(y(t)/y_lag)^(1-dummy_IT);
tau(t) = ( gbar + (R_lag/((1+n)*pi(t)) - 1)*bstar ) / y(t);
c1(t) = (1-alfa)*y(t) - tau(t)*y(t) - phi*tau(t)^2 - bstar;
c2(t) = alfa*(1+n)*y(t) + R_lag/pi(t)*bstar;
pi_prime = pistar*exp(states(:,1))*y(t)^(1-dummy_IT).*y_prime.^(-(1-dummy_IT));
Resid0 = NaN(N_guess0,1); Resid = NaN(N_guess,1);
for k0=1:N_guess0
Dum = 0;
R_guess = R_guess_stack0(k0);
cprime0 = alfa*(1+n)*y_prime + R_guess*bstar.*pi_prime.^(-1);
c_power0 = cprime0.^(1-gama);
E_c_power0 = prob*c_power0;
E_reverse0 = E_c_power0^(1/(1-gama));
sdf_adj0 = betta*c1(t)^(1-eps).*cprime0.^(eps-1)*( 1 / E_reverse0 )^(1-gama-eps).*cprime0.^(1-gama-eps).*pi_prime.^(-1);
Resid0(k0) = abs(1 - R_guess*prob*sdf_adj0);
if k0 > 1 && Resid0(k0) > Resid0(k0-1)
Dum = 1;
break
end
end
[Resid_mini0,Index_min0] = min(Resid0);
R_guess_stack = R_guess_stack0(Index_min0) + linspace(R_l,R_u,N_guess);
for k=1:N_guess
R_guess = R_guess_stack(k);
cprime = alfa*(1+n)*y_prime + R_guess*bstar.*pi_prime.^(-1);
c_power = cprime.^(1-gama);
E_c_power = prob*c_power;
E_reverse = E_c_power^(1/(1-gama));
sdf_adj = betta*c1(t)^(1-eps).*cprime.^(eps-1)*( 1 / E_reverse )^(1-gama-eps).*cprime.^(1-gama-eps).*pi_prime.^(-1);
Resid(k) = abs(1 - R_guess*prob*sdf_adj);
if k>1 && Resid(k) > Resid(k-1)
break
end
end
[Resid_mini,Index_min] = min(Resid);
R(t) = R_guess_stack(Index_min);
Max_Resid(t) = Resid_mini;
Index(t) = Index_min;
cprime = alfa*(1+n).*y_prime + R(t)*bstar.*pi_prime.^(-1);
c_power = cprime.^(1-gama);
EV(t) = prob*c_power;
Utility(t) = 1/(1-gama)*( c1(t)^eps + betta*( EV(t) )^(eps/(1-gama)) )^((1-gama)/eps);
end
if dummy_NIT==1
dummy_IT = 0;
end
if Announced == 1
Resid_init = NaN(N_guess_init,1);
pi_prime = pistar*exp(states(:,1))*y(T_sim)^(1-dummy_IT).*y_prime.^(-(1-dummy_IT));
for k_init=1:N_guess_init
R_guess = R_guess_stack_init(k_init);
cprime_init = alfa*(1+n)*y_prime + R_guess*bstar.*pi_prime.^(-1);
c_power_init = cprime_init.^(1-gama);
E_c_power_init = prob*c_power_init;
E_reverse_init = E_c_power_init^(1/(1-gama));
sdf_adj_init = betta*c1(T_sim)^(1-eps).*cprime_init.^(eps-1)*( 1 / E_reverse_init )^(1-gama-eps).*cprime_init.^(1-gama-eps).*pi_prime.^(-1);
Resid_init(k_init) = abs(1 - R_guess*prob*sdf_adj_init);
if k_init > 1 && Resid_init(k_init) > Resid_init(k_init-1)
break
end
end
[Resid_init,Index_init] = min(Resid_init);
R_ann = R_guess_stack_init(Index_init);
R(T_sim) = R_ann;
%-------------
%Initial old
%-------------
cprime_init = alfa*(1+n)*y_prime + R_ann*bstar.*pi_prime.^(-1);
c_power_init = cprime_init.^(1-gama);
E_c_power_init = prob*c_power_init;
Utility_init = 1/(1-gama)*( c1(T_sim)^eps + betta*( E_c_power_init )^(eps/(1-gama)) )^((1-gama)/eps);
else
%-------------
%Initial old
%-------------
pi_prime_init = pistar*exp(e_vec(T_sim+1))/(y(T_sim+1)/y(T_sim))^(1-dummy_IT);
cprime_init = alfa*(1+n)*y(T_sim+1) + R(T_sim)*bstar/pi_prime_init;
Utility_init = 1/(1-gama)*( c1(T_sim)^eps + betta*( cprime_init^(1-gama) )^(eps/(1-gama)) )^((1-gama)/eps);
%Utility_init = Utility(T_sim); %if use expected U of initial old
end
if dummy_IT == 1
U_IT_init = Utility_init;
else
load("test_lambda.mat","U_IT","U_IT_init")
%Utility_init = U_IT_init;
end
%------------
%Reform
%------------
for t=T_sim+1:T_fin
R_lag = R(t-1);
y_lag = y(t-1);
pi(t) = pistar*exp(e_vec(t))/(y(t)/y_lag)^(1-dummy_IT);
tau(t) = ( gbar + (R_lag/((1+n)*pi(t)) - 1)*bstar ) / y(t);
c1(t) = (1-alfa)*y(t) - tau(t)*y(t) - phi*tau(t)^2 - bstar;
c2(t) = alfa*(1+n)*y(t) + R_lag/pi(t)*bstar;
pi_prime = pistar*exp(states(:,1))*y(t)^(1-dummy_IT).*y_prime.^(-(1-dummy_IT));
Resid0 = NaN(N_guess0,1); Resid = NaN(N_guess,1);
for k0=1:N_guess0
Dum = 0;
R_guess = R_guess_stack0(k0);
cprime0 = alfa*(1+n)*y_prime + R_guess*bstar.*pi_prime.^(-1);
c_power0 = cprime0.^(1-gama);
E_c_power0 = prob*c_power0;
E_reverse0 = E_c_power0^(1/(1-gama));
sdf_adj0 = betta*c1(t)^(1-eps).*cprime0.^(eps-1)*( 1 / E_reverse0 )^(1-gama-eps).*cprime0.^(1-gama-eps).*pi_prime.^(-1);
Resid0(k0) = abs(1 - R_guess*prob*sdf_adj0);
if k0 > 1 && Resid0(k0) > Resid0(k0-1)
Dum = 1;
break
end
end
[Resid_mini0,Index_min0] = min(Resid0);
R_guess_stack = R_guess_stack0(Index_min0) + linspace(R_l,R_u,N_guess);
for k=1:N_guess
R_guess = R_guess_stack(k);
cprime = alfa*(1+n)*y_prime + R_guess*bstar.*pi_prime.^(-1);
c_power = cprime.^(1-gama);
E_c_power = prob*c_power;
E_reverse = E_c_power^(1/(1-gama));
sdf_adj = betta*c1(t)^(1-eps).*cprime.^(eps-1)*( 1 / E_reverse )^(1-gama-eps).*cprime.^(1-gama-eps).*pi_prime.^(-1);
Resid(k) = abs(1 - R_guess*prob*sdf_adj);
if k>1 && Resid(k) > Resid(k-1)
break
end
end
[Resid_mini,Index_min] = min(Resid);
R(t) = R_guess_stack(Index_min);
Max_Resid(t) = Resid_mini;
Index(t) = Index_min;
cprime = alfa*(1+n).*y_prime + R(t)*bstar.*pi_prime.^(-1);
c_power = cprime.^(1-gama);
E_c_power = prob*c_power;
E_reverse = E_c_power^(1/(1-gama));
SDF_check = betta*c1(t)^(1-eps).*cprime.^(eps-1)*( 1 / E_reverse )^(1-gama-eps).*cprime.^(1-gama-eps).*pi_prime.^(-1);
Resid_check(t) = abs(1 - R(t)*prob*SDF_check);
EV(t) = prob*c_power;
Utility(t) = 1/(1-gama)*( c1(t)^eps + betta*( EV(t) )^(eps/(1-gama)) )^((1-gama)/eps);
if t==T_sim+1
U_sum(t) = omega^(t-1-T_sim)*Utility(t) + omega^(-1)*Utility_init;
U_sum_1(t) = omega_1^(t-1-T_sim)*Utility(t) + omega_1^(-1)*Utility_init;
U_sum_2(t) = omega_2^(t-1-T_sim)*Utility(t) + omega_2^(-1)*Utility_init;
U_sum_3(t) = omega_3^(t-1-T_sim)*Utility(t) + omega_3^(-1)*Utility_init;
U_sum_4(t) = omega_4^(t-1-T_sim)*Utility(t) + omega_4^(-1)*Utility_init;
else
U_sum(t) = omega^(t-1-T_sim)*Utility(t);
U_sum_1(t) = omega_1^(t-1-T_sim)*Utility(t);
U_sum_2(t) = omega_2^(t-1-T_sim)*Utility(t);
U_sum_3(t) = omega_3^(t-1-T_sim)*Utility(t);
U_sum_4(t) = omega_4^(t-1-T_sim)*Utility(t);
end
if dummy_IT == 0
Lambda_NIT(t) = 100*( (Utility(t)/U_IT(t))^(1/(1-gama)) - 1); %Consumption equiv. welfare gain
Lambda_init = 100*( (Utility_init/U_IT_init)^(1/(1-gama)) - 1);
end
end
U_sum_tot = sum(U_sum(T_sim+1:T_fin));
U_sum_tot_1 = sum(U_sum_1(T_sim+1:T_fin));
U_sum_tot_2 = sum(U_sum_2(T_sim+1:T_fin));
U_sum_tot_3 = sum(U_sum_3(T_sim+1:T_fin));
U_sum_tot_4 = sum(U_sum_4(T_sim+1:T_fin));
if dummy_IT == 1
U_IT = Utility;
U_sum_IT = U_sum_tot;
U_sum_IT_1 = U_sum_tot_1;
U_sum_IT_2 = U_sum_tot_2;
U_sum_IT_3 = U_sum_tot_3;
U_sum_IT_4 = U_sum_tot_4;
end