Debian Codegraph @

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

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