-
Notifications
You must be signed in to change notification settings - Fork 25
/
recordFcn.m
177 lines (147 loc) · 8.09 KB
/
recordFcn.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
% Record numbers plotted
function [record] = recordFcn(plotType,record,V_1,V_a,peachcount,peachfile,...
tiall,Startdate,stime,qahead,...
varnames,names_shocks,fid0,finalRecord,varargin)
if V_1==1, j=1; else j=0; end % Applies to everything except Counterfactual by Shock and Counterfactual by Var
switch plotType
case 'Q4Q4 Table'
percent = varargin{1};
table = varargin{2};
Means_q4q4 = varargin{3};
Bands_q4q4 = varargin{4};
switch peachcount
case 1, record(end+j).type = 'Conditional Q4Q4 Table';
case 0, record(end+j).type = 'Unconditional Q4Q4 Table';
case 2, record(end+j).type = 'Semi-Conditional Q4Q4 Table';
end
record(end).labels = {'dates',[num2str(100*percent),' %LB'],'mean',[num2str(100*percent),' %UB']};
record(end).data(:,:,V_1) = [table' squeeze(Bands_q4q4(1,V_1,:,peachcount+1)), Means_q4q4(V_1,:,peachcount+1)',squeeze(Bands_q4q4(2,V_1,:,peachcount+1))];
case 'Forecast'
bandsp = varargin{1};
mlp = varargin{2};
switch peachcount
case 1, record(end+j).type = 'Conditional Forecast';
case 0, record(end+j).type = 'Unconditional Forecast';
case 2, record(end+j).type = 'Semi-Conditional Forecast';
end
record(end).labels = {'dates','90%LB','80%LB','70%LB','60%LB','50%LB','50%UB','60%UB','70%UB','80%UB','90%UB','mean'};
record(end).data(:,:,V_a) = [tiall(Startdate:(stime+qahead),:),bandsp(Startdate:end,:),mlp(Startdate:end)];
case 'Exp_Forecast'
bandsp = varargin{1};
mlp = varargin{2};
switch peachcount
case 1, record(end+j).type = 'Conditional Forecast';
case 0, record(end+j).type = 'Unconditional Forecast';
case 2, record(end+j).type = 'Semi-Conditional Forecast';
end
record(end).labels = {'dates','90%LB','80%LB','70%LB','60%LB','50%LB','50%UB','60%UB','70%UB','80%UB','90%UB','mean'};
record(end).data(:,:,V_a) = [tiall(Startdate:(stime+qahead),:),bandsp(Startdate:end,:),mlp(Startdate:end)];
bandsp = varargin{1};
mlp = varargin{2};
switch peachcount
case 1, record(end+j).type = 'Conditional Forecast';
case 0, record(end+j).type = 'Unconditional Forecast';
case 2, record(end+j).type = 'Semi-Conditional Forecast';
end
record(end).labels = {'dates','90%LB','80%LB','70%LB','60%LB','50%LB','50%UB','60%UB','70%UB','80%UB','90%UB','mean'};
record(end).data(:,:,V_a) = [tiall(Startdate:(stime+qahead),:),bandsp(Startdate:end,:),mlp(Startdate:end)];
case 'Shock Decomposition'
list = varargin{1};
mlp = varargin{2};
mlp_bar = varargin{3};
switch peachcount
case 1, record(end+j).type = 'Conditional Shock Decomposition';
case 0, record(end+j).type = 'Unconditional Shock Decomposition';
case 2, record(end+j).type = 'Semi-Conditional Shock Decomposition';
end
record(end).labels= {'dates','deviations from mean',list{:}};
%record(end).data(:,:,V_a) = [tiall(Startdate:(stime+qahead),:),mlp(Startdate:end),mlp_bar(Startdate:end,:)];
case '4Q Forecast'
bandsp = varargin{1};
mlp = varargin{2};
switch peachcount
case 1, record(end+j).type = 'Conditional 4Q Forecast';
case 0, record(end+j).type = 'Unconditional 4Q Forecast';
case 2, record(end+j).type = 'Semi-Conditional 4Q Forecast';
end
record(end).labels= {'dates','90%LB','80%LB','70%LB','60%LB','50%LB','50%UB','60%UB','70%UB','80%UB','90%UB','mean'};
record(end).data(:,:,V_a) = [tiall(Startdate:(stime+qahead),:),bandsp(Startdate:end,:),mlp(Startdate:end)];
case 'Counterfactual by Variable'
S_1 = varargin{1};
S_a = varargin{2};
Shseq = varargin{3};
mlp_counter_byvar = varargin{4};
if V_1==1 && S_1==1, j=1; else j=0; end
switch peachcount
case 1, record(end+j).type = 'Conditional Counterfactual by Variable Forecast';
case 0, record(end+j).type = 'Unconditional Counterfactual by Variable Forecast';
case 2, record(end+j).type = 'Semi-Conditional Counterfactual by Variable Forecast';
end
shock_label = names_shocks(Shseq);
record(end).labels= {'dates',shock_label{:}};
if S_1==1
record(end).data(:,1,V_a) = tiall(Startdate:(stime+qahead),:);
end
record(end).data(:,S_1+1,V_a) = [mlp_counter_byvar(Startdate:end)];
case 'Counterfactual by Shock'
S_1 = varargin{1};
S_a = varargin{2};
Shseq = varargin{3};
mlp_counter = varargin{4};
if S_1==1 && V_1==1, j=1; else j=0; end
switch peachcount
case 1, record(end+j).type = 'Conditional Counterfactual by Shock Forecast';
case 0, record(end+j).type = 'Unconditional Counterfactual by Shock Forecast';
case 2, record(end+j).type = 'Semi-Conditional Counterfactual by Shock Forecast';
end
var_label = varnames(Shseq);
record(end).labels= {'dates',var_label{:}};
if S_1==1
record(end).data(:,1,V_a) = tiall(Startdate:(stime+qahead),:);
end
record(end).data(:,S_1+1,V_a) = [mlp_counter(Startdate:end)];
case 'Shock'
Vseq = varargin{1};
mlp = varargin{2};
pnobss = varargin{3};
switch peachcount
case 1, record(end+j).type = 'Conditional Shock Innovation';
case 0, record(end+j).type = 'Unconditional Shock Innovation';
case 2, record(end+j).type = 'Semi-Conditional Shock Innovation';
end
shock_label = names_shocks(Vseq);
record(end).labels= {'dates',shock_label{:}};
if V_1==1
record(end).data(:,1) = tiall(Startdate:(stime+(logical(peachcount)*pnobss)),:);
end
record(end).data(:,V_1+1) = mlp(Startdate:(stime+(logical(peachcount)*pnobss)),:);
end
if finalRecord
% Record Dick Peach's forecast
load(peachfile)
fprintf(fid0, 'Conditional Data \n');
fprintf(fid0, '%s \n', peachfile);
eval(['fprintf(fid0, ''' repmat(' %s',1,length(data)) ' \n '', varnames{:});'])
eval(['fprintf(fid0, ''' repmat(' %4.5f',1,length(data)) ' \n '', data);'])
fprintf(fid0, ' \n');
% Record plotted data
for k = 1:length(record)
fprintf(fid0,'%s \n\n', record(k).type);
for v = 1:size(record(k).data,3)
if ~ismember(record(k).type,{'Semi-Conditional Shock Innovation';'Conditional Shock Innovation';'Unconditional Shock Innovation'})
if ismember(record(k).type,{'Semi-Conditional Counterfactual by Shock Forecast';'Conditional Counterfactual by Shock Forecast';'Unconditional Counterfactual by Shock Forecast'})
fprintf(fid0,'%s \n', char(names_shocks(v)));
else
fprintf(fid0,'%s \n', char(varnames(v)));
end
end
fprintf(fid0,'%s ', record(k).labels{:});
fprintf(fid0,' \n');
for a = 1:size(record(k).data,1)
eval(['fprintf(fid0, ''' repmat(' %4.5f',1,size(record(k).data,2)) ' \n '' ,[record(k).data(a,:,v)]);']);
end
fprintf(fid0,' \n \n');
end
end
end
end