2008-06-21 10:33:31 +02:00
|
|
|
function [nvar,vartan,CovarFileNumber] = dsge_posterior_theoretical_covariance(SampleSize,M_,options_,oo_)
|
2007-09-22 00:54:23 +02:00
|
|
|
% This function estimates the posterior density of the endogenous
|
|
|
|
% variables second order moments.
|
|
|
|
%
|
|
|
|
% INPUTS
|
2008-06-21 10:33:31 +02:00
|
|
|
% SampleSize [integer]
|
|
|
|
%
|
|
|
|
%
|
|
|
|
%
|
2007-09-22 00:54:23 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% None.
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
2008-05-19 15:22:57 +02:00
|
|
|
% Other matlab routines distributed with Dynare: set_stationary_variables_list.m
|
|
|
|
% CheckPath.m
|
|
|
|
% selec_posterior_draws.m
|
|
|
|
% set_parameters.m
|
|
|
|
% resol.m
|
|
|
|
% th_autocovariances.m
|
|
|
|
% posterior_moments.m
|
|
|
|
%
|
2007-09-22 00:54:23 +02:00
|
|
|
%
|
2008-01-17 16:45:44 +01:00
|
|
|
% part of DYNARE, copyright Dynare Team (2007-2008)
|
2007-09-22 00:54:23 +02:00
|
|
|
% Gnu Public License.
|
2008-01-17 16:45:44 +01:00
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
type = 'posterior';
|
|
|
|
|
2007-10-12 19:02:04 +02:00
|
|
|
% Set varlist (vartan)
|
2007-11-09 11:22:08 +01:00
|
|
|
[ivar,vartan] = set_stationary_variables_list;
|
2008-05-19 15:22:57 +02:00
|
|
|
nvar = length(ivar);
|
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
% Set the size of the auto-correlation function to zero.
|
|
|
|
nar = options_.ar;
|
|
|
|
options_.ar = 0;
|
2007-09-22 00:54:23 +02:00
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
% Get informations about the _posterior_draws files.
|
|
|
|
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
|
|
|
|
NumberOfDrawsFiles = length(DrawsFiles);
|
|
|
|
|
|
|
|
% Number of lines in posterior data files.
|
2007-09-22 00:54:23 +02:00
|
|
|
MaXNumberOfCovarLines = ceil(options_.MaxNumberOfBytes/(nvar*(nvar+1)/2)/8);
|
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
if SampleSize<=MaXNumberOfCovarLines
|
2008-06-24 19:13:36 +02:00
|
|
|
Covariance_matrix = zeros(SampleSize,nvar*(nvar+1)/2);
|
2007-09-22 00:54:23 +02:00
|
|
|
NumberOfCovarFiles = 1;
|
|
|
|
else
|
|
|
|
Covariance_matrix = zeros(MaXNumberOfCovarLines,nvar*(nvar+1)/2);
|
2008-06-21 10:33:31 +02:00
|
|
|
NumberOfLinesInTheLastCovarFile = mod(SampleSize,MaXNumberOfCovarLines);
|
|
|
|
NumberOfCovarFiles = ceil(SampleSize/MaXNumberOfCovarLines);
|
2007-09-22 00:54:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
NumberOfCovarLines = rows(Covariance_matrix);
|
|
|
|
CovarFileNumber = 1;
|
|
|
|
|
|
|
|
% Compute 2nd order moments and save them in *_Posterior2ndOrderMoments* files
|
|
|
|
linea = 0;
|
|
|
|
for file = 1:NumberOfDrawsFiles
|
2008-06-24 20:20:48 +02:00
|
|
|
load([M_.dname '/metropolis/' DrawsFiles(file).name '.mat']);
|
2007-09-22 00:54:23 +02:00
|
|
|
NumberOfDraws = rows(pdraws);
|
2008-06-17 23:23:02 +02:00
|
|
|
isdrsaved = cols(pdraws)-1;
|
2007-09-22 00:54:23 +02:00
|
|
|
for linee = 1:NumberOfDraws
|
|
|
|
linea = linea+1;
|
2008-06-17 23:23:02 +02:00
|
|
|
if isdrsaved
|
|
|
|
dr = pdraws{linee,2};
|
|
|
|
else
|
|
|
|
set_parameters(pdraws{linee,1});
|
|
|
|
[dr,info] = resol(oo_.steady_state,0);
|
|
|
|
end
|
2008-06-21 10:33:31 +02:00
|
|
|
tmp = th_autocovariances(dr,ivar,M_,options_);
|
2007-09-22 00:54:23 +02:00
|
|
|
for i=1:nvar
|
|
|
|
for j=i:nvar
|
2008-06-21 10:33:31 +02:00
|
|
|
Covariance_matrix(linea,symmetric_matrix_index(i,j,nvar)) = tmp{1}(i,j);
|
2007-09-22 00:54:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if linea == NumberOfCovarLines
|
2008-06-24 20:20:48 +02:00
|
|
|
save([ M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix');
|
2007-09-22 00:54:23 +02:00
|
|
|
CovarFileNumber = CovarFileNumber + 1;
|
|
|
|
linea = 0;
|
|
|
|
test = CovarFileNumber-NumberOfCovarFiles;
|
2008-06-17 23:23:02 +02:00
|
|
|
if ~test% Prepare the last round...
|
2007-09-22 00:54:23 +02:00
|
|
|
Covariance_matrix = zeros(NumberOfLinesInTheLastCovarFile,nvar*(nvar+1)/2);
|
|
|
|
NumberOfCovarLines = NumberOfLinesInTheLastCovarFile;
|
2008-06-17 23:23:02 +02:00
|
|
|
CovarFileNumber = CovarFileNumber - 1;
|
|
|
|
elseif test<0;
|
2007-09-22 00:54:23 +02:00
|
|
|
Covariance_matrix = zeros(MaXNumberOfCovarLines,nvar*(nvar+1)/2);
|
|
|
|
else
|
2008-06-17 23:23:02 +02:00
|
|
|
clear('Covariance_matrix');
|
2007-09-22 00:54:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-24 19:13:36 +02:00
|
|
|
options_.ar = nar;
|