2019-09-10 17:02:20 +02:00
|
|
|
function y = irf(M_, options_, dr, e1, long, drop, replic, iorder)
|
|
|
|
% function y = irf(M_, options_, dr, e1, long, drop, replic, iorder)
|
2008-01-21 12:18:56 +01:00
|
|
|
% Computes impulse response functions
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-01-21 12:18:56 +01:00
|
|
|
% INPUTS
|
2019-09-10 17:02:20 +02:00
|
|
|
% M_: structure representing the model
|
|
|
|
% options_: structure representing options for commands
|
|
|
|
% 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
|
2008-01-21 12:18:56 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% y: impulse response matrix
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-01-21 12:18:56 +01:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
2008-08-01 14:40:33 +02:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2003-2019 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-01-21 12:18:56 +01:00
|
|
|
|
2010-10-13 18:52:07 +02:00
|
|
|
if M_.maximum_lag >= 1
|
|
|
|
temps = repmat(dr.ys,1,M_.maximum_lag);
|
|
|
|
else
|
|
|
|
temps = zeros(M_.endo_nbr, 1); % Dummy values for purely forward models
|
|
|
|
end
|
2010-01-05 11:46:10 +01:00
|
|
|
y = 0;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2017-05-27 19:26:12 +02:00
|
|
|
local_order = iorder;
|
2019-12-13 18:20:10 +01:00
|
|
|
if local_order~=1 && M_.hessian_eq_zero
|
2017-05-27 19:26:12 +02:00
|
|
|
local_order = 1;
|
|
|
|
end
|
|
|
|
|
|
|
|
if local_order == 1
|
2006-04-29 11:43:21 +02:00
|
|
|
y1 = repmat(dr.ys,1,long);
|
|
|
|
ex2 = zeros(long,M_.exo_nbr);
|
|
|
|
ex2(1,:) = e1';
|
2019-09-10 17:02:20 +02:00
|
|
|
y2 = simult_(M_,options_,temps,dr,ex2,local_order);
|
2006-04-29 11:43:21 +02:00
|
|
|
y = y2(:,M_.maximum_lag+1:end)-y1;
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
2005-02-18 20:54:39 +01:00
|
|
|
% eliminate shocks with 0 variance
|
2005-10-01 11:17:40 +02:00
|
|
|
i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0 ));
|
2005-02-18 20:54:39 +01:00
|
|
|
nxs = length(i_exo_var);
|
2006-04-29 22:15:58 +02:00
|
|
|
ex1 = zeros(long+drop,M_.exo_nbr);
|
2005-02-18 20:54:39 +01:00
|
|
|
chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var));
|
|
|
|
for j = 1: replic
|
2009-12-16 18:17:34 +01:00
|
|
|
ex1(:,i_exo_var) = randn(long+drop,nxs)*chol_S;
|
|
|
|
ex2 = ex1;
|
2017-05-16 15:10:20 +02:00
|
|
|
ex2(drop+1,:) = ex2(drop+1,:)+e1';
|
2019-09-10 17:02:20 +02:00
|
|
|
y1 = simult_(M_,options_,temps,dr,ex1,local_order);
|
|
|
|
y2 = simult_(M_,options_,temps,dr,ex2,local_order);
|
2009-12-16 18:17:34 +01:00
|
|
|
y = y+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2006-04-29 11:43:21 +02:00
|
|
|
y=y/replic;
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|