File: fore_gh.m

package info (click to toggle)
dynare 4.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,408 kB
  • sloc: cpp: 84,998; ansic: 29,058; pascal: 13,843; sh: 4,833; objc: 4,236; yacc: 3,622; makefile: 2,278; lex: 1,541; python: 236; lisp: 69; xml: 8
file content (256 lines) | stat: -rw-r--r-- 8,775 bytes parent folder | download | duplicates (8)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
function [yactCalyg,yforeCalygml,yAg,yFg,yactqg,yforeqgml,qAg,qFg,...
                      yactmg,yforemgml,mAg,mFg,yact,yactCal] = fore_gh(xinput)
% Plot graphics
%    [yactCalyg,yforeCalygml,yAg,yFg,yactqg,yforeqgml,qAg,qFg,...
%                      yactmg,yforemgml,mAg,mFg,yact,yactCal] = fore_gh(xinput)
%
% xdata=xinput{1}: data, all logged except R, U, etc.
% nvar=xinput{2}: number of variables
% nSample=xinput{3}: sample size (including lags or initial periods)
% nSampleCal=xinput{4}: converting nSample of calendar years;
% yforelml=xinput{5}: monthly ML forecast, all in level, in percent
% yforemgml=xinput{6}: monthly growth -- annualized rate, in percent
% yforeqgml=xinput{7}: prior-quarter growth -- annualized rate, in percent
% yforeCalygml=xinput{8}: annual rate, expressed in percentage point, in percent
% actup=xinput{9}: periods for actual data (monthly)
% actupq=xinput{10}: periods for actual data (quarterly)
% actupy=xinput{11}: periods for actual data (calendar yearly)
% vlist=xinput{12}: list of variables
% vlistlog=xinput{13}: sub list of variables that are in log
% vlistper=xinput{14}: sub list of variables that are in percent
% q_m=xinput{15}: month or quarter in the model
% forep=xinput{16}: forecast periods (monthly)
% ylab=xinput{17}: labels for the y-axis
% forepq=xinput{18}: quarters in the forecast period
% forepy=xinput{19}: calendar years in the forecast period
% Psuedo=xinput{20}: 1: Psuedo out-of-sample; 0: real time out-of-sample
% Graphfore=xinput{21}: 1: graphics in this file; 0: no graphics in the execution.
% yearsCal=xinput{22}:  calendar years matching output "yactCalyg"
% qmEnd=xinput{23}:  last month (or quarter) of the sample
%-------------
% yactCalyg: annual growth for actual data
% yforeCalygml: annaul growth for ML forecasts, expressed in percent
% yAg: length of yactCalyg (actual data)
% yFg: lenght of yforeCalyg (forecasts)
%
% yactqg: prior-quarter annualized growth for actual data
% yforeqgml: prior-quarter annaulized growth for ML forecasts, expressed in percent
% qAg: length of yactqg (actual data)
% qFg: lenght of yforeqg (forecasts)
%
% yactmg: month-to-month annualized growth for actual data
% yforemgml: month-to-month annaulized growth for ML forecasts, expressed in percent
% mAg: length of yactqg (actual data)
% mFg: lenght of yforeqg (forecasts)
%
% yact:  log(y) except R, ect. (monthly).  If Psuedo, yact includes "forep" months.
%             i.e., (actup+forep)-by-nvar
% yactCal:  same as yact but ends at the end of the last calendar year.  If Psuedo,
%     (actup+forep)-by-nvar, which include some actual data in the 1st calendar year.
%
%
% Copyright (C) 1997-2012 Tao Zha
%
% This free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% It is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% If you did not received a copy of the GNU General Public License
% with this software, see <http://www.gnu.org/licenses/>.
%


xdata=xinput{1}; nvar=xinput{2}; nSample=xinput{3}; nSampleCal=xinput{4};
yforelml=xinput{5}; yforemgml=xinput{6}; yforeqgml=xinput{7}; yforeCalygml=xinput{8};
actup=xinput{9}; actupq=xinput{10}; actupy=xinput{11}; vlist=xinput{12};
vlistlog=xinput{13}; vlistper=xinput{14}; q_m=xinput{15}; forep=xinput{16};
ylab=xinput{17}; forepq=xinput{18}; forepy=xinput{19}; Psuedo=xinput{20};
Graphfore=xinput{21}; yearsCal=xinput{22}; qmEnd=xinput{23};

% ========= plot the graphics with actural vs forecast vs Full Bayesian =========
%
%*** actual data
if Psuedo
   yact = xdata(nSample-actup+1:nSample+forep,:);   % actup (not calendar) months + forep
   yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal+forepy*q_m,:);  % calendar years
else
   yact = xdata(nSample-actup+1:nSample,:);    % actup (not calendar) months
   yactCal = xdata(nSampleCal-actupy*q_m+1:nSampleCal,:);   % caledar years
end
%



%%%%---------------------------------------------------------------
%$$$ Actual monthly growth rate, Prior quarter, and year-over-year change
%%%%---------------------------------------------------------------

%
%@@@ Monthly change (annaluized rate)
%
yactm = yact;
mT1 = length(yact(:,1));
%
yactmg = yactm(2:mT1,:);    % start at second month to get growth rate
yactmg(:,vlistlog) = (yactm(2:mT1,vlistlog) - yactm(1:mT1-1,vlistlog)) .* 12;
                             % monthly, 12*log(1+growth rate), annualized growth rate
yactmg(:,vlistlog) = 100*(exp(yactmg(:,vlistlog))-1);
yactmg(:,vlistper) = 100*yactmg(:,vlistper);
mAg = length(yactmg(:,1));


%
%@@@ Prior Quarter change (annaluized rate)
%
if Psuedo
	yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3)+forepq*3,:);
   yactq = zeros(actupq+forepq,length(vlist));
else
	yactQ = xdata(nSample-mod(qmEnd,3)-actupq*3+1:nSample-mod(qmEnd,3),:);
   yactq = zeros(actupq,length(vlist));
end
%
qT1 = length(yactQ(:,1))/3;
qT1a = length(yactq(:,1));
if qT1 ~= qT1a
	warning('line #')
	error('qT1: Beginings or ends of monthly and quarterly series do not match!')
end
%
for i = 1:qT1
   i1 = 1+3*(i-1);
   i2 = 3*i;
   yactq(i,:) = sum(yactQ(i1:i2,:)) ./ 3;
end
%
yactqg = yactq(5:qT1,:);    % 4+1=5 where 4 means 4 quarters
yactqg(:,vlistlog) = (yactq(5:qT1,vlistlog) - yactq(4:qT1-1,vlistlog)) .* 4;
                              % quarterly, 4*log(1+growth rate), annualized growth rate
yactqg(:,vlistlog) = 100*(exp(yactqg(:,vlistlog))-1);
yactqg(:,vlistper) = 100*yactqg(:,vlistper);
qAg = length(yactqg(:,1));


%
%@@@ Calendar year-over-year change
%
if Psuedo
   yactCaly = zeros(actupy+forepy,length(vlist));  % past "actupy" calendar years + forepy
else
   yactCaly = zeros(actupy,length(vlist));  % past "actupy" calendar years
end
yT1 = length(yactCal(:,1))/q_m;
yT1a = length(yactCaly(:,1));
if yT1 ~= yT1a
	error('yT1: Beginings or ends of monthly and quarterly series are not the same!')
end
%
for i = 1:yT1
   i1 = 1+q_m*(i-1);
   i2 = q_m*i;
   yactCaly(i,:) = sum(yactCal(i1:i2,:)) ./ q_m;
end
%
yactCalyg = yactCaly(2:yT1,:);    % 1+1=2 where 1 means 1 year
yactCalyg(:,vlistlog) = (yactCaly(2:yT1,vlistlog) - yactCaly(1:yT1-1,vlistlog));
                          % annual rate: log(1+growth rate)
yactCalyg(:,vlistlog) = 100*(exp(yactCalyg(:,vlistlog))-1);
yactCalyg(:,vlistper) = 100*yactCalyg(:,vlistper);
yAg = length(yactCalyg(:,1));


%----------------------------------------------------------------------
%=================  Graphics of actual vs forecast ===================
%----------------------------------------------------------------------
yactl(:,vlistlog)=exp(yact(:,vlistlog));
yactl(:,vlistper)=100*yact(:,vlistper);  % convert to levels, in percent
%
mFg = length(yforemgml(:,1));
qFg = length(yforeqgml(:,1));
yFg = length(yforeCalygml(:,1));

if Psuedo
   t1=1:actup+forep;
else
   t1=1:actup;
end
t2=actup+1:actup+forep;
%
if Graphfore
	figure           % The graphics below are expressed in level (monthly)
	for i = 1:nvar
	   subplot(nvar/2,2,i)
   	plot(t1,yactl(:,i),t2,yforelml(:,i),'--')
   	%title('solid-actual, dotted-forecast');
   	%title(eval(['forelabel']));
   	%ylabel(eval(['x' int2str(i)]));
		ylabel(char(ylab(i)))
	end
end

t1 = 1:mAg;
if Psuedo
   t2 = mAg-mFg+1:mAg;
else
   t2 = mAg+1:mAg+mFg;
end
%
if Graphfore
	figure   % The graphics below are monthly growth rates except R and U, at annualized rates
	for i = 1:nvar
	   subplot(nvar/2,2,i)
	   plot(t1,yactmg(:,i),t2,yforemgml(:,i),'--')
	   %title('solid-actual, dotted-forecast');
	   %xlabel(eval(['forelabel']));
	   %ylabel(eval(['x' int2str(i)]));
		ylabel(char(ylab(i)))
	end
end

t1 = 1:qAg;
if Psuedo
   t2 = qAg-qFg+1:qAg;
else
   t2 = qAg+1:qAg+qFg;
end
%
if Graphfore
	figure  % The graphics below are prior quarter growth rate except R and U, at annualized rates
	for i = 1:nvar
	   subplot(nvar/2,2,i)
	   plot(t1,yactqg(:,i),t2,yforeqgml(:,i),'--')
	   %title('quarterly growth, unconditional');
	   %xlabel(eval(['forelabel']));
   	%ylabel(eval(['x' int2str(i)]));
		ylabel(char(ylab(i)))
	end
end


%t1 = 1:yAg;
t1 = yearsCal;
yAgCal=yearsCal(length(yearsCal));
if Psuedo
   t2 = yAgCal-yFg+1:yAgCal;
else
   t2 = yAgCal+1:yAgCal+yFg;
end
%
if Graphfore
	figure
	% The graphics below are over-the-year growth rate except R and U, annually
	for i = 1:nvar
	   subplot(nvar/2,2,i)
   	plot(t1,yactCalyg(:,i),t2,yforeCalygml(:,i),'--')
	   %title('solid-actual, dotted-forecast');
	   %xlabel(eval(['forelabel']));
	   %ylabel(eval(['x' int2str(i)]));
		ylabel(char(ylab(i)))
	end
end