Debian Codegraph @

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

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