Home > matlab > conditional_variance_decomposition.m

conditional_variance_decomposition

PURPOSE ^

This function computes the conditional variance decomposition of a given state space model

SYNOPSIS ^

function ConditionalVarianceDecomposition = conditional_variance_decomposition(StateSpaceModel, Steps, SubsetOfVariables,sigma_e_is_diagonal)

DESCRIPTION ^

 This function computes the conditional variance decomposition of a given state space model
 for a subset of endogenous variables.
 
 INPUTS 
   StateSpaceModel     [structure]   Specification of the state space model.
   Steps               [integer]     1*h vector of dates.
   SubsetOfVariables   [integer]     1*q vector of indices.
    
 OUTPUTS 
   ConditionalVarianceDecomposition  [double] [n h p] array, where 
                                                    n is equal to length(SubsetOfVariables)
                                                    h is the number of Steps
                                                    p is the number of state innovations and
 SPECIAL REQUIREMENTS

 [1] In this version, absence of measurement errors is assumed...

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ConditionalVarianceDecomposition = conditional_variance_decomposition(StateSpaceModel, Steps, SubsetOfVariables,sigma_e_is_diagonal)
0002 % This function computes the conditional variance decomposition of a given state space model
0003 % for a subset of endogenous variables.
0004 %
0005 % INPUTS
0006 %   StateSpaceModel     [structure]   Specification of the state space model.
0007 %   Steps               [integer]     1*h vector of dates.
0008 %   SubsetOfVariables   [integer]     1*q vector of indices.
0009 %
0010 % OUTPUTS
0011 %   ConditionalVarianceDecomposition  [double] [n h p] array, where
0012 %                                                    n is equal to length(SubsetOfVariables)
0013 %                                                    h is the number of Steps
0014 %                                                    p is the number of state innovations and
0015 % SPECIAL REQUIREMENTS
0016 %
0017 % [1] In this version, absence of measurement errors is assumed...
0018 
0019 % Copyright (C) 2010 Dynare Team
0020 %
0021 % This file is part of Dynare.
0022 %
0023 % Dynare is free software: you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation, either version 3 of the License, or
0026 % (at your option) any later version.
0027 %
0028 % Dynare is distributed in the hope that it will be useful,
0029 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031 % GNU General Public License for more details.
0032 %
0033 % You should have received a copy of the GNU General Public License
0034 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0035 
0036 if any(Steps <= 0)
0037     error(['Conditional variance decomposition: All periods must be strictly ' ...
0038            'positive'])
0039 end
0040 
0041 number_of_state_innovations = ...
0042     StateSpaceModel.number_of_state_innovations;
0043 transition_matrix = StateSpaceModel.transition_matrix;
0044 number_of_state_equations = ...
0045     StateSpaceModel.number_of_state_equations;
0046 order_var = StateSpaceModel.order_var;
0047 nSteps = length(Steps);
0048 
0049 ConditionalVariance = zeros(number_of_state_equations,nSteps,number_of_state_innovations);
0050 
0051 if StateSpaceModel.sigma_e_is_diagonal
0052     B = StateSpaceModel.impulse_matrix.* ...
0053         repmat(sqrt(diag(StateSpaceModel.state_innovations_covariance_matrix)'),...
0054                number_of_state_equations,1);
0055 else
0056     B = StateSpaceModel.impulse_matrix*chol(StateSpaceModel.state_innovations_covariance_matrix)';
0057 end
0058 
0059 for i=1:number_of_state_innovations
0060     BB = B(:,i)*B(:,i)';
0061     V = zeros(number_of_state_equations,number_of_state_equations);
0062     m = 1;
0063     for h = 1:max(Steps)
0064         V = transition_matrix*V*transition_matrix'+BB;
0065         if h == Steps(m)
0066             ConditionalVariance(order_var,m,i) = diag(V);
0067             m = m+1;
0068         end
0069     end
0070 end
0071 
0072 ConditionalVariance = ConditionalVariance(SubsetOfVariables,:,:);
0073 
0074 NumberOfVariables = length(SubsetOfVariables);
0075 SumOfVariances = zeros(NumberOfVariables,nSteps);
0076 for h = 1:length(Steps)
0077     SumOfVariances(:,h) = sum(ConditionalVariance(:,h,:),3);
0078 end
0079 
0080 ConditionalVarianceDecomposition = zeros(NumberOfVariables,length(Steps),number_of_state_innovations); 
0081 for i=1:number_of_state_innovations
0082     for h = 1:length(Steps)
0083         ConditionalVarianceDecomposition(:,h,i) = squeeze(ConditionalVariance(:,h,i))./SumOfVariances(:,h);
0084     end
0085 end

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