-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshowShadowrates.m
197 lines (153 loc) · 7.05 KB
/
showShadowrates.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
%% collect shadow rate series as plotted in Figure 2 of the paper and store as a csv table
%% 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;
% labels for Panel(a) exYield
datalabel = 'fredsxMD20exYield-2022-09';
modeltype1 = 'ELBnonstructuralAR1SV';
prettylabel1 = 'Non-structural shadow-rate VAR';
modeltype2 = 'ELBshadowrateGeneralAR1SV';
prettylabel2 = 'General shadow-rate VAR';
% labels for Panel(b) withYield
datalabel3 = 'fredsxMD20-2022-09';
modeltype3 = 'ELBblocknonstructuralAR1SV';
prettylabel3 = 'Non-structural shadow-rate VAR (w/restrictions)';
YLIM = [-8 6];
ELBbound = .25;
ELBcolor = colors4plots(8);
ELBtag = '';
ELBlegend = '25 bp';
resultsdir = pwd;
%% 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>
titlename = sprintf('showShadowrate%s', ELBtag);
initwrap
mat1 = matfile(fullfile(resultsdir, sprintf('%s-%s%s-RATSbvarshrinkage-p12.mat', datalabel, modeltype1, ELBtag)));
mat2 = matfile(fullfile(resultsdir, sprintf('%s-%s%s-RATSbvarshrinkage-p12.mat', datalabel, modeltype2, ELBtag)));
mat3 = matfile(fullfile(resultsdir, sprintf('%s-%s%s-RATSbvarshrinkage-p12.mat', datalabel3, modeltype3, ELBtag)));
shadowshortlabel = 'shadowrate';
ydates = mat1.ydates;
if ydates ~= mat2.ydates
error('date mismatch')
end
T = length(ydates);
p = mat1.p;
shadowrateVintagesMid1 = mat1.shadowrateVintagesMid;
shadowrateVintagesTails1 = mat1.shadowrateVintagesTails;
shadowrateVintagesMid2 = mat2.shadowrateVintagesMid;
shadowrateVintagesTails2 = mat2.shadowrateVintagesTails;
shadowrateVintagesMid3 = mat3.shadowrateVintagesMid;
shadowrateVintagesTails3 = mat3.shadowrateVintagesTails;
ndxSHADOWRATE = mat1.ndxSHADOWRATE;
if ~isequal(ndxSHADOWRATE, mat2.ndxSHADOWRATE)
error('ndxSHADOWRATE mismatch')
end
%% 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(:,ndxSHADOWRATE);
% patch mat1
ndxActual = isnan(shadowrateVintagesMid1(:,:,end));
this = shadowrateVintagesMid1(:,:,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesMid1(:,:,end) = this;
for nn = 1 : size(shadowrateVintagesTails1,3)
this = shadowrateVintagesTails1(:,:,nn,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesTails1(:,:,nn,end) = this;
end
% patch mat2
this = shadowrateVintagesMid2(:,:,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesMid2(:,:,end) = this;
for nn = 1 : size(shadowrateVintagesTails2,3)
this = shadowrateVintagesTails2(:,:,nn,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesTails2(:,:,nn,end) = this;
end
% patch mat3
this = shadowrateVintagesMid3(:,:,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesMid3(:,:,end) = this;
for nn = 1 : size(shadowrateVintagesTails3,3)
this = shadowrateVintagesTails3(:,:,nn,end);
this(ndxActual) = ActualRateData(ndxActual);
shadowrateVintagesTails3(:,:,nn,end) = this;
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 comparison exYield
n = 1; % FFR
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
h1 = plotCI(shadowrateVintagesMid1(:,n,end), squeeze(shadowrateVintagesTails1(:,n,tailNDX,end)), ydates, [], 'k-', 'linewidth', 3);
h2 = plot(ydates, shadowrateVintagesMid2(:,n,end), 'r-.', 'linewidth', 3);
h2tails = plot(ydates, squeeze(shadowrateVintagesTails2(:,n,tailNDX,end)), 'r-.', 'linewidth', 2);
% replot mid
plot(ydates, shadowrateVintagesMid1(:,n,end), 'k-', 'linewidth', 3);
xtickdates([datenum(2006,1,1) ydates(end)])
ylim(YLIM)
hELB = yline(ELBbound, ':', 'color', ELBcolor);
hl = legend([h1(1) h2 hELB], prettylabel1, prettylabel2, ELBlegend, ...
'location', 'northwest', 'box', 'off', 'AutoUpdate', 'off');
thiswrapname = sprintf('%s%d-p%d-%s-%s-vs-%s%s', shadowshortlabel, n, p, datalabel, modeltype1,modeltype2, ELBtag);
wrapthisfigure(thisfig, thiswrapname, wrap, [], [], [], [], true)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center'); %#ok<NASGU>
set(hl, 'location', 'southeast', 'box','on');
wrapthisfigure(thisfig, strcat(thiswrapname, '-LSAP'), wrap)
%% plot comparison withYield against WuXia Krippner
n = 1;
thisfig = figure;
set(gca, 'fontsize', fontsize)
hold on
hfinal = plotCI(shadowrateVintagesMid3(:,n,end), squeeze(shadowrateVintagesTails3(:,n,tailNDX,end)), ydates, [], 'k-', 'linewidth', 3);
xtickdates([datenum(2006,1,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], prettylabel3, 'Wu-Xia', 'Krippner', ELBlegend, ...
'location', 'southeast', 'box', 'off', 'AutoUpdate', 'off');
thiswrapname = sprintf('%s%d-p%d-%s-%s%s-wuxiakrippner', shadowshortlabel, n, p, datalabel3, modeltype3, ELBtag);
wrapthisfigure(thisfig, thiswrapname, wrap)
hLSAP = xline(lsapDates, '--', lsapLabels, 'fontsize', fontsize, 'LabelVerticalAlignment', 'top', 'LabelHorizontalAlignment', 'center');
set(hl, 'location', 'southeast', 'box','on');
wrapthisfigure(thisfig, strcat(thiswrapname, '-LSAP'), wrap)
%% tabulate values
tabname = 'CCMMshadowrates';
data4table = [shadowrateVintagesMid1(:,n,end), squeeze(shadowrateVintagesTails1(:,n,tailNDX,end)), ...
shadowrateVintagesMid2(:,n,end), squeeze(shadowrateVintagesTails2(:,n,tailNDX,end)), ...
shadowrateVintagesMid3(:,n,end), squeeze(shadowrateVintagesTails3(:,n,tailNDX,end))];
labels4table = {sprintf('Median: %s (ex Yields)', prettylabel1), sprintf('5%%: %s (ex Yields)', prettylabel1), sprintf('95%%: %s (ex Yields)', prettylabel1), ...
sprintf('Median: %s (ex Yields)', prettylabel2), sprintf('5%%: %s (ex Yields)', prettylabel2), sprintf('95%%: %s (ex Yields)', prettylabel2), ...
sprintf('Median: %s (w/Yields)', prettylabel3), sprintf('5%%: %s (w/Yields)', prettylabel3), sprintf('95%%: %s (w/Yields)', prettylabel3)};
sam = ydates >= datenum(2006,1,1);
writedatatable(wrap, tabname, ydates(sam), data4table(sam,:), labels4table, 'yyyy-mm');
%% wrap up
dockAllFigures
finishwrap