2009-06-03 16:50:02 +02:00
|
|
|
function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
|
2009-12-16 18:17:34 +01:00
|
|
|
dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type)
|
2009-06-11 16:39:52 +02:00
|
|
|
% This function computes the posterior or prior distribution of the conditional variance
|
2009-06-03 16:50:02 +02:00
|
|
|
% decomposition of the endogenous variables (or a subset of the endogenous variables).
|
2011-09-17 12:33:07 +02:00
|
|
|
%
|
|
|
|
% INPUTS
|
2009-06-11 16:39:52 +02:00
|
|
|
% 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'
|
|
|
|
%
|
|
|
|
%
|
2011-09-17 12:33:07 +02:00
|
|
|
% OUTPUTS
|
2009-06-11 16:39:52 +02:00
|
|
|
% 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).
|
2009-06-03 16:50:02 +02:00
|
|
|
|
2012-06-08 18:22:34 +02:00
|
|
|
% Copyright (C) 2009-2012 Dynare Team
|
2009-06-03 16:50:02 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
% Get informations about the _posterior_draws files.
|
2009-06-11 16:39:52 +02:00
|
|
|
if strcmpi(type,'posterior')
|
|
|
|
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
|
|
|
|
posterior = 1;
|
|
|
|
elseif strcmpi(type,'prior')
|
|
|
|
DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
|
2011-12-15 11:56:23 +01:00
|
|
|
CheckPath('prior/moments',M_.dname);
|
2009-06-11 16:39:52 +02:00
|
|
|
posterior = 0;
|
|
|
|
else
|
|
|
|
disp('dsge_simulated_theoretical_conditional_variance_decomposition:: Unknown type!')
|
|
|
|
error()
|
|
|
|
end
|
|
|
|
|
2009-06-15 16:36:30 +02:00
|
|
|
% Set varlist (vartan)
|
|
|
|
if ~posterior
|
|
|
|
if isfield(options_,'varlist')
|
|
|
|
temp = options_.varlist;
|
|
|
|
end
|
|
|
|
options_.varlist = options_.prior_analysis_endo_var_list;
|
|
|
|
end
|
2012-06-06 12:27:46 +02:00
|
|
|
[ivar,vartan ] = get_variables_list(options_, M_);
|
2009-06-15 16:36:30 +02:00
|
|
|
if ~posterior
|
|
|
|
if exist('temp','var')
|
|
|
|
options_.varlist = temp;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
nvar = length(ivar);
|
|
|
|
|
|
|
|
% Set the size of the auto-correlation function to zero.
|
|
|
|
nar = options_.ar;
|
|
|
|
options_.ar = 0;
|
|
|
|
|
2009-06-03 16:50:02 +02:00
|
|
|
NumberOfDrawsFiles = rows(DrawsFiles);
|
2010-11-28 11:03:40 +01:00
|
|
|
NumberOfSavedElementsPerSimulation = nvar*M_.exo_nbr*length(Steps);
|
2009-06-03 16:50:02 +02:00
|
|
|
MaXNumberOfConditionalDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
|
|
|
|
|
|
|
|
if SampleSize<=MaXNumberOfConditionalDecompLines
|
2010-11-28 11:03:40 +01:00
|
|
|
Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,SampleSize);
|
2009-06-03 16:50:02 +02:00
|
|
|
NumberOfConditionalDecompFiles = 1;
|
|
|
|
else
|
2010-11-28 11:03:40 +01:00
|
|
|
Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,MaXNumberOfConditionalDecompLines);
|
2009-06-03 16:50:02 +02:00
|
|
|
NumberOfLinesInTheLastConditionalDecompFile = mod(SampleSize,MaXNumberOfConditionalDecompLines);
|
2009-06-15 16:36:30 +02:00
|
|
|
NumberOfConditionalDecompFiles = ceil(SampleSize/MaXNumberOfConditionalDecompLines);
|
2009-06-03 16:50:02 +02:00
|
|
|
end
|
|
|
|
|
2009-06-26 12:21:30 +02:00
|
|
|
NumberOfConditionalDecompLines = size(Conditional_decomposition_array,4);
|
|
|
|
ConditionalDecompFileNumber = 0;
|
2009-06-03 16:50:02 +02:00
|
|
|
|
|
|
|
StateSpaceModel.number_of_state_equations = M_.endo_nbr;
|
|
|
|
StateSpaceModel.number_of_state_innovations = M_.exo_nbr;
|
|
|
|
|
2009-06-26 12:21:30 +02:00
|
|
|
first_call = 1;
|
2009-06-03 16:50:02 +02:00
|
|
|
|
|
|
|
linea = 0;
|
|
|
|
for file = 1:NumberOfDrawsFiles
|
2009-06-11 16:39:52 +02:00
|
|
|
if posterior
|
|
|
|
load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
|
|
|
|
else
|
|
|
|
load([M_.dname '/prior/draws/' DrawsFiles(file).name ]);
|
|
|
|
end
|
2009-06-03 16:50:02 +02:00
|
|
|
isdrsaved = columns(pdraws)-1;
|
|
|
|
NumberOfDraws = rows(pdraws);
|
|
|
|
for linee = 1:NumberOfDraws
|
|
|
|
linea = linea+1;
|
|
|
|
if isdrsaved
|
|
|
|
set_parameters(pdraws{linee,1});% Needed to update the covariance matrix of the state innovations.
|
|
|
|
dr = pdraws{linee,2};
|
|
|
|
else
|
|
|
|
set_parameters(pdraws{linee,1});
|
2011-09-17 12:33:07 +02:00
|
|
|
[dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
|
2009-06-03 16:50:02 +02:00
|
|
|
end
|
2009-06-26 12:21:30 +02:00
|
|
|
if first_call
|
|
|
|
endo_nbr = M_.endo_nbr;
|
2012-11-16 20:05:13 +01:00
|
|
|
nstatic = M_.nstatic;
|
|
|
|
nspred = M_.nspred;
|
2009-06-26 12:21:30 +02:00
|
|
|
iv = (1:endo_nbr)';
|
2012-11-16 20:05:13 +01:00
|
|
|
ic = [ nstatic+(1:nspred) endo_nbr+(1:size(dr.ghx,2)-nspred) ]';
|
2011-02-20 12:24:24 +01:00
|
|
|
StateSpaceModel.number_of_state_equations = M_.endo_nbr;
|
2009-06-26 12:21:30 +02:00
|
|
|
StateSpaceModel.number_of_state_innovations = M_.exo_nbr;
|
2009-10-29 18:16:10 +01:00
|
|
|
StateSpaceModel.sigma_e_is_diagonal = M_.sigma_e_is_diagonal;
|
2010-11-28 11:03:40 +01:00
|
|
|
StateSpaceModel.order_var = dr.order_var;
|
2009-06-26 12:21:30 +02:00
|
|
|
first_call = 0;
|
2012-11-16 20:05:13 +01:00
|
|
|
clear('endo_nbr','nstatic','nspred','k');
|
2009-06-26 12:21:30 +02:00
|
|
|
end
|
2011-01-26 14:05:39 +01:00
|
|
|
[StateSpaceModel.transition_matrix,StateSpaceModel.impulse_matrix] = kalman_transition_matrix(dr,iv,ic,M_.exo_nbr);
|
2009-06-03 16:50:02 +02:00
|
|
|
StateSpaceModel.state_innovations_covariance_matrix = M_.Sigma_e;
|
|
|
|
clear('dr');
|
2009-06-26 12:21:30 +02:00
|
|
|
Conditional_decomposition_array(:,:,:,linea) = conditional_variance_decomposition(StateSpaceModel, Steps, ivar);
|
2009-06-03 16:50:02 +02:00
|
|
|
if linea == NumberOfConditionalDecompLines
|
2009-06-26 12:21:30 +02:00
|
|
|
ConditionalDecompFileNumber = ConditionalDecompFileNumber + 1;
|
|
|
|
linea = 0;
|
2009-06-11 16:39:52 +02:00
|
|
|
if posterior
|
|
|
|
save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
|
|
|
|
'Conditional_decomposition_array');
|
|
|
|
else
|
|
|
|
save([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
|
|
|
|
'Conditional_decomposition_array');
|
|
|
|
end
|
2009-06-26 12:21:30 +02:00
|
|
|
if (ConditionalDecompFileNumber==NumberOfConditionalDecompFiles-1)% Prepare last round.
|
2010-11-28 11:03:40 +01:00
|
|
|
Conditional_decomposition_array = zeros(nvar, length(Steps),M_.exo_nbr,NumberOfLinesInTheLastConditionalDecompFile) ;
|
2009-06-03 16:50:02 +02:00
|
|
|
NumberOfConditionalDecompLines = NumberOfLinesInTheLastConditionalDecompFile;
|
2009-06-26 12:21:30 +02:00
|
|
|
elseif ConditionalDecompFileNumber<NumberOfConditionalDecompFiles-1
|
2010-11-28 11:03:40 +01:00
|
|
|
Conditional_decomposition_array = zeros(nvar,length(Steps),M_.exo_nbr,MaXNumberOfConditionalDecompLines);
|
2009-06-03 16:50:02 +02:00
|
|
|
else
|
|
|
|
clear('Conditional_decomposition_array');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-16 20:05:13 +01:00
|
|
|
options_.ar = nar;
|