Home > matlab > irf.m

irf

PURPOSE ^

function y = irf(dr, e1, long, drop, replic, iorder)

SYNOPSIS ^

function y = irf(dr, e1, long, drop, replic, iorder)

DESCRIPTION ^

 function y = irf(dr, e1, long, drop, replic, iorder)
 Computes impulse response functions
 
 INPUTS
    dr:     structure of decisions rules for stochastic simulations
    e1:     exogenous variables value in time 1 after one shock
    long:   number of periods of simulation
    drop:   truncation (in order 2)
    replic: number of replications (in order 2)
    iorder: first or second order approximation

 OUTPUTS
    y:      impulse response matrix
        
 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y = irf(dr, e1, long, drop, replic, iorder)
0002 
0003 % function y = irf(dr, e1, long, drop, replic, iorder)
0004 % Computes impulse response functions
0005 %
0006 % INPUTS
0007 %    dr:     structure of decisions rules for stochastic simulations
0008 %    e1:     exogenous variables value in time 1 after one shock
0009 %    long:   number of periods of simulation
0010 %    drop:   truncation (in order 2)
0011 %    replic: number of replications (in order 2)
0012 %    iorder: first or second order approximation
0013 %
0014 % OUTPUTS
0015 %    y:      impulse response matrix
0016 %
0017 % SPECIAL REQUIREMENTS
0018 %    none
0019 
0020 % Copyright (C) 2003-2010 Dynare Team
0021 %
0022 % This file is part of Dynare.
0023 %
0024 % Dynare is free software: you can redistribute it and/or modify
0025 % it under the terms of the GNU General Public License as published by
0026 % the Free Software Foundation, either version 3 of the License, or
0027 % (at your option) any later version.
0028 %
0029 % Dynare is distributed in the hope that it will be useful,
0030 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0031 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0032 % GNU General Public License for more details.
0033 %
0034 % You should have received a copy of the GNU General Public License
0035 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0036 
0037 global M_ oo_ options_
0038 
0039 
0040 if M_.maximum_lag >= 1
0041     temps = repmat(dr.ys,1,M_.maximum_lag);
0042 else
0043     temps = zeros(M_.endo_nbr, 1); % Dummy values for purely forward models
0044 end
0045 y       = 0;
0046 
0047 if iorder == 1
0048     y1 = repmat(dr.ys,1,long);
0049     ex2 = zeros(long,M_.exo_nbr);
0050     ex2(1,:) = e1';
0051     y2 = simult_(temps,dr,ex2,iorder);
0052     y = y2(:,M_.maximum_lag+1:end)-y1;
0053 else
0054     % eliminate shocks with 0 variance
0055     i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0 ));
0056     nxs = length(i_exo_var);
0057     ex1 = zeros(long+drop,M_.exo_nbr);
0058     ex2 = ex1;
0059     chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var));
0060     for j = 1: replic
0061         ex1(:,i_exo_var) = randn(long+drop,nxs)*chol_S;
0062         ex2 = ex1;
0063         ex2(drop+1,:) = ex2(drop+1,:)+e1';   
0064         y1 = simult_(temps,dr,ex1,iorder);
0065         y2 = simult_(temps,dr,ex2,iorder);
0066         y = y+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
0067     end
0068     y=y/replic;
0069 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005