-
Notifications
You must be signed in to change notification settings - Fork 3
/
ocp.m
180 lines (157 loc) · 7.12 KB
/
ocp.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
clear all; clc; close all;
dy_path='c:/dynare/5.1/matlab';
dy_root="c:/dynare/";
%dy_path='c:/dynare/4.5.7/matlab';
addpath(dy_path);
savepath=pwd;
addpath(pwd);
addpath(fullfile(pwd,'frequency'));
Time=100;
if(size(getenv('MODEL_NAME'), 1))
list_models = { getenv('MODEL_NAME') };
else
cd models
modelspath=pwd;
all = dir;
all = all(3:end);
list_models = {};
for i =1:size(all,1)
if all(i).isdir
list_models{end+1}=all(i).name;
end
end
cd ..
end
%list_models=list_models(20);
% main_epimmb( [modellist (string)], ...
% [macrovariablelist (string)],...
% horizon (number), re_simulate (0=no, 1=yes), ...
% [indicator_shock_size(0=model specific, 1=common) common_shock_size])
%main_epimmb(["HHK_20","AJRT_20","ACS_21","ERT_21_NK","KUX_20"],...
shocks=zeros(4,2); % number shocks x shock size
shocks(1,:)=[0 0]; %model specific
shocks(2,:)=[1 0.0005]; %low
shocks(3,:)=[1 0.001 ]; %medium
shocks(4,:)=[1 0.0025]; %large
%list_models = { 'BKM_22' }
shocklist={'Model-specific Initial Infections','Low Initial Infections','Medium Initial Infections','High Initial Infections'};
%macrovariablelist = unionvariable(list_models,savepath);
macrovariablelist = ["Consumption","Labour","Output","Susceptibles","Infected","Recovered","Deaths","Interest","Inflation","Investment"]; % list is put as an array to prepare future generation from json files
for index_m=1:size(list_models,2)
modelname=list_models{index_m};
if modelname == "CCGPRV_21"| modelname =="F_21"| modelname =="VDS_21" | modelname =="MY_21" | modelname=="CF_20"; % Model with only model specified shock
for index_s=1:size(shocks,1)
if index_s == 1
modelname=list_models{index_m};
shockname=shocklist{index_s};
str_modelname=string(modelname);
str_shockname=string(shockname);
json_filename=str_modelname+"-"+str_shockname+".output.json";
%cd(list_models{index_m})
results_mat=ocp_epimmb(list_models(index_m),macrovariablelist,[shocks(index_s,1) shocks(index_s,2)],dy_root);
if(~exist('results', 'file'))
mkdir results;
end
cd results
jso.model=modelname;
jso.shock=shockname;
for iii = 1:length(macrovariablelist)
eval(strcat("jso.data.", macrovariablelist(iii)," = results_mat(" , num2str(iii) , ",1:Time+1);"))
end
% jso.data.Consumption=results_mat(1,1:Time+1);
% jso.data.Labour=results_mat(2,1:Time+1);
% jso.data.Output=results_mat(3,1:Time+1);
% jso.data.Susceptibles=results_mat(4,1:Time+1);
% jso.data.Infected=results_mat(5,1:Time+1);
% jso.data.Recovered=results_mat(6,1:Time+1);
% jso.data.Deaths=results_mat(7,1:Time+1);
% jso.data.Interest=results_mat(8,1:Time+1);
% jso.data.Inflation=results_mat(9,1:Time+1);
% jso.data.Investment=results_mat(10,1:Time+1);
json_print=jsonencode(jso);
new_string = strrep(json_print, ',', ',\n');
% add a return character after curly brackets:
new_string = strrep(new_string, '{', '{\n');
new_string = strrep(new_string,'Interest','Nominal Interest Rate');
fid=fopen(json_filename,'w');
fprintf(fid, new_string);
fclose('all');
cd ..
else
modelname=list_models{index_m};
shockname=shocklist{index_s};
str_modelname=string(modelname);
str_shockname=string(shockname);
json_filename=str_modelname+"-"+str_shockname+".output.json";
%cd(list_models{index_m})
%results_mat=ocp_epimmb(list_models(index_m),macrovariablelist,[shocks(index_s,1) shocks(index_s,2)],dy_root);
if(~exist('results', 'file'))
mkdir results;
end
cd results
jso.model=modelname;
jso.shock=shockname;
for iii = 1:length(macrovariablelist)
eval(strcat("jso.data.", macrovariablelist(iii)," = nan(1,Time+1);"))
end
% jso.data.Consumption=nan(1,Time+1);
% jso.data.Labour=nan(1,Time+1);
% jso.data.Output=nan(1,Time+1);
% jso.data.Susceptibles=nan(1,Time+1);
% jso.data.Infected=nan(1,Time+1);
% jso.data.Recovered=nan(1,Time+1);
% jso.data.Deaths=nan(1,Time+1);
% jso.data.Interest=nan(1,Time+1);
% jso.data.Inflation=nan(1,Time+1);
% jso.data.Investment=nan(1,Time+1);
json_print=jsonencode(jso);
new_string = strrep(json_print, ',', ',\n');
% add a return character after curly brackets:
new_string = strrep(new_string, '{', '{\n');
new_string = strrep(new_string,'Interest','Nominal Interest Rate');
fid=fopen(json_filename,'w');
fprintf(fid, new_string);
fclose('all');
cd ..
end
end
else
for index_s=1:size(shocks,1)
modelname=list_models{index_m};
shockname=shocklist{index_s};
str_modelname=string(modelname);
str_shockname=string(shockname);
json_filename=str_modelname+"-"+str_shockname+".output.json";
%cd(list_models{index_m})
results_mat=ocp_epimmb(list_models(index_m),macrovariablelist,[shocks(index_s,1) shocks(index_s,2)],dy_root);
if(~exist('results', 'file'))
mkdir results;
end
cd results
jso.model=modelname;
jso.shock=shockname;
for iii = 1:length(macrovariablelist)
eval(strcat("jso.data.", macrovariablelist(iii)," = results_mat(" , num2str(iii) , ",1:Time+1);"))
end
% jso.data.Consumption=results_mat(1,1:Time+1);
% jso.data.Labour=results_mat(2,1:Time+1);
% jso.data.Output=results_mat(3,1:Time+1);
% jso.data.Susceptibles=results_mat(4,1:Time+1);
% jso.data.Infected=results_mat(5,1:Time+1);
% jso.data.Recovered=results_mat(6,1:Time+1);
% jso.data.Deaths=results_mat(7,1:Time+1);
% jso.data.Interest=results_mat(8,1:Time+1);
% jso.data.Inflation=results_mat(9,1:Time+1);
% jso.data.Investment=results_mat(10,1:Time+1);
json_print=jsonencode(jso);
new_string = strrep(json_print, ',', ',\n');
% add a return character after curly brackets:
new_string = strrep(new_string, '{', '{\n');
new_string = strrep(new_string,'Interest','Nominal Interest Rate');
fid=fopen(json_filename,'w');
fprintf(fid, new_string);
fclose('all');
cd ..
end
end
end