Repository navigation
Expand file tree
/
Copy pathtest5_CCMM.m
More file actions
160 lines (123 loc) · 4.71 KB
/
Copy pathtest5_CCMM.m
File metadata and controls
160 lines (123 loc) · 4.71 KB
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
%% CCMM models
%
%
% Tutorial file for showcasing models from the paper _Addressing COVID-19 Outliers
% in BVARs with Stochastic Volatility estimators by_ Andrea Carriero,Todd E. Clark,
% Massimiliano Marcellino, Elmar Mertens
%% Housekeeping
clear
close all
clear classes
rehash path
import base.*
%% Convenience functions
% The |extremesFunc| function compresses any number of samples (draws from the
% posterior) into two numbers - the minimum and the maximum.
percentiles = [10, 50, 90];
prctileFunc = @(x) prctile(x, percentiles, 2);
extremesFunc = @(x) [min(x, [], 2), max(x, [], 2)];
medianFunc = @(x) median(x, 2);
%% Number of Samples
numPresampled = 100;
%% Prepare meta information for the models
% The meta information is the same as for the standard BVARs.
estimStart = datex.m(1960,3);
estimEnd = datex.m(2021,3);
estimSpan = datex.span(estimStart, estimEnd);
meta = Meta( ...
endogenous=["RPI","DPCERA3M086SBEA", "INDPRO","CUMFNS","UNRATE", "PAYEMS", "CES0600000007",...
"CES0600000008", "WPSFD49207", "PCEPI", "HOUST", "SP500", "EXUSUK", "GS5", "GS10", "BAAFFM"], ...
exogenous=[], ...
order=12, ...
intercept=true, ...
estimationSpan=estimSpan, ...
identificationHorizon=20 ...
);
%% Specifying and loading input data
inputTbx = tablex.fromFile("CCMMSV.csv");
dataH = DataHolder(meta, inputTbx);
%% Reduced form models
% There are some common settings for the models described in the paper. Since
% the models are organized hierarchically—starting from a basic SV model (very
% similar to the Cogley–Sargent specification) and extending it in two steps,
% first by introducing outliers and then by allowing for _t_-distributed residuals—the
% settings are also hierarchical. This means that broader models share parameters
% with the simpler ones, while introducing additional settings as the model becomes
% more complex. Therefore we only report here the additional settings for each
%
%
% *Basic SV model*
% Estimator sepcific settings:
%
% *HeteroskedasticityScale (0.15)* – prior on the scale of the inverse wishart
% distribution of the variance of the residual in heteroskedasticity
%
% *TurningPoint* – Used to set the prior of the transition matrix , since
% the OLS estimate for its prior mean is computed only up to this point
estimatorR1 = estimator.CCMMSV(meta, Turningpoint = datex.m(2020,3));
modelR1 = ReducedForm( ...
meta=meta, ...
dataHolder=dataH, ...
estimator=estimatorR1 ...
);
%
% *Model with outliers*
% Additional estimator sepcific settings:
%
% *OutlierFreq (10)* – mean outlier frequency, indicating how often outliers
% are expected to occur (in years)
%
% *PriorObsYears (10)* – strength of the outlier prior, with precision set
% to reflect the span of prior observations.
estimatorR2 = estimator.CCMMSVO(meta, Turningpoint = datex.m(2020,3), OutlierFreq = 4);
modelR2 = ReducedForm( ...
meta=meta, ...
dataHolder=dataH, ...
estimator=estimatorR2 ...
);
%
% *Model with outliers and _t-_distributed residual*
% Additional estimator sepcific settings:
%
% *DoFLowerBound (3)* – lower bound of degrees of freedom for the Student-t
% residuals
%
% *DoFUpperBound (40)* – upper bound of degrees of freedom for the Student-t
% residuals
estimatorR3 = estimator.CCMMSVOT(meta,...
Turningpoint = datex.m(2020,3), OutlierFreq = 4);
modelR3 = ReducedForm( ...
meta=meta, ...
dataHolder=dataH, ...
estimator=estimatorR3 ...
);
%% Estimation/sampling of the reduced form model
modelR1.initialize();
info1 = modelR1.presample(numPresampled);
modelR1.Presampled{1}
modelR2.initialize();
info2 = modelR2.presample(numPresampled);
modelR2.Presampled{1}
modelR3.initialize();
info3 = modelR3.presample(numPresampled);
modelR3.Presampled{1}
%% Running Unconditional forecast
%
% Settig up the forecast range and run the forecast
fcastStart = datex.shift(modelR1.Meta.EstimationEnd,1);
fcastEnd = datex.shift(modelR1.Meta.EstimationEnd, 12);
fcastSpan = datex.span(fcastStart, fcastEnd);
fcastStart, fcastEnd
fcastTbx1 = modelR1.forecast(fcastSpan);
fcastPrctileTbx1 = tablex.apply(fcastTbx1, prctileFunc);
fcastTbx2 = modelR2.forecast(fcastSpan);
fcastPrctileTbx2 = tablex.apply(fcastTbx2, prctileFunc);
fcastTbx3 = modelR3.forecast(fcastSpan);
fcastPrctileTbx3 = tablex.apply(fcastTbx3, prctileFunc);
% Visualize the unconditional forecast
chartpack.forecastPercentiles( ...
fcastPrctileTbx1, modelR1, FigureTitle ="Unconditional forecast with base SV")
chartpack.forecastPercentiles( ...
fcastPrctileTbx2, modelR2, FigureTitle ="Unconditional forecast with outliers")
chartpack.forecastPercentiles( ...
fcastPrctileTbx3, modelR3, FigureTitle ="Unconditional forecast with outliers and t distributed shocks")