-
Notifications
You must be signed in to change notification settings - Fork 13
/
robust_no_recalibrate_gbm.m
178 lines (124 loc) · 6.24 KB
/
robust_no_recalibrate_gbm.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
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
growth_r_moments = load('./data/growth_and_r_moments.csv', '-ascii');
firm_moments = load('./data/firm_moments.csv', '-ascii');
bejk_moments = load('./data/bejk_moments.csv', '-ascii');
trade_moments = load('./data/trade_moments.csv', '-ascii');
entry_moments = load('./data/entry_moment.csv', '-ascii');
load('cal_params')
disp('Calbirated values computed on date')
disp(T)
disp('')
disp('')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delta_param = entry_moments(1,1);
params.zeta = 1.00;
params.gtarget = growth_r_moments(2);
params.rho = growth_r_moments(1) - params.gtarget;
M = 500;
z_bar = 7.0;
addpath('./eq_functions');
addpath('./markov_chain');
% Generating grids and stationary distribution
z = linspace(0, z_bar, M); %The grid, if useful at all.
%The following are invariant as long as M and z are fixed
[L_1_minus, L_2] = generate_stencils(z);
params.zgridL1 = L_1_minus;
params.zgridL2 = L_2;
params.zgridz = z;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
params.gamma = 1.0001;
params.n = 10; % number of countries
params.eta = 0; % denomination of adaption costs
params.Theta = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% moments...
quantile_moments = [firm_moments(1,:); firm_moments(2,:)];
quantile_moments = repmat(1-sum(quantile_moments,2),1,4)/4 + quantile_moments;
% This just ensures they add up to one since, the moments are averaged
% accros years, they don't exactly sum up
moments.quantile_moments = quantile_moments;
moments.other_moments = [params.gtarget,trade_moments(1,1),bejk_moments(1,1),bejk_moments(2,1)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
chi_scale = [0.90, 1, 1.10];
closest_chi = [];
for yyy = 1:length(chi_scale)
scale = 1;
load('cal_params')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
params.d = new_cal(1);
params.theta = new_cal(2);
params.kappa = new_cal(3);
params.delta = delta_param;
params.sigma = new_cal(7);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
params.chi = 1/ (new_cal(4)*chi_scale(yyy));
params.mu = new_cal(5).*scale;
params.upsilon = new_cal(6).*scale;
disp('Chi Values')
disp(params.chi)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[baseline, b_welfare] = compute_growth_fun_cal(params);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
low_tau = (new_cal(1)-1).*0.90 + 1;
params.d = low_tau;
[counterfact, c_welfare] = compute_growth_fun_cal(params);
params.d = new_cal(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda_gain = exp((params.rho).*(c_welfare - b_welfare)) - 1;
record_values = [];
cal_params = [];
record_values = [record_values; baseline(1,1),counterfact(1,1),baseline(1,1)-counterfact(1,1),lambda_gain, params.upsilon];
params.dT = (new_cal(1)-1).*0.90 + 1;
%{'theta', 'kappa', 'chi', 'mu', 'upsilon', 'zeta', 'delta', 'N', 'gamma', 'eta', 'Theta', 'd_0', 'd_T'};
cal_params = [cal_params; baseline(1,1), params.theta, params.kappa, params.chi, params.mu, params.upsilon, params.zeta, params.delta...
params.n, 1.0, params.eta, params.Theta, params.d, params.dT, params.rho, params.sigma];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mu_param = params.mu;
upsilon_param = params.upsilon;
scale_values = linspace(.1,2,200);
for zzz = 1:length(scale_values)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
scale = scale_values(zzz);
params.mu = mu_param.*scale;
params.upsilon = upsilon_param.*scale;
params.d = new_cal(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[baseline, b_welfare] = compute_growth_fun_cal(params);
%cal_params = [cal_params; baseline(1,1), params.d, params.theta,...
% params.kappa, 1/params.chi, params.mu, params.upsilon, params.sigma, params.delta];
params.dT = (new_cal(1)-1).*0.90 + 1;
%{'theta', 'kappa', 'chi', 'mu', 'upsilon', 'zeta', 'delta', 'N', 'gamma', 'eta', 'Theta', 'd_0', 'd_T'};
cal_params = [cal_params; baseline(1,1), params.theta, params.kappa, params.chi, params.mu, params.upsilon, params.zeta, params.delta...
params.n, 1.0, params.eta, params.Theta, params.d, params.dT, params.rho, params.sigma];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
params.d = params.dT;
[counterfact, c_welfare] = compute_growth_fun_cal(params);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda_gain = exp((params.rho).*(c_welfare - b_welfare)) - 1;
record_values = [record_values; baseline(1,1),counterfact(1,1),baseline(1,1)-counterfact(1,1),lambda_gain, params.upsilon];
end
%disp(record_values)
filename = join(['./output/robust/gbm/norecalibrate_values_gbm_',num2str(chi_scale(yyy)),'.mat']);
chi_value = params.chi;
save(filename ,'record_values', 'chi_value')
filename_two = join(['./output/robust/gbm/param_values_gbm_',num2str(chi_scale(yyy)),'.mat']);
save(filename_two ,'cal_params')
[~,idx] = min(abs(cal_params(:,1)-params.gtarget));
disp('Parameters for given chi which deliver growth closest to baseline growth')
header = {'g', 'theta', 'kappa', 'chi', 'mu', 'upsilon', 'zeta', 'delta', 'N', 'gamma', 'eta', 'Theta', 'd_0', 'd_T'};
disp(header)
disp([cal_params(idx,:)])
filename = join(['../../parameters/calibration_chi_',num2str(round(params.chi,2)),'.csv']);
header = {'theta', 'kappa', 'chi', 'mu', 'upsilon', 'zeta', 'delta', 'N', 'gamma', 'eta', 'Theta', 'd_0', 'd_T', 'rho', 'sigma'};
writecell([header; num2cell(cal_params(idx,2:end))],filename)
closest_chi = [closest_chi; cal_params(idx,2:end)];
end
save('./output/robust/gbm/closest_chi_params' ,'closest_chi')
%writematrix(closest_chi,'./output/robust/gbm/closest_chi_params.csv')
%
%writecell([header; num2cell(closest_chi)],'../../parameters/closest_chi_params.csv')
rmpath('./eq_functions');
rmpath('./markov_chain');