-
Notifications
You must be signed in to change notification settings - Fork 6
/
showQRTshadow2023.m
234 lines (178 loc) · 9.43 KB
/
showQRTshadow2023.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
%% 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/
%#ok<*DATNM>
%#ok<*DATST>
%% prep
clear; close all; clc;
fontsize = 14;
ELBbound = .125;
ELBcolor = Colors4Plots(8);
%% get LSAP dates
[lsapDates, lsapLabels] = getLSAPdates();
lsapDates = datenum(lsapDates);
ndxDropTaper = ~strcmpi(lsapLabels, 'taper begins');
lsapLabels = lsapLabels(ndxDropTaper);
lsapDates = lsapDates(ndxDropTaper);
tailNDX = [1 4]; % [1 4] for 90% or [2 3] for IQR
%% load stuff
%#ok<*UNRCH>
for MODELTYPE = {'ELBblockhybrid'}
modeltype = MODELTYPE{:};
for DATALABEL = {'fredblockMD20-2022-09', 'fredblockMD20exYield-2022-09'}
datalabel = DATALABEL{:};
switch ELBbound
case .25
resultsdir = '../matfilesShadowrateVAR/lagerFREDblock';
ELBtag = '';
ELBlegend = '25 bp';
switch datalabel
case 'fredblockMD20-2022-09'
YLIM = [-8 4];
case {'fredMD20exYield-2022-09', 'fredblockMD20exYield-2022-09'}
if strcmpi(modeltype, 'ELBhybrid')
YLIM = [-8 4];
else
YLIM = [-30 15];
end
otherwise
YLIM = [-4 4];
end
case .125
resultsdir = '../matfilesShadowrateVAR/lagerFREDblock';
ELBtag = '-ELB125';
ELBlegend = '12.5 bp';
switch datalabel
case 'fredMD20-2022-09'
YLIM = [-8 4];
case 'fredMD20exYield-2022-09'
YLIM = [-12 4];
otherwise
YLIM = [-12 4];
end
otherwise
error('ELBbound value of %5.2f not recognized', ELBbound)
end
titlename = sprintf('showQRTshadow-%s-%s%s', datalabel, modeltype, ELBtag);
initwrap
mat = matfile(fullfile(resultsdir, sprintf('%s-%s%s-RATSbvarshrinkage-p12.mat', datalabel, modeltype, ELBtag)));
shadowshortlabel = 'shadowrate';
Nvin = size(mat.shadowrateQRTmid,3);
firstQRTobs = mat.Tjumpoffs(1,1);
ydates = mat.ydates;
T = length(ydates);
p = mat.p;
shadowrateQRTmid = mat.shadowrateQRTmid;
shadowrateQRTtails = mat.shadowrateQRTtails;
shadowrateVintagesMid = mat.shadowrateVintagesMid;
shadowrateVintagesTails = mat.shadowrateVintagesTails;
ndxSHADOWRATE = mat.ndxSHADOWRATE;
%% patch in actual rate data
FREDmd = importdata(sprintf('%s.csv', datalabel),',');
checkdiff(ydates, FREDmd.data(3:end,1));
data = FREDmd.data(3:end,2:end);
ActualRateData = data(:,mat.ndxSHADOWRATE);
% patch QRT
ndxActual = isnan(shadowrateQRTmid);
shadowrateQRTmid(ndxActual) = ActualRateData(ndxActual);
for nn = 1 : size(shadowrateQRTtails,3)
this = shadowrateQRTtails(:,:,nn);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateQRTtails(:,:,nn) = this;
end
% patch FINAL
ndxActual = isnan(shadowrateVintagesMid(:,:,end));
this = shadowrateVintagesMid(:,:,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesMid(:,:,end) = this;
for nn = 1 : size(shadowrateVintagesTails,3)
this = shadowrateVintagesTails(:,:,nn,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesTails(:,:,nn,end) = this;
end
%% qrt vs final
for n = 1 : length(ndxSHADOWRATE)
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
hfinal = plotCI(shadowrateVintagesMid(:,n,end), squeeze(shadowrateVintagesTails(:,n,tailNDX,end)), ydates, [], 'k-', 'linewidth', 3);
hqrt = plot(ydates, shadowrateQRTmid(:,n), 'r-', 'linewidth', 3);
hqrttails = plot(ydates, squeeze(shadowrateQRTtails(:,n,tailNDX)), 'r-.', 'linewidth', 2);
% xtickdates(ydates([firstQRTobs end]))
xtickdates([datenum(2008,8,1) ydates(end)])
ylim(YLIM)
hELB = yline(ELBbound, ':', 'color', ELBcolor);
hl = legend([hfinal hqrt hELB], 'full sample', 'quasi-real time', ELBlegend, ...
'location', 'northwest', 'box', 'off', 'AutoUpdate', 'off');
wrapthisfigure(thisfig, sprintf('%s%d-QRTp%d-%s-%s%s', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap, [], [], [], [], true)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center');
set(hl, 'location', 'southeast', 'box','on');
wrapthisfigure(thisfig, sprintf('%s%d-QRTp%d-%s-%s%s-LSAP', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap)
delete(hLSAP); delete(hqrt); delete(hqrttails); delete(hl);
ylim(YLIM);
wrapthisfigure(thisfig, sprintf('%s%d-FINALp%d-%s-%s%s', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap, [], [], [], [], true)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center'); %#ok<NASGU>
wrapthisfigure(thisfig, sprintf('%s%d-FINALp%d-%s-%s%s-LSAP', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap, [], [], [], [], true)
end
%% patch in wuxia
wuxia = importdata('WUXIASHADOWRATE.csv');
wuxiaDates = wuxia.data(:,1);
wuxiaRate = wuxia.data(:,2);
%% patch in krippner
krippner = importdata('KRIPPNERSHADOWRATE.csv');
krippnerDates = krippner.data(:,1);
krippnerRate = krippner.data(:,2);
%% plot QRT vs WUXIA and Krippner
n = 1;
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
hfinal = plotCIredshades(shadowrateQRTmid(:,n,end), squeeze(shadowrateQRTtails(:,n,tailNDX,end)), ydates, [], 'r-', 'linewidth', 3);
% xtickdates(ydates([firstQRTobs end]))
xtickdates([datenum(2008,8,1) ydates(end)])
hwx = plot(wuxiaDates, wuxiaRate, '-.', 'color', Colors4Plots('lightblue'), 'linewidth', 3);
hkrip = plot(krippnerDates, krippnerRate, ':', 'color', Colors4Plots('darkblue'), 'linewidth', 3);
ylim(YLIM)
hELB = yline(ELBbound, ':', 'color', ELBcolor);
hl = legend([hfinal hwx hkrip hELB], 'Shadow-rate VAR', 'Wu-Xia', 'Krippner', ELBlegend, ...
'location', 'southeast', 'box', 'off', 'AutoUpdate', 'off');
wrapthisfigure(thisfig, sprintf('%s%d-QRTp%d-%s-%s%s-wuxiakrippner', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap, [], [], [], [], true)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center'); %#ok<NASGU>
set(hl, 'location', 'southeast', 'box','on');
wrapthisfigure(thisfig, sprintf('%s%d-QRTp%d-%s-%s%s-wuxiakrippner-LSAP', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap)
%% plot FINAL vs WUXI and Krippner
n = 1;
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
hfinal = plotCI(shadowrateVintagesMid(:,n,end), squeeze(shadowrateVintagesTails(:,n,tailNDX,end)), ydates, [], 'k-', 'linewidth', 3);
% xtickdates(ydates([firstQRTobs end]))
xtickdates([datenum(2008,8,1) ydates(end)])
hwx = plot(wuxiaDates, wuxiaRate, '-.', 'color', Colors4Plots('lightblue'), 'linewidth', 3);
hkrip = plot(krippnerDates, krippnerRate, ':', 'color', Colors4Plots('darkblue'), 'linewidth', 3);
ylim(YLIM)
hELB = yline(ELBbound, ':', 'color', ELBcolor);
hl = legend([hfinal hwx hkrip hELB], 'Shadow-rate VAR', 'Wu-Xia', 'Krippner', ELBlegend, ...
'location', 'southeast', 'box', 'off', 'AutoUpdate', 'off');
wrapthisfigure(thisfig, sprintf('%s%d-FINALp%d-%s-%s%s-wuxiakrippner', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap, [], [], [], [], true)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center');
set(hl, 'location', 'southeast', 'box','on');
wrapthisfigure(thisfig, sprintf('%s%d-FINALp%d-%s-%s%s-wuxiakrippner-LSAP', shadowshortlabel, n, p, datalabel, modeltype, ELBtag), wrap)
%% tabulate values
tabname = sprintf('%s%d-p%d-%s-%s', shadowshortlabel, n, p, datalabel, modeltype);
data4table = [shadowrateQRTmid(:,n) shadowrateVintagesMid(:,n,end)];
labels4table = {'Shadow rate (QRT)', 'Shadow rate (final)'};
sam = firstQRTobs : T;
writedatatable(wrap, tabname, ydates(sam), data4table(sam,:), labels4table, 'yyyy-mm');
% writedatatable2tex(wrap, tabname, ydates(sam), data4table(sam,:), labels4table, 'yyyy-mm');
%% wrap up
dockAllFigures
finishwrap
% wrap = latexwrapper(wrap, 'close');
end
end