Debian Codegraph @

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

raw
1 function yhat = fsim(Bh,A0h,phi,nn)
2 % yhat = fsim(Bh,A0h,phi,nn)
3 % Unconditional forecasts with simulated shocks (which do not depend on reduced-form or structural shocks).
4 % y_hat(t+h) = c + x_hat(t+h-1)*Bh, X: 1*k; Bh: k*nvar; y_hat: 1*nvar
5 % where Bh: the (posterior) estimate of B;
6 % A0h: has columns correpond to equations
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 % 3/22/99. Revised so that A0h has columns corr. to equations. Previous
13 % may use A0h' (papers before Sims and Zha IER paper). So please double
14 % check.
15 %
16 % See forecasterr.m when A0h_in (instead of A0h) is used.
17 %
18 % Copyright (C) 1997-2012 Tao Zha
19 %
20 % This free software: you can redistribute it and/or modify
21 % it under the terms of the GNU General Public License as published by
22 % the Free Software Foundation, either version 3 of the License, or
23 % (at your option) any later version.
24 %
25 % It is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
29 %
30 % If you did not received a copy of the GNU General Public License
31 % with this software, see <http://www.gnu.org/licenses/>.
32 %
33
34 % ** setup
35 nvar = nn(1);
36 lags = nn(2);
37 forep = nn(3);
38 tcwc = nvar*lags; % total coefficients without constant
39
40 Ures = randn(forep,nvar)/A0h; % Unconditional forecast
41 % Now, forep-by-nvar -- ready for forecasts
42 % Ures: reduced-form residuals. Row--steps; Column--n shocks
43
44 yhat = zeros(forep,nvar);
45 for k=1:forep
46 yhat(k,:) = phi*Bh + Ures(k,:);
47 phi(1,nvar+1:tcwc) = phi(1,1:tcwc-nvar);
48 phi(1,1:nvar) = yhat(k,:);
49 end