Debian Codegraph @

tests/reporting/runDynareReport.m

raw
1 function runDynareReport(dc_a, dc_q, db_a, db_q)
2 %function runDynareReport(dc_a, dc_q, db_a, db_q)
3
4 % Copyright © 2013-2023 Dynare Team
5 %
6 % This file is part of Dynare.
7 %
8 % Dynare is free software: you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version.
12 %
13 % Dynare is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
17 %
18 % You should have received a copy of the GNU General Public License
19 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
20
21 tic
22 larange= dates('2007a'):dates('2014a');
23 trange = dates('2012q2'):dates('2014q4');
24 prange = dates('2007q1'):dates('2013q4');
25 forecast_date = dates('2012q2');
26 srange = forecast_date:prange(end);
27
28 startpoint = strings(prange(1));
29 shaded = strings(srange(1));
30 endpoint = strings(prange(end));
31
32 shortNames = {'US', 'EU', 'JA', 'EA6', 'LA6', 'RC6'};
33 longNames = {'Coca Cola', 'Kinder Bueno', 'Pizza', ...
34 'Vegetarianism Is Good', 'OS X', 'Dothraki'};
35
36 %% Begin Report
37 rep = report('directory', 'my/report/dir', 'title', 'Report Title', ...
38 'maketoc', true);
39
40 %% Page 1: GDP
41 rep.addPage('title', 'Jan1 vs Jan2', ...
42 'titleFormat', '\large\bfseries');
43 rep.addSection();
44 rep.addVspace();
45
46 % Table 1
47 rep.addTable('title', {'Real GDP Growth','subtitle 1', 'subtitle 2'}, ...
48 'range', larange, ...
49 'vlineAfter', dates('2011y'), ...
50 'highlightRows', {'gray!25','white','green!22'});
51 rep = AnnualTable(rep, db_a, dc_a, 'PCH_GROWTH4_', larange);
52 rep.addVspace('number', 2);
53
54 % Table 2
55 rep.addTable('title', 'Potential GDP Growth', 'range', larange, ...
56 'vlineAfter', dates('2011y'));
57 rep = AnnualTable(rep, db_a, dc_a, 'PCH_GROWTH4_BAR_', larange);
58
59
60 %% Page 2: Headline & Core Inflation
61 rep.addPage('title', 'Jan1 vs Jan2', ...
62 'titleFormat', '\large\bfseries');
63 rep.addSection();
64 rep.addVspace();
65
66 % Table 1
67 rep.addTable('title', 'Headline CPI Inflation', 'range', larange, ...
68 'vlineAfter', dates('2011y'));
69 rep = AnnualTable(rep, db_a, dc_a, 'PCH_PIE4_', larange);
70 rep.addVspace('number', 2);
71
72 % Table 2
73 rep.addTable('title', 'Core CPI Inflation', 'range', larange, ...
74 'vlineAfter', dates('2011y'));
75 rep = AnnualTable(rep, db_a, dc_a, 'PCH_PIEX4_', larange);
76
77
78 %% Page 3: Gas & Food Inflation
79 rep.addPage('title', 'Jan1 vs Jan2', ...
80 'titleFormat', '\large\bfseries');
81 rep.addSection();
82 rep.addVspace();
83
84 % Table 1
85 rep.addTable('title', 'Gas Inflation', 'range', larange, ...
86 'vlineAfter', dates('2011y'));
87 rep = AnnualTable(rep, db_a, dc_a, 'PCH_PIE4_GAS_', larange);
88 rep.addVspace('number', 2);
89
90 % Table 2
91 rep.addTable('title', 'Food Inflation', 'range', larange, ...
92 'vlineAfter', dates('2011y'));
93 rep = AnnualTable(rep, db_a, dc_a, 'PCH_PIE4_CONSFOOD_', larange);
94
95
96 %% Page 4: i & Output Gap
97 rep.addPage('title', 'Jan1 vs Jan2', ...
98 'titleFormat', '\large\bfseries');
99 rep.addSection();
100 rep.addVspace();
101
102 % Table 1
103 rep.addTable('title', 'Nominal Interest Rate', 'range', larange, ...
104 'vlineAfter', dates('2011y'));
105 rep = AnnualTable(rep, db_a, dc_a, 'RS_', larange);
106 rep.addVspace('number', 2);
107
108 % Table 2
109 rep.addTable('title', 'Output Gap', 'range', larange, ...
110 'vlineAfter', dates('2011y'), 'tableDirName', 'page4table2');
111 db_a.tex_rename_('Y_WORLD', 'World');
112 rep.addSeries('data', db_a{'Y_WORLD'});
113 delta = db_a{'Y_WORLD'}-dc_a{'Y_WORLD'};
114 delta.tex_rename_('$\Delta$');
115 rep.addSeries('data', delta, ...
116 'tableShowMarkers', true, ...
117 'tableAlignRight', true);
118 rep = AnnualTable(rep, db_a, dc_a, 'Y_', larange);
119
120 %% Country Pages
121 for i=1:length(shortNames)
122 rep.addPage('title', {'Jan1 vs Jan2', longNames{i}}, ...
123 'titleFormat', {'\large\bfseries', '\large'});
124 rep.addSection('cols', 5);
125 rep = CountryGraphPage(rep, shortNames{i}, db_q, dc_q, prange, srange);
126
127 rep.addPage('title', 'Jan1 vs Jan2', ...
128 'titleFormat', '\large\bfseries');
129 rep.addSection();
130 rep = CountryTablePage(rep, shortNames{i}, longNames{i}, db_q, dc_q, ...
131 db_a, dc_a, trange, dates('2012q2'));
132 end
133
134 %% Residual Reports
135 % Countries
136 for i=1:length(shortNames)
137 rep.addPage('title', 'Residual Report Jan1 vs Jan2', ...
138 'titleFormat', '\large\bfseries');
139 rep.addSection();
140 rep = ResidTablePage(rep, shortNames{i}, longNames{i}, db_q, dc_q, trange, dates('2012q2'));
141 end
142
143 % Commodities
144 rep.addPage('title', 'Residual Report Jan1 vs Jan2', ...
145 'titleFormat', '\large\bfseries');
146 rep.addSection();
147 rep = CommResidTablePage(rep, db_q, dc_q, trange, dates('2012q2'));
148
149 %% Commodities Graphs
150 %Page 24
151 rep.addPage('title', 'Jan1 vs Jan2', ...
152 'titleFormat', '\large\bfseries', ...
153 'removeHeaderAndFooter', true);
154 rep.addSection('height', '0.475\textheight');
155
156 rep.addGraph('title', {'World Real Oil Price Index','SUBTITLE'}, ...
157 'xrange', prange, ...
158 'shade', srange, ...
159 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
160 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
161 'xTickLabelRotation', 0);
162 rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ...
163 'graphBar', true, ...
164 'graphBarColor', 'red', ...
165 'graphBarFillColor', 'gray', ...
166 'graphBarWidth', 1);
167 db_q.tex_rename_('LRPOIL_WORLD', 'Oil Price');
168 rep.addSeries('data', db_q{'LRPOIL_WORLD'}, ...
169 'graphLineColor', 'blue', ...
170 'graphLineWidth', 1.5, ...
171 'graphMarker', 'triangle*', ...
172 'graphMarkerEdgeColor','black', ...
173 'graphMarkerSize',4);
174 db_q.tex_rename_('LRPOIL_BAR_WORLD', 'Equilibrium Oil Price');
175 rep.addSeries('data', db_q{'LRPOIL_BAR_WORLD'}, ...
176 'graphLineColor', 'green', ...
177 'graphLineStyle', 'solid', ...
178 'graphLineWidth', 1.5);
179
180 rep.addGraph('title', 'World Real Food Price Index', ...
181 'xrange', prange, ...
182 'shade', srange, ...
183 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
184 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
185 'xTickLabelRotation', 0, ...
186 'showLegend', true, ...
187 'legendAt', [.5,.5]);
188 rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ...
189 'graphBar', true, ...
190 'graphBarColor', 'green', ...
191 'graphBarFillColor', 'yellow', ...
192 'graphBarWidth', 1);
193 db_q.tex_rename_('LRPFOOD_WORLD', 'Food Price');
194 rep.addSeries('data', db_q{'LRPFOOD_WORLD'}, ...
195 'graphLineColor', 'blue', ...
196 'graphLineWidth', 1.5);
197 db_q.tex_rename_('LRPFOOD_BAR_WORLD', 'Equilibrium Food Price');
198 rep.addSeries('graphVline', dates('2009q2'), ...
199 'graphLineColor', 'red', ...
200 'graphLineWidth', 1.5);
201
202 % Page 25
203 rep.addPage('title', {'Jan1 vs Jan2', 'World Oil and Food Prices'}, ...
204 'titleFormat', {'\large\bfseries', '\large'}, ...
205 'setPageNumber', 90);
206 rep.addSection('cols', 1);
207 rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', ...
208 'cols', 2, ...
209 'heading', '\textbf{My First Paragraph Has Two Columns}');
210
211 rep.addSection('cols', 1);
212 rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\newline', ...
213 'heading', '\textbf{My Next Paragraphs Only Have One}', ...
214 'indent', false);
215 rep.addParagraph('text', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\newline');
216
217 rep.addSection('cols', 2);
218
219 rep.addGraph('title', 'World Real Oil Price', ...
220 'xrange', prange, ...
221 'shade', srange, ...
222 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
223 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
224 'xTickLabelRotation', 0);
225 rep.addSeries('data', db_q{'LRPOIL_WORLD'}, ...
226 'graphLineColor', 'blue', ...
227 'graphLineWidth', 1.5);
228 rep.addSeries('data', dc_q{'LRPOIL_WORLD'}, ...
229 'graphLineColor', 'blue', ...
230 'graphLineStyle', 'dashed', ...
231 'graphLineWidth', 1.5);
232
233 srange1 = prange(1):forecast_date;
234 rep.addGraph('title', 'Equilibrium World Real Oil Price', ...
235 'xrange', prange, ...
236 'shade', srange1);
237 rep.addSeries('data', db_q{'LRPOIL_BAR_WORLD'}, ...
238 'graphLineColor', 'blue', ...
239 'graphLineWidth', 1.5);
240 rep.addSeries('data', dc_q{'LRPOIL_BAR_WORLD'}, ...
241 'graphLineColor', 'blue', ...
242 'graphLineStyle', 'dashed', ...
243 'graphLineWidth', 1.5);
244
245 rep.addGraph('title', 'World Real Food Price', ...
246 'xrange', prange, ...
247 'shade', srange, ...
248 'xTickLabels','ALL',...
249 'xTickLabelRotation', 45,...
250 'xAxisTight',false,...
251 'yAxisTight',true);
252 rep.addSeries('data', db_q{'LRPFOOD_WORLD'}, ...
253 'graphLineColor', 'blue', ...
254 'graphLineWidth', 1.5);
255 rep.addSeries('data', dc_q{'LRPFOOD_WORLD'}, ...
256 'graphLineColor', 'blue', ...
257 'graphLineStyle', 'dashed', ...
258 'graphLineWidth', 1.5);
259 rep.addSeries('graphHline', 460, ...
260 'graphLineColor', 'red', ...
261 'graphLineWidth', 1.5);
262
263 a=dseries([1:200]', '1984q1');
264 b=dseries([1:200]', '1984q1');
265 c=dseries([1:200]', '1984q1');
266 d=dseries([1:200]', '1984q1');
267 b(dates('2012q2'):dates('2015q2'))=b(dates('2012q2'):dates('2015q2'))+2;
268 c(dates('2012q2'):dates('2015q2'))=c(dates('2012q2'):dates('2015q2'))+4;
269 d(dates('2012q2'):dates('2015q2'))=d(dates('2012q2'):dates('2015q2'))+6;
270
271 rep.addGraph('title', 'Equilibrium World Real Food Price', ...
272 'xrange', prange, ...
273 'shade', srange, ...
274 'showLegend', true, ...
275 'xTickLabelRotation', 0);
276 rep.addSeries('data', a, ...
277 'graphLineColor', 'blue', ...
278 'graphLineWidth', 1.5, ...
279 'graphLegendName', 'baseline', ...
280 'graphMiscTikzAddPlotOptions', 'mark=halfcircle*,color=red');
281 rep.addSeries('data', b, ...
282 'graphLineColor', 'blue', ...
283 'graphLineStyle', 'dashed', ...
284 'graphLineWidth', 1.5, ...
285 'graphLegendName', 'control', ...
286 'graphMiscTikzAddPlotOptions', 'mark=halfcircle*,mark options={rotate=90,scale=3}', ...
287 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 40);
288 rep.addSeries('data', c, ...
289 'graphLineColor', 'blue', ...
290 'graphLineStyle', 'dashed', ...
291 'graphLineWidth', 1.5, ...
292 'graphLegendName', 'control', ...
293 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 30);
294 rep.addSeries('data', d, ...
295 'graphLineColor', 'blue', ...
296 'graphLineStyle', 'dashed', ...
297 'graphLineWidth', 1.5, ...
298 'graphLegendName', 'control', ...
299 'graphFanShadeColor', 'red', 'graphFanShadeOpacity', 20);
300
301 %% Page 26
302 rep.addPage('title', {'report\_data test'}, ...
303 'titleFormat', {'\large\bfseries', '\large'});
304 rep.addSection('cols', 1);
305 rep.addTable('title', {'Table Data 0', 'subtitle 2'});
306 rep.addData('data', [repmat({'a'},10,1) num2cell(rand(10,6))]);
307 rep.addVspace();
308 rep.addSection('cols', 1);
309 rep.addTable('title', {'Table Data 1', 'subtitle 3'});
310 rep.addData('data', [repmat({'a'},10,1) repmat({'b'},10,1) num2cell(rand(10,1))], 'column_names', {'Name', '', 'Var2'});
311
312 %% Write & Compile Report
313 rep.write();
314 rep.compile();
315 toc
316 end