-
Notifications
You must be signed in to change notification settings - Fork 6
/
plotVARshadowrateMissingData.m
305 lines (218 loc) · 8.81 KB
/
plotVARshadowrateMissingData.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
%% plot shadow rate / missing-data rate
%#ok<*DATNM>
%#ok<*DATST>
%#ok<*NOSEL>
%#ok<*DISPLAYPROG>
%#ok<*UNRCH>
%#ok<*DLABINDEX>
%% load em toolboxes
warning('off','MATLAB:handle_graphics:exceptions:SceneNode')
path(pathdef)
addpath matlabtoolbox/emtools/
addpath matlabtoolbox/emtexbox/
addpath matlabtoolbox/emgibbsbox/
addpath matlabtoolbox/emeconometrics/
addpath matlabtoolbox/emstatespace/
%% Initial operations
clear; close all; clc;
%% set parameters for VAR and MCMC
datalabel = 'fredMD20exYield-2022-09';
p = 12; % Number of lags on dependent variables
jumpoffDate = datenum(2022,8,1);
doRATSprior = true;
samStart = []; % truncate start of sample if desired (leave empty if otherwise)
ELBbound = 0.25;
np = 12;
%% process ELB setting
switch ELBbound
case .25
resultsdir = '~/jam/lager/QUANTICO/quantico2023logscoresXL/';
ELBtag = '';
ELBlegend = '25 bp';
switch datalabel
case 'fredMD20exYield-2022-09';
YLIM = [-14 4];
case 'fredMD20-2022-09';
YLIM = [-8 4];
end
case .125
resultsdir = '~/jam/lager/quantico2023logscoresELB125/';
ELBtag = '-ELB125';
ELBlegend = '12.5 bp';
YLIM = [-8 4]; % set common yaxis limits for all plots
case .5
resultsdir = '~/jam/lager/quantico2023logscoresELB500/';
ELBtag = '-ELB500';
ELBlegend = '50 bp';
YLIM = [-14 4]; % set common yaxis limits for all plots
otherwise
error('ELBbound value of %5.2f not recognized', ELBbound)
end
%% load results
modellabel = 'ShadowVsMissingRateSampling';
if doRATSprior
modellabel = strcat(modellabel, '-RATSbvarshrinkage');
end
titlename=sprintf('%s%s-%s-p%d', datalabel, ELBtag, modellabel, p);
if ~isempty(samStart)
titlename = strcat(titlename,'-', datestr(samStart, 'yyyymmm'));
end
load(fullfile(resultsdir, sprintf('do-%s.mat', titlename)))
% patch
if ELBbound == .5
ELBtag = '-ELB500';
end
%% start latexwrapper to collect results
initwrap
fontsize = 16;
%% plot shadowrate
for n = 1 : Nshadowrates
ELBjumpoff = p + elbT0;
thesedates = ydates(ELBjumpoff+1:thisT);
ndxELB = ELBdummy(ELBjumpoff+1:thisT);
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
h0 = plotCI(shadowrateMid(:,n), squeeze(shadowrateTails(:,n,[1 4])), thesedates, [], 'k-', 'linewidth', 3);
plothorzline(ELBbound, [], 'k--')
% ylim([-2.5 2.5])
xtickdates(thesedates)
h3 = plot(thesedates, missingrateMid(:,n), 'r-.', 'linewidth', 3);
h3b = plot(thesedates, squeeze(missingrateTails(:,n,[1 4])), 'r-', 'linewidth', 2);
legend([h0 h3], 'shadow-rate sampling', 'missing-data sampling', 'location', 'best')
ylim(YLIM)
wrapthisfigure(thisfig, sprintf('shadowrate%d-vs-missingrate-%s%s', n, datalabel, ELBtag), wrap)
% missing-data draw comparison
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
h3 = plot(thesedates, missingrate2Mid(:,n), 'b-.', 'linewidth', 3);
plot(thesedates, squeeze(missingrate2Tails(:,n,[1 4])), 'b-', 'linewidth', 2);
plothorzline(ELBbound, [], 'k--')
xtickdates(thesedates)
ylim(YLIM)
wrapthisfigure(thisfig, sprintf('shadowrate%d-vs-missingrate-MissingDataSampling-%s%s-step1', n, datalabel, ELBtag), wrap)
h1 = plot(thesedates, missingrateMid(:,n), 'r-', 'linewidth', 3);
plot(thesedates, squeeze(missingrateTails(:,n,[1 4])), 'r-', 'linewidth', 2)
legend([h1 h3], 'shadow-rate VAR', 'missing-data VAR', 'location', 'best')
wrapthisfigure(thisfig, sprintf('shadowrate%d-vs-missingrate-MissingDataSampling-%s%s', n, datalabel, ELBtag), wrap)
end
%% 2-panel version
medianPAIshadow = squeeze(median(PAIshadow, 1));
medianPAImissing = squeeze(median(PAImissing, 1));
ndxLag1 = 1 + (1:N);
ndxLagOther = N + 2 : K;
for n = 1 : N
thisfig = figure;
subplot(1,2,1)
set(gca, 'fontsize', 16)
hold on
hlag = plot(medianPAIshadow(2:end,n), medianPAImissing(2:end,n), 'rx', 'linewidth', 2);
plot(medianPAIshadow(1,n), medianPAImissing(1,n), 'bx', 'linewidth', 2)
hint = plot(medianPAIshadow(1,n), medianPAImissing(1,n), 'bo', 'linewidth', 2);
legend([hlag hint], 'Lag coefficients', 'Intercept', 'location', 'best')
xlabel('Shadow-rate VAR coeffs ')
ylabel('Missing-rate VAR coeffs')
title('all coefficients')
subplot(1,2,2)
set(gca, 'fontsize', 16)
hold on
hlagX = plot(medianPAIshadow(ndxLagOther,n), medianPAImissing(ndxLagOther,n), 'kx', 'linewidth', 2);
hlag1 = plot(medianPAIshadow(ndxLag1,n), medianPAImissing(ndxLag1,n), 'rx', 'linewidth', 2);
% plot(medianPAIawayelb(1,n), medianPAIatelb(1,n), 'bx', 'linewidth', 2)
% hint = plot(medianPAIawayelb(1,n), medianPAIatelb(1,n), 'bo', 'linewidth', 2);
legend([hlag1 hlagX], 'Lag 1 coefficients', 'other lags', 'location', 'best')
xlabel('Shadow-rate VAR coeffs ')
ylabel('Missing-rate VAR coeffs')
title('all (w/o intercept)')
wrapthisfigure(thisfig, sprintf('simple-%s%s-PAI-%s', datalabel, ELBtag, ncode{n}), wrap)
end
%% scatter of intercepts
thisfig = figure;
set(gca, 'fontsize', 16)
hold on
plot(medianPAIshadow(1,:), medianPAImissing(1,:), 'bx', 'linewidth', 2);
xlabel('Shadow-rate VAR coeffs ')
ylabel('Missing-rate VAR coeffs')
title('all intercepts')
wrapthisfigure(thisfig, sprintf('simple-%s%s-interceptPAI', datalabel, ELBtag), wrap)
%% scatter of all
scatter = ols(medianPAIshadow(:), [ones(length(medianPAIshadow(:)), 1) medianPAImissing(:)]);
% prt(scatter)
thisfig = figure;
set(gca, 'fontsize', 16)
hold on
hlag = plot(vec(medianPAIshadow(2:end,:)), vec(medianPAImissing(2:end,:)), 'kx', 'linewidth', 2);
hint = plot(medianPAIshadow(1,:), medianPAImissing(1,:), 'rx', 'linewidth', 2);
xlabel('Shadow-rate VAR')
ylabel('Missing-rate VAR')
h45 = plot(xlim, ylim, 'k--');
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-allPAI', datalabel, ELBtag), wrap)
legend([hlag, hint, h45], 'Lag coefficients', 'Intercepts', '45 degrees', ...
'box', 'off', 'location', 'northwest')
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-allPAI-WITHLEGEND', datalabel, ELBtag), wrap)
title(sprintf('R^2 = %4.2f', scatter.rsqr))
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-allPAI-withR2', datalabel, ELBtag), wrap)
stdabsresid = abs(scatter.resid); % / sqrt(scatter.sige);
[~, sortndx] = sort(stdabsresid);
cutoff = stdabsresid(sortndx) > 2;
[PAIrow, PAIcol] = ind2sub(size(medianPAIshadow), sortndx(cutoff));
unique(Ylabels(PAIcol))
%% lag scatter only
thisfig = figure;
set(gca, 'fontsize', 16)
hold on
hlag = plot(vec(medianPAIshadow(2:end,:)), vec(medianPAImissing(2:end,:)), 'kx', 'linewidth', 2);
xlabel('Shadow-rate VAR')
ylabel('Missing-rate VAR')
h45 = plot(xlim, ylim, 'k--');
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-PAIlag', datalabel, ELBtag), wrap)
% legend([hlag, hint, h45], 'Lag coefficients', 'Intercepts', '45 degrees', ...
% 'box', 'off', 'location', 'northwest')
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-PAIlag-WITHLEGEND', datalabel, ELBtag), wrap)
title(sprintf('R^2 = %4.2f', scatter.rsqr))
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-PAIlag-withR2', datalabel, ELBtag), wrap)
%% standardized PAI changes
% PAI0 = squeeze(mean(PAImissing, 1));
% PAI0se = squeeze(std(PAImissing, 1, 1));
% PAImean = squeeze(mean(PAIshadow, 1));
% PAIdevs = (PAImean - PAI0) ./ PAI0se;
%
% maxRED = 2.5;
% plot all
thisfig = figure;
hb = surf(1:N,1:K,abs(PAIdevs));
xlim([1 N])
xticks(1:N)
xticklabels(Ylabels);
yticks([1, 1 + 3 * N])
yticklabels({'intercepts', 'lags'});
% caxis([0 maxRED])
% color by height
shading interp
colorbar
colormap turbo
set(gca, 'fontsize', 12)
view(-20,67)
wrapthisfigure(thisfig, sprintf('simple-%s%s-ELBPAIall', datalabel, ELBtag), wrap);
%% compare SV
shadowSVmid = squeeze(median(SVshadow,1));
shadowSVtails = squeeze(prctile(SVshadow, setQuantiles,1));
missingSVmid = squeeze(median(SVmissing,1));
missingSVtails = squeeze(prctile(SVmissing, setQuantiles,1));
thesedates = ydates(ELBjumpoff:thisT);
for n = 1 : N
thisfig = figure;
hold on
set(gca, 'fontsize', 16)
hShadow = plot(thesedates, shadowSVmid(ELBjumpoff-p:end,n), 'r-', 'linewidth', 2);
hMissing = plot(thesedates, missingSVmid(ELBjumpoff-p:end,n), 'k--', 'linewidth', 2);
xtickdates(thesedates)
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-SVmid-%s', datalabel, ELBtag, ncode{n}), wrap)
legend([hShadow hMissing], 'Shadow-rate VAR', 'Missing-rate VAR', 'box', 'on', 'location', 'best')
wrapthisfigure(thisfig, sprintf('simple-%s%s-missing-vs-shadow-SVmid-%s-WITHLEGEND', datalabel, ELBtag, ncode{n}), wrap)
end
%% wrap up
dockAllFigures
finishwrap
finishscript