Debian Codegraph @

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

raw
1 function imf = fn_impulse(Bh,swish,nn)
2 % Computing impulse functions with
3 % imf = fn_impulse(Bh,swish,nn)
4 % imf is in a format that is the SAME as in RATS.
5 % Column: nvar responses to 1st shock,
6 % nvar responses to 2nd shock, and so on.
7 % Row: steps of impulse responses.
8 %-----------------
9 % Bh is the estimated reduced form coefficient in the form
10 % Y(T*nvar) = XB + U, X: T*k (may include all exogenous terms), B: k*nvar.
11 % The matrix form and dimension are the same as "Bh" from the function "sye.m";
12 % Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k.
13 % Note: columns correspond to equations.
14 % swish is the inv(A0) in the structural model y'(t)*A0 = e'(t).
15 % Note: columns corresponding to equations.
16 % nn is the numbers of inputs [nvar,lags,# of steps of impulse responses].
17 %
18 % Written by Tao Zha.
19 %
20 %
21 % Copyright (C) 1997-2012 Tao Zha
22 %
23 % This free software: you can redistribute it and/or modify
24 % it under the terms of the GNU General Public License as published by
25 % the Free Software Foundation, either version 3 of the License, or
26 % (at your option) any later version.
27 %
28 % It is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 % GNU General Public License for more details.
32 %
33 % If you did not received a copy of the GNU General Public License
34 % with this software, see <http://www.gnu.org/licenses/>.
35 %
36
37 nvar = nn(1);
38 lags = nn(2);
39 imstep = nn(3); % number of steps for impulse responses
40
41 Ah = Bh';
42 % Row: nvar equations
43 % Column: 1st lag (with nvar variables) to lags (with nvar variables) + const = k.
44
45 imf = zeros(imstep,nvar*nvar);
46 % Column: nvar responses to 1st shock, nvar responses to 2nd shock, and so on.
47 % Row: steps of impulse responses.
48 M = zeros(nvar*(lags+1),nvar);
49 % Stack lags M's in the order of, e.g., [Mlags, ..., M2,M1;M0]
50 M(1:nvar,:) = swish';
51 Mtem = M(1:nvar,:); % temporary M.
52 % first (initial) responses to 1 standard deviation shock. Row: responses; Column: shocks
53 % * put in the form of "imf"
54 imf(1,:) = Mtem(:)';
55
56 t = 1;
57 ims1 = min([imstep-1 lags]);
58 while t <= ims1
59 Mtem = Ah(:,1:nvar*t)*M(1:nvar*t,:);
60 % Row: nvar equations, each for the nvar variables at tth lag
61 M(nvar+1:nvar*(t+1),:)=M(1:nvar*t,:);
62 M(1:nvar,:) = Mtem;
63 imf(t+1,:) = Mtem(:)';
64 % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc.
65 t= t+1;
66 end
67
68 for t = lags+1:imstep-1
69 Mtem = Ah(:,1:nvar*lags)*M(1:nvar*lags,:);
70 % Row: nvar equations, each for the nvar variables at tth lag
71 M(nvar+1:nvar*(t+1),:) = M(1:nvar*t,:);
72 M(1:nvar,:)=Mtem;
73 imf(t+1,:) = Mtem(:)';
74 % stack imf with each step, Row: 6 var to 1st shock, 6 var to 2nd shock, etc.
75 end