Debian Codegraph @

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

raw
1 function Estrexa = fidcndexa(yexa,phil,A0_h,Bh_h,nvar,lags)
2 % Estrexa = fidcndexa(yexa,phil,A0_h,Bh_h,nvar,lags)
3 % Exact structural shocks e(t) (backed out by conditioning on the path "yexa")
4 %
5 % yexa: actup-by-nvar. Actual data (all log except R, U, etc.) begin
6 % at nSample-actup+1 and ends at nSample, where nSample is the period
7 % for actual data (excluding dummy observations)
8 % phil: the 1-by-(nvar*lags+1) data matrix where k=nvar*lags+1
9 % (last period plus lags, prior to nSample-actup+1)
10 % A0_h: A0, column-equation; in the form of y(t)A0=X(t)A+ + e(t)
11 % Bh_h: reduced-form parameter matrix: k-by-nvar, y(t) = X(t)*Bh+u(t)
12 % where X(t) is k-by-nvar and y(t) is 1-by-nvar
13 % nvar: number of variables in the BVAR model
14 % lags: number of lags in the BVAR model
15 % ------
16 % Estrexa: actup-by-nvar -- backed out exact shocks given parameter values
17 % where actup = length(yexa(:,1)).
18 %
19 %% See Zha's note "Forecast (2)" p.11
20 %
21 %% Some notations: y(t+1) = y(t)B1 + e(t+1)inv(A0). e(t+1) is 1-by-n.
22 %% Let r(t+1)=e(t+1)inv(A0) + e(t+2)C + .... where inv(A0) is impulse
23 %% response at t=1, C at t=2, etc. The row of inv(A0) or C is
24 %% all responses to one shock.
25 %% Let r be q-by-1 (such as r(1) = r(t+1)
26 %% = y(t+1) (constrained) - y(t+1) (forecast)).
27 %% Use impulse responses to find out R (k-by-q) where k=nvar*nsteps
28 %% where nsteps the largest constrained step. The key of the program
29 %% is to creat R using impulse responses
30 %% Optimal solution for shock e where R'*e=r and e is k-by-1 is
31 %% e = R*inv(R'*R)*r.
32 %
33 % Written by Tao Zha April 1998
34 % Change the input arguments so that old programs may not be compatible, 03/19/98.
35 %
36 % Copyright (C) 1997-2012 Tao Zha
37 %
38 % This free software: you can redistribute it and/or modify
39 % it under the terms of the GNU General Public License as published by
40 % the Free Software Foundation, either version 3 of the License, or
41 % (at your option) any later version.
42 %
43 % It is distributed in the hope that it will be useful,
44 % but WITHOUT ANY WARRANTY; without even the implied warranty of
45 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 % GNU General Public License for more details.
47 %
48 % If you did not received a copy of the GNU General Public License
49 % with this software, see <http://www.gnu.org/licenses/>.
50 %
51
52 tcwc = nvar*lags; % total coefficients without constant
53 actup = length(yexa(:,1)); % periods considered for structural shocks.
54 phis=phil; % for exact backed out shocks
55
56 Estrsexa=zeros(actup,nvar); % backed out exact shocks
57
58 for k=1:actup
59 Estrexa(k,:) = (yexa(k,:)-phis*Bh_h) * A0_h;
60 phis(nvar+1:tcwc) = phis(1:tcwc-nvar);
61 phis(1:nvar) = yexa(k,:);
62 end