| 1 |
function irfs = fn_irf_var1(G1, impact, nsteps); |
| 2 |
%irfs = fn_irf_var1(G1, impact,nsteps); |
| 3 |
% Inputs: |
| 4 |
% G1: n-by-n; |
| 5 |
% impact: n-by-r; |
| 6 |
% nsteps: number of steps for impulse responses. |
| 7 |
%--- |
| 8 |
% Outputs: |
| 9 |
% irfs: nsteps-by-n-by-r. For each shock of r shocks, impulse responses are nsteps-by-n. |
| 10 |
% |
| 11 |
% See fn_vds.m and fn_uncondfcst_var1.m. |
| 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 |
|
| 30 |
[n,r] = size(impact); |
| 31 |
|
| 32 |
[n1,n2] = size(G1); |
| 33 |
if (n1 ~= n2) || (n1 ~= n) |
| 34 |
error('fn_irf_var1.m: make sure that (1) G1 is square and (2) size(G1,1) = size(impact,1)'); |
| 35 |
end |
| 36 |
|
| 37 |
irfs = zeros(nsteps,n,r); |
| 38 |
|
| 39 |
|
| 40 |
%---- Impuse responses at the first step. |
| 41 |
M = impact; |
| 42 |
for ri=1:r |
| 43 |
irfs(1,:,ri) = M(:,ri)'; |
| 44 |
end |
| 45 |
|
| 46 |
for ti = 2:nsteps |
| 47 |
M = G1*M; |
| 48 |
for ri=1:r |
| 49 |
irfs(ti,:,ri) = M(:,ri)'; |
| 50 |
end |
| 51 |
end |