Home > matlab > shock_decomposition.m

shock_decomposition

PURPOSE ^

function z = shock_decomposition(M_,oo_,options_,varlist)

SYNOPSIS ^

function oo_ = shock_decomposition(M_,oo_,options_,varlist)

DESCRIPTION ^

 function z = shock_decomposition(M_,oo_,options_,varlist)
 Computes shocks contribution to a simulated trajectory

 INPUTS
    M_:          [structure]  Definition of the model
    oo_:         [structure]  Storage of results
    options_:    [structure]  Options
    varlist:     [char]       List of variables

 OUTPUTS
    oo_:         [structure]  Storage of results

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function oo_ = shock_decomposition(M_,oo_,options_,varlist)
0002 % function z = shock_decomposition(M_,oo_,options_,varlist)
0003 % Computes shocks contribution to a simulated trajectory
0004 %
0005 % INPUTS
0006 %    M_:          [structure]  Definition of the model
0007 %    oo_:         [structure]  Storage of results
0008 %    options_:    [structure]  Options
0009 %    varlist:     [char]       List of variables
0010 %
0011 % OUTPUTS
0012 %    oo_:         [structure]  Storage of results
0013 %
0014 % SPECIAL REQUIREMENTS
0015 %    none
0016 
0017 % Copyright (C) 2009-2011 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 % indices of endogenous variables
0035 if size(varlist,1) == 0
0036     varlist = M_.endo_names(1:M_.orig_endo_nbr,:);
0037 end
0038 
0039 [i_var,nvar] = varlist_indices(varlist,M_.endo_names);
0040 
0041 % number of variables
0042 endo_nbr = M_.endo_nbr;
0043 
0044 % number of shocks
0045 nshocks = M_.exo_nbr;
0046 
0047 % parameter set
0048 parameter_set = options_.parameter_set;
0049 if isempty(parameter_set)
0050     if isfield(oo_,'posterior_mean')
0051         parameter_set = 'posterior_mean';
0052     elseif isfield(oo_,'posterior_mode')
0053         parameter_set = 'posterior_mode';
0054     else
0055         error(['shock_decomposition: option parameter_set is not specified ' ...
0056                'and posterior mode is not available'])
0057     end
0058 end
0059 
0060 oo = evaluate_smoother(parameter_set);
0061 
0062 % reduced form
0063 dr = oo.dr;
0064 
0065 % data reordering
0066 order_var = dr.order_var;
0067 inv_order_var = dr.inv_order_var;
0068 
0069 
0070 % coefficients
0071 A = dr.ghx;
0072 B = dr.ghu;
0073 
0074 % initialization
0075 for i=1:nshocks
0076     epsilon(i,:) = eval(['oo.SmoothedShocks.' M_.exo_names(i,:)]);
0077 end
0078 gend = size(epsilon,2);
0079 
0080 z = zeros(endo_nbr,nshocks+2,gend);
0081 for i=1:endo_nbr
0082     z(i,end,:) = eval(['oo.SmoothedVariables.' M_.endo_names(i,:)]);
0083 end
0084 
0085 maximum_lag = M_.maximum_lag;
0086 lead_lag_incidence = M_.lead_lag_incidence;
0087 
0088 k2 = dr.kstate(find(dr.kstate(:,2) <= maximum_lag+1),[1 2]);
0089 i_state = order_var(k2(:,1))+(min(i,maximum_lag)+1-k2(:,2))*M_.endo_nbr;
0090 for i=1:gend
0091     if i > 1 && i <= maximum_lag+1
0092         lags = min(i-1,maximum_lag):-1:1;
0093     end
0094     
0095     if i > 1
0096         tempx = permute(z(:,1:nshocks,lags),[1 3 2]);
0097         m = min(i-1,maximum_lag);
0098         tempx = [reshape(tempx,endo_nbr*m,nshocks); zeros(endo_nbr*(maximum_lag-i+1),nshocks)];
0099         z(:,1:nshocks,i) = A(inv_order_var,:)*tempx(i_state,:);
0100         lags = lags+1;
0101     end
0102 
0103     z(:,1:nshocks,i) = z(:,1:nshocks,i) + B(inv_order_var,:).*repmat(epsilon(:,i)',endo_nbr,1);
0104     z(:,nshocks+1,i) = z(:,nshocks+2,i) - sum(z(:,1:nshocks,i),2);
0105 end
0106 
0107 
0108 oo_.shock_decomposition = z;
0109 
0110 graph_decomp(z,M_.exo_names,M_.endo_names,i_var,options_.initial_date)

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005