Debian Codegraph @

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

raw
1 function yhat = forecast(Bh,phi,nn)
2 % yhat = forecast(Bh,phi,nn)
3 %
4 % Forecast: unconditional forecating: yhat = forecast(Bh,phi,nn)
5 % y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar
6 % where Bh: the (posterior) estimate of B;
7 % phi: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1
8 % (last period plus lags before the beginning of forecast);
9 % nn: [nvar,lags,forep], forep: forecast periods;
10 % yhat: forep*nvar.
11 %
12 % Copyright (C) 1997-2012 Tao Zha
13 %
14 % This free software: you can redistribute it and/or modify
15 % it under the terms of the GNU General Public License as published by
16 % the Free Software Foundation, either version 3 of the License, or
17 % (at your option) any later version.
18 %
19 % It is distributed in the hope that it will be useful,
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 % GNU General Public License for more details.
23 %
24 % If you did not received a copy of the GNU General Public License
25 % with this software, see <http://www.gnu.org/licenses/>.
26 %
27
28 % ** setup
29 nvar = nn(1);
30 lags = nn(2);
31 forep = nn(3);
32 tcwc = nvar*lags; % total coefficients without constant
33
34 % ** reconstruct x(t) for y(t+h) = x(t+h-1)*B
35 % ** where phi = x(t+h-1) with last column being constant
36 yhat = zeros(forep,nvar);
37 for k=1:forep
38 yhat(k,:) = phi*Bh;
39 phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar);
40 phi(1,1:nvar) = yhat(k,:);
41 end