-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbarplotBETAslopes.m
110 lines (86 loc) · 2.8 KB
/
barplotBETAslopes.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
%% plot BETA coefficients of general model at different jumpoffs
clear
close all
fclose all;
%% 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<*UNRCH>
%#ok<*NANMEAN>
%#ok<*DATNM>
%#ok<*DATST>
%% setup
doAR1SV = true;
datalabel = 'fredsxMD20exYield-2022-09';
p = 12;
if doAR1SV
resultsdir = pwd;
resultlabel = sprintf('ELBshadowrateGeneralAR1SV-RATSbvarshrinkage-p%d', p);
titlename = sprintf('barplotBETA-AR1SV-%s-p%d', datalabel, p);
else
resultsdir = pwd;
resultlabel = sprintf('ELBshadowrateGeneral-RATSbvarshrinkage-p%d', p);
titlename = sprintf('barplotBETA-%s-p%d', datalabel, p);
end
%% one wrapper per lag choice
wrap = [];
initwrap
%% load data
oos = matfile(fullfile(resultsdir, sprintf('%s-%s.mat', datalabel, resultlabel)));
ydates = oos.ydates;
Tjumpoffs = oos.Tjumpoffs;
dates = ydates(Tjumpoffs);
ncode = oos.ncode;
Ylabels = fredMDshortlabel(oos.ncode);
Ylabels = strrep(Ylabels, '_', '');
N = length(Ylabels);
ndxMacro = ~ismember(1:N,oos.ndxYIELDS);
Nmacro = sum(ndxMacro);
setQuantiles = oos.setQuantiles;
ndxTails68 = find(ismember(setQuantiles, normcdf11)); % find to enable indexing of matfile objects
ndxTails = find(ismember(setQuantiles, [5 95])); % find to enable indexing of matfile objects
%% barplot for given jumpoff
for thisT = length(Tjumpoffs) % [ 1 108 length(Tjumpoffs)]
betaColor = colors4plots("blue");
errorColor = colors4plots("lightblue");
theseBETAtails = oos.BETAquantiles(:,:,ndxTails,thisT);
theseBETAtails68 = oos.BETAquantiles(:,:,ndxTails68,thisT);
mid = oos.BETAmean(:, :, thisT);
hi = theseBETAtails(:,:,2) - mid;
lo = mid - theseBETAtails(:,:,1);
if hi < 0
error houston
end
if lo < 0
error houston
end
hi68 = theseBETAtails68(:,:,2) - mid;
lo68 = mid - theseBETAtails68(:,:,1);
if lo68 < 0
error houston
end
if hi68 < 0
error houston
end
thisfig = figure;
bar(1:Nmacro, mid, 'FaceColor', betaColor, 'EdgeColor','flat');
hold on
errorbar(1:Nmacro, mid, hi, lo, 'color', errorColor, 'linestyle', 'none', 'linewidth', 2);
% errorbar(1:Nmacro, mid, hi68, lo68, 'color', errorColor68, 'linestyle', 'none', 'linewidth', 2);
hold off
xticklabels(strrep(Ylabels(ndxMacro), '\', ''));
set(gca, "FontSize", 16)
set(gca, "box", "off")
grid on
% title(sprintf('BETA coefficients at jumpoff %s', datestr(dates(thisT))))
wrapthisfigure(thisfig, sprintf('%s-%s-%s', 'BETA', resultlabel, datestr(dates(thisT), 'yyyymm')), wrap)
end
%% finish
dockAllFigures
finishwrap
finishscript