Home > matlab > dsge_simulated_theoretical_variance_decomposition.m

dsge_simulated_theoretical_variance_decomposition

PURPOSE ^

This function computes the posterior or prior distribution of the variance

SYNOPSIS ^

function [nvar,vartan,NumberOfDecompFiles] =dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type)

DESCRIPTION ^

 This function computes the posterior or prior distribution of the variance
 decomposition of the observed 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).
   CovarFileNumber   [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,NumberOfDecompFiles] = ...
0002     dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type)
0003 % This function computes the posterior or prior distribution of the variance
0004 % decomposition of the observed 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 %   CovarFileNumber   [integer]  scalar, number of prior or posterior data files (for covariance).
0018 
0019 % Copyright (C) 2007-2009 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 nodecomposition = 0;
0037 
0038 % Get informations about the _posterior_draws files.
0039 if strcmpi(type,'posterior')
0040     DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
0041     posterior = 1;
0042 elseif strcmpi(type,'prior')
0043     DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
0044     CheckPath('prior/moments',M_.dname);
0045     posterior = 0;
0046 else
0047     disp('dsge_simulated_theoretical_variance_decomposition:: Unknown type!')
0048     error()
0049 end
0050 NumberOfDrawsFiles = length(DrawsFiles);
0051 
0052 % Set varlist (vartan)
0053 if ~posterior
0054     if isfield(options_,'varlist')
0055         temp = options_.varlist;
0056     end
0057     options_.varlist = options_.prior_analysis_endo_var_list;
0058 end
0059 [ivar,vartan,options_] = set_stationary_variables_list(options_,M_);
0060 if ~posterior
0061     if exist('temp','var')
0062         options_.varlist = temp;
0063     end
0064 end
0065 nvar = length(ivar);
0066 
0067 % Set the size of the auto-correlation function to zero.
0068 nar = options_.ar;
0069 options_.ar = 0;
0070 
0071 
0072 
0073 nexo = M_.exo_nbr;
0074 
0075 NumberOfDrawsFiles = rows(DrawsFiles);
0076 NumberOfSavedElementsPerSimulation = nvar*(nexo+1);
0077 MaXNumberOfDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
0078 
0079 if SampleSize<=MaXNumberOfDecompLines
0080     Decomposition_array = zeros(SampleSize,nvar*nexo);
0081     NumberOfDecompFiles = 1;
0082 else
0083     Decomposition_array = zeros(MaXNumberOfDecompLines,nvar*nexo);
0084     NumberOfLinesInTheLastDecompFile = mod(SampleSize,MaXNumberOfDecompLines);
0085     NumberOfDecompFiles = ceil(SampleSize/MaXNumberOfDecompLines);
0086 end
0087 
0088 NumberOfDecompLines = rows(Decomposition_array);
0089 DecompFileNumber = 1;
0090 
0091 % Compute total variances (covariances are not saved) and variances
0092 % implied by each structural shock.
0093 linea = 0;
0094 for file = 1:NumberOfDrawsFiles
0095     if posterior
0096         load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
0097     else
0098         load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
0099     end
0100     isdrsaved = columns(pdraws)-1;
0101     NumberOfDraws = rows(pdraws);
0102     for linee = 1:NumberOfDraws
0103         linea = linea+1;
0104         if isdrsaved
0105             dr = pdraws{linee,2};
0106         else
0107             set_parameters(pdraws{linee,1});
0108             [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0109         end
0110         tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition);
0111         for i=1:nvar
0112             for j=1:nexo
0113                 Decomposition_array(linea,(i-1)*nexo+j) = tmp{2}(i,j);
0114             end
0115         end
0116         if linea == NumberOfDecompLines
0117             if posterior
0118                 save([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array');
0119             else
0120                 save([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array');
0121             end
0122             DecompFileNumber = DecompFileNumber + 1;
0123             linea = 0;
0124             test = DecompFileNumber-NumberOfDecompFiles;
0125             if ~test% Prepare the last round...
0126                 Decomposition_array = zeros(NumberOfLinesInTheLastDecompFile,nvar*nexo);
0127                 NumberOfDecompLines = NumberOfLinesInTheLastDecompFile;
0128                 DecompFileNumber = DecompFileNumber - 1;
0129             elseif test<0;
0130                 Decomposition_array = zeros(MaXNumberOfDecompLines,nvar*nexo);
0131             else
0132                 clear('Decomposition_array');
0133             end
0134         end
0135     end
0136 end
0137 
0138 options_.ar = nar;

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