Home > matlab > dsge_simulated_theoretical_conditional_variance_decomposition.m

dsge_simulated_theoretical_conditional_variance_decomposition

PURPOSE ^

This function computes the posterior or prior distribution of the conditional variance

SYNOPSIS ^

function [nvar,vartan,NumberOfConditionalDecompFiles] =dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type)

DESCRIPTION ^

 This function computes the posterior or prior distribution of the conditional variance
 decomposition of the endogenous variables (or a subset of the endogenous variables).

 INPUTS
   SampleSize   [integer]       scalar, number of simulations.
   M_           [structure]     Dynare structure describing the model.
   options_     [structure]     Dynare structure defining global options.
   oo_          [structure]     Dynare structure where the results are saved.
   type         [string]        'prior' or 'posterior'


 OUTPUTS
   nvar                             [integer]  nvar is the number of stationary variables.
   vartan                           [char]     array of characters (with nvar rows).
   NumberOfConditionalDecompFiles   [integer]  scalar, number of prior or posterior data files (for covariance).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
0002     dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type)
0003 % This function computes the posterior or prior distribution of the conditional variance
0004 % decomposition of the endogenous variables (or a subset of the endogenous variables).
0005 %
0006 % INPUTS
0007 %   SampleSize   [integer]       scalar, number of simulations.
0008 %   M_           [structure]     Dynare structure describing the model.
0009 %   options_     [structure]     Dynare structure defining global options.
0010 %   oo_          [structure]     Dynare structure where the results are saved.
0011 %   type         [string]        'prior' or 'posterior'
0012 %
0013 %
0014 % OUTPUTS
0015 %   nvar                             [integer]  nvar is the number of stationary variables.
0016 %   vartan                           [char]     array of characters (with nvar rows).
0017 %   NumberOfConditionalDecompFiles   [integer]  scalar, number of prior or posterior data files (for covariance).
0018 
0019 % Copyright (C) 2009-2011 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 
0037 % Get informations about the _posterior_draws files.
0038 if strcmpi(type,'posterior')
0039     DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
0040     posterior = 1;
0041 elseif strcmpi(type,'prior')
0042     DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
0043     CheckPath('prior/moments',M_.dname);
0044     posterior = 0;
0045 else
0046     disp('dsge_simulated_theoretical_conditional_variance_decomposition:: Unknown type!')
0047     error()
0048 end
0049 
0050 % Set varlist (vartan)
0051 if ~posterior
0052     if isfield(options_,'varlist')
0053         temp = options_.varlist;
0054     end
0055     options_.varlist = options_.prior_analysis_endo_var_list;
0056 end
0057 [ivar,vartan ] = set_stationary_variables_list(options_, M_);
0058 if ~posterior
0059     if exist('temp','var')
0060         options_.varlist = temp;
0061     end
0062 end
0063 nvar = length(ivar);
0064 
0065 % Set the size of the auto-correlation function to zero.
0066 nar = options_.ar;
0067 options_.ar = 0;
0068 
0069 NumberOfDrawsFiles = rows(DrawsFiles);
0070 NumberOfSavedElementsPerSimulation = nvar*M_.exo_nbr*length(Steps);
0071 MaXNumberOfConditionalDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
0072 
0073 if SampleSize<=MaXNumberOfConditionalDecompLines
0074     Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,SampleSize);
0075     NumberOfConditionalDecompFiles = 1;
0076 else
0077     Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,MaXNumberOfConditionalDecompLines);
0078     NumberOfLinesInTheLastConditionalDecompFile = mod(SampleSize,MaXNumberOfConditionalDecompLines);
0079     NumberOfConditionalDecompFiles = ceil(SampleSize/MaXNumberOfConditionalDecompLines);
0080 end
0081 
0082 NumberOfConditionalDecompLines = size(Conditional_decomposition_array,4);
0083 ConditionalDecompFileNumber = 0;
0084 
0085 StateSpaceModel.number_of_state_equations = M_.endo_nbr;
0086 StateSpaceModel.number_of_state_innovations = M_.exo_nbr;
0087 
0088 first_call = 1;
0089 
0090 linea = 0;
0091 for file = 1:NumberOfDrawsFiles
0092     if posterior
0093         load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
0094     else
0095         load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
0096     end
0097     isdrsaved = columns(pdraws)-1;
0098     NumberOfDraws = rows(pdraws);
0099     for linee = 1:NumberOfDraws
0100         linea = linea+1;
0101         if isdrsaved
0102             set_parameters(pdraws{linee,1});% Needed to update the covariance matrix of the state innovations.
0103             dr = pdraws{linee,2};
0104         else
0105             set_parameters(pdraws{linee,1});
0106             [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0107         end
0108         if first_call
0109             endo_nbr = M_.endo_nbr;
0110             nstatic = dr.nstatic;
0111             npred = dr.npred;
0112             iv = (1:endo_nbr)';
0113             ic = [ nstatic+(1:npred) endo_nbr+(1:size(dr.ghx,2)-npred) ]';
0114             StateSpaceModel.number_of_state_equations = M_.endo_nbr;
0115             StateSpaceModel.number_of_state_innovations = M_.exo_nbr;
0116             StateSpaceModel.sigma_e_is_diagonal = M_.sigma_e_is_diagonal;
0117             StateSpaceModel.order_var = dr.order_var;
0118             first_call = 0;
0119             clear('endo_nbr','nstatic','npred','k');
0120         end
0121         [StateSpaceModel.transition_matrix,StateSpaceModel.impulse_matrix] = kalman_transition_matrix(dr,iv,ic,M_.exo_nbr);
0122         StateSpaceModel.state_innovations_covariance_matrix = M_.Sigma_e;
0123         clear('dr');
0124         Conditional_decomposition_array(:,:,:,linea) = conditional_variance_decomposition(StateSpaceModel, Steps, ivar);
0125         if linea == NumberOfConditionalDecompLines
0126             ConditionalDecompFileNumber = ConditionalDecompFileNumber + 1;
0127             linea = 0;
0128             if posterior
0129                 save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
0130                      'Conditional_decomposition_array');
0131             else
0132                 save([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
0133                      'Conditional_decomposition_array');
0134             end
0135             if (ConditionalDecompFileNumber==NumberOfConditionalDecompFiles-1)% Prepare last round.
0136                 Conditional_decomposition_array = zeros(nvar, length(Steps),M_.exo_nbr,NumberOfLinesInTheLastConditionalDecompFile) ;
0137                 NumberOfConditionalDecompLines = NumberOfLinesInTheLastConditionalDecompFile;
0138             elseif ConditionalDecompFileNumber<NumberOfConditionalDecompFiles-1
0139                 Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,MaXNumberOfConditionalDecompLines);
0140             else
0141                 clear('Conditional_decomposition_array');
0142             end
0143         end
0144     end
0145 end
0146 
0147 options_.ar = nar;

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