Home > matlab > dsge_simulated_theoretical_covariance.m

dsge_simulated_theoretical_covariance

PURPOSE ^

This function computes the posterior or prior distribution of the endogenous

SYNOPSIS ^

function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type)

DESCRIPTION ^

 This function computes the posterior or prior distribution of the endogenous
 variables second order moments.

 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,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type)
0002 % This function computes the posterior or prior distribution of the endogenous
0003 % variables second order moments.
0004 %
0005 % INPUTS
0006 %   SampleSize   [integer]       scalar, number of simulations.
0007 %   M_           [structure]     Dynare structure describing the model.
0008 %   options_     [structure]     Dynare structure defining global options.
0009 %   oo_          [structure]     Dynare structure where the results are saved.
0010 %   type         [string]        'prior' or 'posterior'
0011 %
0012 %
0013 % OUTPUTS
0014 %   nvar              [integer]  nvar is the number of stationary variables.
0015 %   vartan            [char]     array of characters (with nvar rows).
0016 %   CovarFileNumber   [integer]  scalar, number of prior or posterior data files (for covariance).
0017 
0018 % Copyright (C) 2007-2009 Dynare Team
0019 %
0020 % This file is part of Dynare.
0021 %
0022 % Dynare is free software: you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published by
0024 % the Free Software Foundation, either version 3 of the License, or
0025 % (at your option) any later version.
0026 %
0027 % Dynare is distributed in the hope that it will be useful,
0028 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0030 % GNU General Public License for more details.
0031 %
0032 % You should have received a copy of the GNU General Public License
0033 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0034 
0035 nodecomposition = 1;
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_covariance:: Unknown type!')
0047     error();
0048 end
0049 NumberOfDrawsFiles = length(DrawsFiles);
0050 
0051 % Set varlist (vartan)
0052 if ~posterior
0053     if isfield(options_,'varlist')
0054         temp = options_.varlist;
0055     end
0056     options_.varlist = options_.prior_analysis_endo_var_list;
0057 end
0058 [ivar,vartan] = set_stationary_variables_list(options_,M_);
0059 if ~posterior
0060     if exist('temp','var')
0061         options_.varlist = temp;
0062     end
0063 end
0064 nvar = length(ivar);
0065 
0066 % Set the size of the auto-correlation function to zero.
0067 nar = options_.ar;
0068 options_.ar = 0;
0069 
0070 % Number of lines in posterior data files.
0071 MaXNumberOfCovarLines = ceil(options_.MaxNumberOfBytes/(nvar*(nvar+1)/2)/8);
0072 
0073 if SampleSize<=MaXNumberOfCovarLines
0074     Covariance_matrix = zeros(SampleSize,nvar*(nvar+1)/2);
0075     NumberOfCovarFiles = 1;
0076 else
0077     Covariance_matrix = zeros(MaXNumberOfCovarLines,nvar*(nvar+1)/2);
0078     NumberOfLinesInTheLastCovarFile = mod(SampleSize,MaXNumberOfCovarLines);
0079     NumberOfCovarFiles = ceil(SampleSize/MaXNumberOfCovarLines);
0080 end
0081 
0082 NumberOfCovarLines = rows(Covariance_matrix);
0083 CovarFileNumber = 1;
0084 
0085 % Compute 2nd order moments and save them in *_[Posterior, Prior]2ndOrderMoments* files
0086 linea = 0;
0087 for file = 1:NumberOfDrawsFiles
0088     if posterior
0089         load([M_.dname '/metropolis/' DrawsFiles(file).name ],'pdraws');
0090     else
0091         load([M_.dname '/prior/draws/' DrawsFiles(file).name ],'pdraws');
0092     end
0093     NumberOfDraws = rows(pdraws);
0094     isdrsaved = columns(pdraws)-1;
0095     for linee = 1:NumberOfDraws
0096         linea = linea+1;
0097         if isdrsaved
0098             dr = pdraws{linee,2};
0099         else
0100             set_parameters(pdraws{linee,1});
0101             [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0102         end
0103         tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition);
0104         for i=1:nvar
0105             for j=i:nvar
0106                 Covariance_matrix(linea,symmetric_matrix_index(i,j,nvar)) = tmp{1}(i,j);
0107             end
0108         end
0109         if linea == NumberOfCovarLines
0110             if posterior
0111                 save([ M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
0112             else
0113                 save([ M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
0114             end
0115             CovarFileNumber = CovarFileNumber + 1;
0116             linea = 0;
0117             test = CovarFileNumber-NumberOfCovarFiles;
0118             if ~test% Prepare the last round...
0119                 Covariance_matrix = zeros(NumberOfLinesInTheLastCovarFile,nvar*(nvar+1)/2);
0120                 NumberOfCovarLines = NumberOfLinesInTheLastCovarFile;
0121                 CovarFileNumber = CovarFileNumber - 1;
0122             elseif test<0
0123                 Covariance_matrix = zeros(MaXNumberOfCovarLines,nvar*(nvar+1)/2);
0124             else
0125                 clear('Covariance_matrix');
0126             end
0127         end
0128     end
0129 end
0130 
0131 options_.ar = nar;

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