www.gusucode.com > econ 案例源码程序 matlab代码 > econ/GenerateVECModelImpulseResponsesExample.m

    %% Generate VEC Model Impulse Responses 
% This example shows how to generate impulse responses from this VEC(3) model
% (<docid:econ_ug.brz_lcd>, Ch. 6.7):
%
% $$\begin{array}{*{20}{rcl}} \Delta {y_t} &=& \left[ {\begin{array}{*{20}{c}}
% {0.24}&{ - 0.08}\\
% 0&{ - 0.31}
% \end{array}} \right]\Delta {y_{t - 1}} + \left[ {\begin{array}{*{20}{c}}
% 0&{ - 0.13}\\
% 0&{ - 0.37}
% \end{array}} \right]\Delta {y_{t - 2}} + \left[ {\begin{array}{*{20}{c}}
% {0.20}&{ - 0.06}\\
% 0&{ - 0.34}
% \end{array}} \right]\Delta {y_{t - 3}}\\ &+& \left[ \begin{array}{*{20}{c}}
% { - 0.07}\\{0.17}\end{array}\right]\left[\begin{array}{*{20}{c}}{1}&{ -4}\end{array}
% \right]{y_{t - 1}} + {\varepsilon _t}\end{array}$$
%
% $y_t$ is a 2 dimensional time series.  $\Delta y_{t} = y_{t} - y_{t-1}$.
% $\varepsilon_t$ is a 2 dimensional series of mean zero, Gaussian
% innovations with covariance matrix
%
% $$\Sigma = 10^{-5}\left[ {\begin{array}{*{20}{rcl}}
% {2.61}&{ - 0.15}\\
% -0.15&{  2.31}
% \end{array}} \right].$$
%
%%
% Specify the VEC(3) model autoregressive coefficient matrices $B_1$,
% $B_2$, and $B_3$, the error-correction coefficient matrix $C$, and the
% innovations covariance matrix $\Sigma$.
B1    = [0.24 -0.08;
         0.00 -0.31];
B2    = [0.00 -0.13;
         0.00 -0.37];
B3    = [0.20 -0.06;
         0.00 -0.34];
C     = [-0.07; 0.17]*[1 -4];
Sigma = [ 2.61 -0.15;
         -0.15  2.31]*1e-5;
%%
% Compute the autoregressive coefficient matrices that compose the VAR(4) model
% that is equivalent to the VEC(3) model.
B = {B1; B2; B3};
A = vec2var(B,C);
%%
% |A| is a 4-by-1 cell vector containing the 2-by-2, VAR(4) model
% autoregressive coefficient matrices.  Cell |A{j}| contains the
% coefficient matrix for lag |j| in difference-equation notation.  The
% VAR(4) is in terms of $y_t$ rather than $\Delta y_t$.
%%
% Compute the forecast error impulse responses (FEIR) for the VAR(4)
% representation.  That is, accept the default identity matrix for the
% innovations covariance.  Specify to return the impulse responses for the
% first 20 periods.
numObs = 20;
IR = cell(2,1); % Preallocation
IR{1} = armairf(A,[],'NumObs',numObs);
%%
% To compute impulse responses, |armairf| filters an innovation
% standard deviation shock from one series to itself and all other series.
% In this case, the magnitude of the shock is 1 for each series.
%%
% Compute orthogonalized impulse responses by supplying the innovations
% covariance matrix.  Specify to return the impulse responses for the
% first 20 periods.
IR{2} = armairf(A,[],'InnovCov',Sigma,'NumObs',numObs);
%%
% For orthogonalized impulse responses, the innovations covariance governs
% the magnitude of the filtered shock.
%%
% Plot the FEIR and the orthogonalized impulse responses for all series.
type = {'FEIR','Orthogonalized'};
for j = 1:2;
    figure;
    imp = IR{j};
    subplot(2,2,1);
    plot(imp(:,1,1))
    title(sprintf('%s: y_{1,t}',type{j}));
    ylabel('y_{1,t}');
    xlabel('Period');
    subplot(2,2,2);
    plot(imp(:,1,2))
    title(sprintf('%s: y_{1,t} \\rightarrow y_{2,t}',type{j}));
    ylabel('y_{2,t}');
    xlabel('Period');
    subplot(2,2,3);
    plot(imp(:,2,1))
    title(sprintf('%s: y_{2,t} \\rightarrow y_{1,t}',type{j}));
    ylabel('y_{1,t}');
    xlabel('Period');
    subplot(2,2,4);
    plot(imp(:,2,2))
    title(sprintf('%s: y_{2,t}',type{j}));
    ylabel('y_{2,t}');
    xlabel('Period');
end
%%
% Because the innovations covariance is almost diagonal, the FEIR and
% orthogonalized impulse responses have similar dynamic behaviors
% (<docid:econ_ug.brz_lcd>, Ch. 6.7). However, the scale of the plots are
% markedly different.