Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/fn_forecastfixe.m

raw
1 function yhat = fn_forecastfixe(Bh,A0h,phi,nn,Estr,nexo,Xfexo)
2 % yhat = fn_forecastfixe(Bh,A0h,phi,nn,Estr,nexo,Xfexo)
3 % Forecasts conditional on fixed structural shocks
4 % y_hat(t+h) = c + x_hat(t+h-1)*Bh + Estr(t+h,:), X: 1*k; Bh: k*nvar; y_hat: 1*nvar
5 %
6 % Bh: k-by-nvar, the (posterior) estimate of B;
7 % A0h: nvar-by-nvar, columns correponding to equations
8 % phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1
9 % (last period plus lags before the beginning of forecast).
10 % nn: [nvar,lags,nfqm], nfqm: forecast periods (months or quarters).
11 % Estr: nfqm-by-nvar, each column corresponds to strcutural shocks from a particular
12 % source such as MS;
13 % nexo: number of exogenous variables. The constant term is the default setting.
14 % Besides this term, we have nexo-1 exogenous variables.
15 % Xfexo: nfqm-by-nexo-1 vector of exoenous variables in the forecast horizon where
16 % nfqm: number of forecast periods.
17 %-----------------
18 % yhat: nfqm*nvar matrix of forecasts.
19 %
20 % See also fn_forecast.m and fn_forecastsim.m.
21 %
22 % Copyright (C) 1997-2012 Tao Zha
23 %
24 % This free software: you can redistribute it and/or modify
25 % it under the terms of the GNU General Public License as published by
26 % the Free Software Foundation, either version 3 of the License, or
27 % (at your option) any later version.
28 %
29 % It is distributed in the hope that it will be useful,
30 % but WITHOUT ANY WARRANTY; without even the implied warranty of
31 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 % GNU General Public License for more details.
33 %
34 % If you did not received a copy of the GNU General Public License
35 % with this software, see <http://www.gnu.org/licenses/>.
36 %
37
38
39 if nargin == 5
40 nexo=1; % default for constant term
41 elseif nexo<1
42 error('We need at least one exogenous term so nexo must >= 1')
43 end
44
45 % ** setup
46 nvar = nn(1);
47 lags = nn(2);
48 nfqm = nn(3);
49 tcwx = nvar*lags; % total coefficeint without exogenous variables
50
51 if nexo>1
52 if (nfqm > size(Xfexo,1))
53 disp(' ')
54 warning('Make sure the forecast horizon in the exogenous variable matrix Xfexo > forecast periods')
55 disp('Press ctrl-c to abort')
56 pause
57 elseif ((nexo-1) ~= size(Xfexo,2))
58 disp(' ')
59 warning('Make sure that nexo matchs the exogenous variable matrix Xfexo')
60 disp('Press ctrl-c to abort')
61 pause
62 end
63 end
64
65 % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B
66 % ** where phi = x(t+h-1) with last column being constant
67 Ures = Estr/A0h;
68 yhat = zeros(nfqm,nvar);
69 for k=1:nfqm
70 yhat(k,:) = phi*Bh + Ures(k,:);
71 %*** lagged endogenous variables
72 phi(1,nvar+1:tcwx) = phi(1,1:tcwx-nvar);
73 phi(1,1:nvar) = yhat(k,:);
74 %*** exogenous variables excluding constant terms
75 if (nexo>1)
76 phi(1,tcwx+1:tcwx+nexo-1) = Xfexo(k,:);
77 end
78 end