2008-05-19 15:22:57 +02:00
|
|
|
function PosteriorIRF(type)
|
2014-06-23 11:08:48 +02:00
|
|
|
% Builds posterior IRFs after the MH algorithm.
|
|
|
|
%
|
|
|
|
% INPUTS
|
2008-05-19 15:22:57 +02:00
|
|
|
% o type [char] string specifying the joint density of the
|
2014-06-23 11:08:48 +02:00
|
|
|
% deep parameters ('prior','posterior').
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
2008-05-19 15:22:57 +02:00
|
|
|
% None (oo_ and plots).
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None
|
2008-08-01 20:53:30 +02:00
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
% PARALLEL CONTEXT
|
|
|
|
% This funtion has been parallelized in two different points. Then we have two core
|
|
|
|
% functions associated with it(the _core1 and _core2).
|
2016-05-19 17:13:39 +02:00
|
|
|
% See also the comments posterior_sampler.m funtion.
|
2010-05-31 11:50:48 +02:00
|
|
|
|
2022-04-13 13:15:19 +02:00
|
|
|
% Copyright © 2006-2018 Dynare Team
|
2008-08-01 20:53:30 +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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-05-19 15:22:57 +02:00
|
|
|
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2014-06-23 11:08:48 +02:00
|
|
|
global options_ estim_params_ oo_ M_ bayestopt_ dataset_ dataset_info
|
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
% Set the number of periods
|
2014-06-23 11:08:48 +02:00
|
|
|
if isempty(options_.irf) || ~options_.irf
|
2008-05-19 15:22:57 +02:00
|
|
|
options_.irf = 40;
|
|
|
|
end
|
|
|
|
% Set varlist if necessary
|
|
|
|
varlist = options_.varlist;
|
|
|
|
if isempty(varlist)
|
2017-10-10 10:05:59 +02:00
|
|
|
varlist = options_.varobs;
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
options_.varlist = varlist;
|
2017-10-10 10:05:59 +02:00
|
|
|
nvar = length(varlist);
|
2008-05-19 15:22:57 +02:00
|
|
|
IndxVariables = [];
|
|
|
|
for i=1:nvar
|
2017-10-10 10:05:59 +02:00
|
|
|
idx = strmatch(varlist{i}, M_.endo_names, 'exact');
|
2008-05-19 15:22:57 +02:00
|
|
|
if isempty(idx)
|
2017-10-10 10:05:59 +02:00
|
|
|
disp(['PosteriorIRF :: ' varlist{i} 'is not a declared endogenous variable!'])
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2017-10-10 10:05:59 +02:00
|
|
|
IndxVariables = [IndxVariables, idx];
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
2013-05-18 20:49:51 +02:00
|
|
|
|
|
|
|
% Get index of shocks for requested IRFs
|
2022-09-21 09:27:43 +02:00
|
|
|
irf_shocks_indx = getIrfShocksIndx(M_, options_);
|
2014-06-23 11:08:48 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
% Set various parameters & Check or create directories
|
|
|
|
nvx = estim_params_.nvx;
|
|
|
|
nvn = estim_params_.nvn;
|
|
|
|
ncx = estim_params_.ncx;
|
|
|
|
ncn = estim_params_.ncn;
|
|
|
|
np = estim_params_.np ;
|
|
|
|
npar = nvx+nvn+ncx+ncn+np;
|
2010-06-24 12:49:27 +02:00
|
|
|
offset = npar-np; clear('nvx','nvn','ncx','ncn','np');
|
|
|
|
|
2014-06-23 11:08:48 +02:00
|
|
|
nvobs = dataset_.vobs;
|
|
|
|
gend = dataset_.nobs;
|
2008-05-19 15:22:57 +02:00
|
|
|
MaxNumberOfPlotPerFigure = 9;
|
|
|
|
nn = sqrt(MaxNumberOfPlotPerFigure);
|
|
|
|
MAX_nirfs_dsge = ceil(options_.MaxNumberOfBytes/(options_.irf*nvar*M_.exo_nbr)/8);
|
|
|
|
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
|
2010-06-24 12:49:27 +02:00
|
|
|
if options_.dsge_var
|
2008-05-19 15:22:57 +02:00
|
|
|
MAX_nirfs_dsgevar = ceil(options_.MaxNumberOfBytes/(options_.irf*nvobs*M_.exo_nbr)/8);
|
|
|
|
else
|
|
|
|
MAX_nirfs_dsgevar = 0;
|
|
|
|
end
|
2010-06-24 12:49:27 +02:00
|
|
|
|
2011-12-15 11:56:23 +01:00
|
|
|
DirectoryName = CheckPath('Output',M_.dname);
|
2008-05-19 15:22:57 +02:00
|
|
|
if strcmpi(type,'posterior')
|
2011-12-15 11:56:23 +01:00
|
|
|
MhDirectoryName = CheckPath('metropolis',M_.dname);
|
2008-05-19 15:22:57 +02:00
|
|
|
elseif strcmpi(type,'gsa')
|
2011-02-25 09:27:33 +01:00
|
|
|
if options_.opt_gsa.pprior
|
2011-12-15 11:56:23 +01:00
|
|
|
MhDirectoryName = CheckPath(['GSA' filesep 'prior'],M_.dname);
|
2011-02-25 09:27:33 +01:00
|
|
|
else
|
2011-12-15 11:56:23 +01:00
|
|
|
MhDirectoryName = CheckPath(['GSA' filesep 'mc'],M_.dname);
|
2011-02-25 09:27:33 +01:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2011-12-15 11:56:23 +01:00
|
|
|
MhDirectoryName = CheckPath('prior',M_.dname);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2015-05-09 15:13:59 +02:00
|
|
|
|
|
|
|
%delete old stale files before creating new ones
|
|
|
|
delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']);
|
|
|
|
delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']);
|
|
|
|
delete_stale_file([MhDirectoryName filesep M_.fname '_irf_dsge*.mat']);
|
|
|
|
delete_stale_file([MhDirectoryName filesep M_.fname '_irf_bvardsge*.mat']);
|
|
|
|
delete_stale_file([MhDirectoryName filesep M_.fname '_param_irf*.mat']);
|
|
|
|
|
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if strcmpi(type,'posterior')
|
2013-12-18 16:39:41 +01:00
|
|
|
B = options_.sub_draws;
|
|
|
|
options_.B = B;
|
2016-10-30 18:31:11 +01:00
|
|
|
if round((1-options_.mh_conf_sig)*B)<2
|
|
|
|
fprintf('\nPosteriorIRF:: options_.mh_conf_sig times options_.sub_draws is too small to generate HPDIs. I am omitting them.\n')
|
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
elseif strcmpi(type,'gsa')
|
2011-12-15 11:56:23 +01:00
|
|
|
RootDirectoryName = CheckPath('gsa',M_.dname);
|
2011-02-25 09:27:33 +01:00
|
|
|
if options_.opt_gsa.pprior
|
|
|
|
load([ RootDirectoryName filesep M_.fname '_prior.mat'],'lpmat0','lpmat','istable')
|
|
|
|
else
|
|
|
|
load([ RootDirectoryName filesep M_.fname '_mc.mat'],'lpmat0','lpmat','istable')
|
|
|
|
end
|
2010-06-24 12:49:27 +02:00
|
|
|
x=[lpmat0(istable,:) lpmat(istable,:)];
|
|
|
|
clear lpmat istable
|
2013-12-18 16:39:41 +01:00
|
|
|
B=size(x,1); options_.B = B;
|
2008-05-19 15:22:57 +02:00
|
|
|
else% type = 'prior'
|
2013-12-18 16:39:41 +01:00
|
|
|
B = options_.prior_draws;
|
|
|
|
options_.B = B;
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2015-05-09 15:13:59 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
irun = 0;
|
|
|
|
IRUN = 0;
|
|
|
|
irun2 = 0;
|
|
|
|
NumberOfIRFfiles_dsge = 1;
|
|
|
|
NumberOfIRFfiles_dsgevar = 1;
|
|
|
|
ifil2 = 1;
|
|
|
|
% Create arrays
|
|
|
|
if B <= MAX_nruns
|
2010-06-24 12:49:27 +02:00
|
|
|
stock_param = zeros(B, npar);
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2010-06-24 12:49:27 +02:00
|
|
|
stock_param = zeros(MAX_nruns, npar);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
if B >= MAX_nirfs_dsge
|
2010-06-24 12:49:27 +02:00
|
|
|
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,MAX_nirfs_dsge);
|
2008-05-19 15:22:57 +02:00
|
|
|
else
|
2010-06-24 12:49:27 +02:00
|
|
|
stock_irf_dsge = zeros(options_.irf,nvar,M_.exo_nbr,B);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
if MAX_nirfs_dsgevar
|
|
|
|
if B >= MAX_nirfs_dsgevar
|
|
|
|
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
|
|
|
|
else
|
|
|
|
stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,B);
|
|
|
|
end
|
2010-06-24 12:49:27 +02:00
|
|
|
NumberOfLags = options_.dsge_varlag;
|
2008-05-19 15:22:57 +02:00
|
|
|
NumberOfLagsTimesNvobs = NumberOfLags*nvobs;
|
|
|
|
if options_.noconstant
|
|
|
|
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs;
|
|
|
|
else
|
|
|
|
NumberOfParametersPerEquation = NumberOfLagsTimesNvobs+1;
|
|
|
|
end
|
|
|
|
Companion_matrix = diag(ones(nvobs*(NumberOfLags-1),1),-nvobs);
|
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
% First block of code executed in parallel. The function devoted to do it is PosteriorIRF_core1.m
|
|
|
|
% function.
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
b = 0;
|
2010-02-10 18:46:24 +01:00
|
|
|
|
|
|
|
localVars=[];
|
|
|
|
|
|
|
|
% Save the local variables.
|
|
|
|
|
2010-02-12 17:41:38 +01:00
|
|
|
localVars.IRUN = IRUN;
|
2010-02-10 18:46:24 +01:00
|
|
|
localVars.irun = irun;
|
|
|
|
localVars.irun2=irun2;
|
2012-05-30 11:24:35 +02:00
|
|
|
localVars.npar = npar;
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
localVars.type=type;
|
2010-06-24 12:49:27 +02:00
|
|
|
if strcmpi(type,'posterior')
|
2014-06-23 11:08:48 +02:00
|
|
|
while b<B
|
2010-06-24 12:49:27 +02:00
|
|
|
b = b + 1;
|
2017-10-03 15:32:17 +02:00
|
|
|
x(b,:) = GetOneDraw(type,M_,estim_params_,oo_,options_,bayestopt_);
|
2010-06-24 12:49:27 +02:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 12:42:01 +02:00
|
|
|
if ~strcmpi(type,'prior')
|
2010-06-24 12:49:27 +02:00
|
|
|
localVars.x=x;
|
2010-02-10 18:46:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
b=0;
|
2010-06-24 12:49:27 +02:00
|
|
|
if options_.dsge_var
|
|
|
|
localVars.gend = gend;
|
|
|
|
localVars.nvobs = nvobs;
|
|
|
|
localVars.NumberOfParametersPerEquation = NumberOfParametersPerEquation;
|
|
|
|
localVars.NumberOfLags = options_.dsge_varlag;
|
|
|
|
localVars.NumberOfLagsTimesNvobs = NumberOfLags*nvobs;
|
|
|
|
localVars.Companion_matrix = diag(ones(nvobs*(NumberOfLags-1),1),-nvobs);
|
2014-06-23 11:08:48 +02:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
localVars.nvar=nvar;
|
|
|
|
localVars.IndxVariables=IndxVariables;
|
|
|
|
localVars.MAX_nirfs_dsgevar=MAX_nirfs_dsgevar;
|
|
|
|
localVars.MAX_nirfs_dsge=MAX_nirfs_dsge;
|
|
|
|
localVars.MAX_nruns=MAX_nruns;
|
|
|
|
localVars.NumberOfIRFfiles_dsge=NumberOfIRFfiles_dsge;
|
|
|
|
localVars.NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar;
|
|
|
|
localVars.ifil2=ifil2;
|
2011-02-25 09:27:33 +01:00
|
|
|
localVars.MhDirectoryName=MhDirectoryName;
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
% Like sequential execution!
|
2017-05-16 12:42:01 +02:00
|
|
|
if isnumeric(options_.parallel)
|
2010-02-10 18:46:24 +01:00
|
|
|
[fout] = PosteriorIRF_core1(localVars,1,B,0);
|
2012-07-02 10:55:02 +02:00
|
|
|
nosaddle = fout.nosaddle;
|
2010-02-10 18:46:24 +01:00
|
|
|
else
|
2011-02-04 17:17:48 +01:00
|
|
|
% Parallel execution!
|
2010-02-10 18:46:24 +01:00
|
|
|
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B);
|
2017-05-16 12:42:01 +02:00
|
|
|
for j=1:totCPU-1
|
2010-02-10 18:46:24 +01:00
|
|
|
nfiles = ceil(nBlockPerCPU(j)/MAX_nirfs_dsge);
|
|
|
|
NumberOfIRFfiles_dsge(j+1) =NumberOfIRFfiles_dsge(j)+nfiles;
|
2017-05-16 12:42:01 +02:00
|
|
|
if MAX_nirfs_dsgevar
|
2010-10-08 16:19:03 +02:00
|
|
|
nfiles = ceil(nBlockPerCPU(j)/MAX_nirfs_dsgevar);
|
|
|
|
else
|
|
|
|
nfiles=0;
|
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
NumberOfIRFfiles_dsgevar(j+1) =NumberOfIRFfiles_dsgevar(j)+nfiles;
|
|
|
|
nfiles = ceil(nBlockPerCPU(j)/MAX_nruns);
|
|
|
|
ifil2(j+1) =ifil2(j)+nfiles;
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
localVars.NumberOfIRFfiles_dsge=NumberOfIRFfiles_dsge;
|
|
|
|
localVars.NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar;
|
|
|
|
localVars.ifil2=ifil2;
|
2014-06-23 11:08:48 +02:00
|
|
|
|
2010-02-10 18:46:24 +01:00
|
|
|
globalVars = struct('M_',M_, ...
|
2011-02-04 17:17:48 +01:00
|
|
|
'options_', options_, ...
|
|
|
|
'bayestopt_', bayestopt_, ...
|
|
|
|
'estim_params_', estim_params_, ...
|
2011-09-22 11:17:31 +02:00
|
|
|
'oo_', oo_, ...
|
2014-06-23 11:08:48 +02:00
|
|
|
'dataset_',dataset_, ...
|
|
|
|
'dataset_info',dataset_info);
|
|
|
|
|
2010-02-10 18:46:24 +01:00
|
|
|
% which files have to be copied to run remotely
|
2018-06-27 17:02:13 +02:00
|
|
|
NamFileInput(1,:) = {'',[M_.fname '.static.m']};
|
|
|
|
NamFileInput(2,:) = {'',[M_.fname '.dynamic.m']};
|
2017-08-29 10:58:39 +02:00
|
|
|
if M_.set_auxiliary_variables
|
2018-06-27 17:02:13 +02:00
|
|
|
NamFileInput(3,:) = {'',[M_.fname '.set_auxiliary_variables.m']};
|
2017-08-29 10:58:39 +02:00
|
|
|
end
|
2017-05-16 12:42:01 +02:00
|
|
|
if options_.steadystate_flag
|
|
|
|
if options_.steadystate_flag == 1
|
2017-02-09 09:44:28 +01:00
|
|
|
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};
|
|
|
|
else
|
2018-06-27 17:02:13 +02:00
|
|
|
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '.steadystate.m']};
|
2017-02-09 09:44:28 +01:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2011-02-04 17:17:48 +01:00
|
|
|
[fout] = masterParallel(options_.parallel, 1, B,NamFileInput,'PosteriorIRF_core1', localVars, globalVars, options_.parallel_info);
|
2012-07-02 10:55:02 +02:00
|
|
|
nosaddle=0;
|
2017-05-16 12:42:01 +02:00
|
|
|
for j=1:length(fout)
|
2012-07-02 10:55:02 +02:00
|
|
|
nosaddle = nosaddle + fout(j).nosaddle;
|
|
|
|
end
|
2014-06-23 11:08:48 +02:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
% END first parallel section!
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
if nosaddle
|
2014-06-23 11:08:48 +02:00
|
|
|
disp(['PosteriorIRF :: Percentage of discarded posterior draws = ' num2str(nosaddle/(B+nosaddle))])
|
2010-02-10 18:46:24 +01:00
|
|
|
end
|
|
|
|
|
2011-02-25 09:27:33 +01:00
|
|
|
ReshapeMatFiles('irf_dsge',type)
|
2008-05-19 15:22:57 +02:00
|
|
|
if MAX_nirfs_dsgevar
|
|
|
|
ReshapeMatFiles('irf_bvardsge')
|
|
|
|
end
|
|
|
|
|
|
|
|
if strcmpi(type,'gsa')
|
2011-02-04 17:17:48 +01:00
|
|
|
return
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
|
2010-02-12 19:31:39 +01:00
|
|
|
IRF_DSGEs = dir([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']);
|
2008-05-19 15:22:57 +02:00
|
|
|
NumberOfIRFfiles_dsge = length(IRF_DSGEs);
|
|
|
|
|
2010-02-12 19:31:39 +01:00
|
|
|
IRF_BVARDSGEs = dir([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']);
|
2008-05-19 15:22:57 +02:00
|
|
|
NumberOfIRFfiles_dsgevar = length(IRF_BVARDSGEs);
|
|
|
|
|
|
|
|
MeanIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
MedianIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
VarIRF = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
DistribIRF = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
|
|
|
HPDIRF = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
|
|
|
|
|
|
|
if options_.TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
varlist_TeX = cell(nvar, 1);
|
2011-02-04 17:17:48 +01:00
|
|
|
for i=1:nvar
|
2017-10-10 10:05:59 +02:00
|
|
|
varlist_TeX(i) = {M_.endo_names_tex{IndxVariables(i)}};
|
2011-02-04 17:17:48 +01:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
|
2013-11-20 18:03:12 +01:00
|
|
|
fprintf('Estimation::mcmc: Posterior (dsge) IRFs...\n');
|
2017-10-10 10:05:59 +02:00
|
|
|
tit(M_.exo_names_orig_ord) = M_.exo_names;
|
2008-05-19 15:22:57 +02:00
|
|
|
kdx = 0;
|
|
|
|
|
|
|
|
for file = 1:NumberOfIRFfiles_dsge
|
2011-02-04 17:17:48 +01:00
|
|
|
load([MhDirectoryName filesep M_.fname '_IRF_DSGEs' int2str(file) '.mat']);
|
2013-05-18 20:49:51 +02:00
|
|
|
for i = irf_shocks_indx
|
2011-02-04 17:17:48 +01:00
|
|
|
for j = 1:nvar
|
|
|
|
for k = 1:size(STOCK_IRF_DSGE,1)
|
|
|
|
kk = k+kdx;
|
|
|
|
[MeanIRF(kk,j,i),MedianIRF(kk,j,i),VarIRF(kk,j,i),HPDIRF(kk,:,j,i),...
|
|
|
|
DistribIRF(kk,:,j,i)] = posterior_moments(squeeze(STOCK_IRF_DSGE(k,j,i,:)),0,options_.mh_conf_sig);
|
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
2011-02-04 17:17:48 +01:00
|
|
|
kdx = kdx + size(STOCK_IRF_DSGE,1);
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
clear STOCK_IRF_DSGE;
|
|
|
|
|
2013-05-18 20:49:51 +02:00
|
|
|
for i = irf_shocks_indx
|
2011-02-04 17:17:48 +01:00
|
|
|
for j = 1:nvar
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s_%s', M_.endo_names{IndxVariables(j)}, tit{i});
|
2015-10-12 15:20:15 +02:00
|
|
|
oo_.PosteriorIRF.dsge.Mean.(name) = MeanIRF(:,j,i);
|
|
|
|
oo_.PosteriorIRF.dsge.Median.(name) = MedianIRF(:,j,i);
|
|
|
|
oo_.PosteriorIRF.dsge.Var.(name) = VarIRF(:,j,i);
|
|
|
|
oo_.PosteriorIRF.dsge.deciles.(name) = DistribIRF(:,:,j,i);
|
|
|
|
oo_.PosteriorIRF.dsge.HPDinf.(name) = HPDIRF(:,1,j,i);
|
|
|
|
oo_.PosteriorIRF.dsge.HPDsup.(name) = HPDIRF(:,2,j,i);
|
2011-02-04 17:17:48 +01:00
|
|
|
end
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if MAX_nirfs_dsgevar
|
|
|
|
MeanIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
MedianIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
VarIRFdsgevar = zeros(options_.irf,nvar,M_.exo_nbr);
|
|
|
|
DistribIRFdsgevar = zeros(options_.irf,9,nvar,M_.exo_nbr);
|
2014-06-23 11:08:48 +02:00
|
|
|
HPDIRFdsgevar = zeros(options_.irf,2,nvar,M_.exo_nbr);
|
2013-11-20 18:03:12 +01:00
|
|
|
fprintf('Estimation::mcmc: Posterior (bvar-dsge) IRFs...\n');
|
2017-10-10 10:05:59 +02:00
|
|
|
tit(M_.exo_names_orig_ord) = M_.exo_names;
|
2008-05-19 15:22:57 +02:00
|
|
|
kdx = 0;
|
|
|
|
for file = 1:NumberOfIRFfiles_dsgevar
|
2010-02-12 19:31:39 +01:00
|
|
|
load([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs' int2str(file) '.mat']);
|
2013-05-18 20:49:51 +02:00
|
|
|
for i = irf_shocks_indx
|
2008-05-19 15:22:57 +02:00
|
|
|
for j = 1:nvar
|
|
|
|
for k = 1:size(STOCK_IRF_BVARDSGE,1)
|
|
|
|
kk = k+kdx;
|
|
|
|
[MeanIRFdsgevar(kk,j,i),MedianIRFdsgevar(kk,j,i),VarIRFdsgevar(kk,j,i),...
|
|
|
|
HPDIRFdsgevar(kk,:,j,i),DistribIRFdsgevar(kk,:,j,i)] = ...
|
|
|
|
posterior_moments(squeeze(STOCK_IRF_BVARDSGE(k,j,i,:)),0,options_.mh_conf_sig);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
kdx = kdx + size(STOCK_IRF_BVARDSGE,1);
|
|
|
|
end
|
2014-06-23 11:08:48 +02:00
|
|
|
clear STOCK_IRF_BVARDSGE;
|
2013-05-18 20:49:51 +02:00
|
|
|
for i = irf_shocks_indx
|
2008-05-19 15:22:57 +02:00
|
|
|
for j = 1:nvar
|
2017-10-10 10:05:59 +02:00
|
|
|
name = sprintf('%s_%s', M_.endo_names{IndxVariables(j)}, tit{i});
|
2015-10-12 15:20:15 +02:00
|
|
|
oo_.PosteriorIRF.bvardsge.Mean.(name) = MeanIRFdsgevar(:,j,i);
|
|
|
|
oo_.PosteriorIRF.bvardsge.Median.(name) = MedianIRFdsgevar(:,j,i);
|
|
|
|
oo_.PosteriorIRF.bvardsge.Var.(name) = VarIRFdsgevar(:,j,i);
|
|
|
|
oo_.PosteriorIRF.bvardsge.deciles.(name) = DistribIRFdsgevar(:,:,j,i);
|
|
|
|
oo_.PosteriorIRF.bvardsge.HPDinf.(name) = HPDIRFdsgevar(:,1,j,i);
|
|
|
|
oo_.PosteriorIRF.bvardsge.HPDsup.(name) = HPDIRFdsgevar(:,2,j,i);
|
2008-05-19 15:22:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-20 18:03:12 +01:00
|
|
|
%
|
|
|
|
% Finally I build the plots.
|
|
|
|
%
|
2010-02-10 18:46:24 +01:00
|
|
|
|
|
|
|
|
2010-05-31 11:50:48 +02:00
|
|
|
% Second block of code executed in parallel, with the exception of file
|
|
|
|
% .tex generation always run in sequentially. This portion of code is execute in parallel by
|
|
|
|
% PosteriorIRF_core2.m function.
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2016-12-21 08:59:57 +01:00
|
|
|
if ~options_.nograph && ~options_.no_graph.posterior
|
2017-05-16 15:10:20 +02:00
|
|
|
% Save the local variables.
|
|
|
|
localVars=[];
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
Check=options_.TeX;
|
|
|
|
if (Check)
|
|
|
|
localVars.varlist_TeX=varlist_TeX;
|
|
|
|
end
|
2011-02-04 17:17:48 +01:00
|
|
|
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
localVars.nvar=nvar;
|
|
|
|
localVars.MeanIRF=MeanIRF;
|
|
|
|
localVars.tit=tit;
|
|
|
|
localVars.nn=nn;
|
|
|
|
localVars.MAX_nirfs_dsgevar=MAX_nirfs_dsgevar;
|
|
|
|
localVars.HPDIRF=HPDIRF;
|
|
|
|
localVars.varlist=varlist;
|
|
|
|
localVars.MaxNumberOfPlotPerFigure=MaxNumberOfPlotPerFigure;
|
|
|
|
if options_.dsge_var
|
|
|
|
localVars.HPDIRFdsgevar=HPDIRFdsgevar;
|
|
|
|
localVars.MeanIRFdsgevar = MeanIRFdsgevar;
|
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
% The files .TeX are genereted in sequential way always!
|
|
|
|
|
|
|
|
subplotnum = 0;
|
2017-10-10 10:05:59 +02:00
|
|
|
titTeX(M_.exo_names_orig_ord) = M_.exo_names_tex;
|
2017-05-16 15:10:20 +02:00
|
|
|
if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
|
|
|
|
fidTeX = fopen([DirectoryName filesep M_.fname '_BayesianIRF.tex'],'w');
|
|
|
|
fprintf(fidTeX,'%% TeX eps-loader file generated by PosteriorIRF.m (Dynare).\n');
|
|
|
|
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
|
|
|
fprintf(fidTeX,' \n');
|
2017-10-10 10:05:59 +02:00
|
|
|
titTeX(M_.exo_names_orig_ord) = M_.exo_names_tex;
|
2017-05-16 15:10:20 +02:00
|
|
|
|
|
|
|
for ii=irf_shocks_indx
|
|
|
|
figunumber = 0;
|
|
|
|
|
|
|
|
for jj=1:nvar
|
|
|
|
if max(abs(MeanIRF(:,jj,ii))) >= options_.impulse_responses.plot_threshold
|
|
|
|
subplotnum = subplotnum+1;
|
|
|
|
|
|
|
|
if subplotnum == 1
|
|
|
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
|
|
|
end
|
2011-02-04 17:17:48 +01:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
if subplotnum == MaxNumberOfPlotPerFigure || (jj == nvar && subplotnum> 0)
|
|
|
|
figunumber = figunumber+1;
|
|
|
|
|
|
|
|
fprintf(fidTeX,'\\centering \n');
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s/%s_Bayesian_IRF_%s_%d}\n',options_.figures.textwidth*min(subplotnum/nn,1),DirectoryName,M_.fname,tit{ii},figunumber);
|
2017-05-16 15:10:20 +02:00
|
|
|
if options_.relative_irf
|
|
|
|
fprintf(fidTeX,['\\caption{Bayesian relative IRF.}']);
|
|
|
|
else
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX,'\\caption{Bayesian IRF: Orthogonalized shock to $%s$.}\n',titTeX{ii});
|
2017-05-16 15:10:20 +02:00
|
|
|
end
|
2017-10-10 10:05:59 +02:00
|
|
|
fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%d}\n', tit{ii},figunumber);
|
2017-05-16 15:10:20 +02:00
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
subplotnum = 0;
|
2015-05-12 08:06:59 +02:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
end
|
2011-02-04 17:17:48 +01:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
fprintf(fidTeX,'%% End of TeX file.\n');
|
|
|
|
fclose(fidTeX);
|
2011-02-04 17:17:48 +01:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
% The others file format are generated in parallel by PosteriorIRF_core2!
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if ~isoctave
|
2017-10-10 10:05:59 +02:00
|
|
|
if isnumeric(options_.parallel) || (M_.exo_nbr*ceil(length(varlist)/MaxNumberOfPlotPerFigure))<8
|
2011-04-06 14:22:34 +02:00
|
|
|
[fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
|
|
|
|
else
|
2017-05-16 15:10:20 +02:00
|
|
|
isRemoteOctave = 0;
|
|
|
|
for indPC=1:length(options_.parallel)
|
|
|
|
isRemoteOctave = isRemoteOctave + (findstr(options_.parallel(indPC).MatlabOctavePath, 'octave'));
|
|
|
|
end
|
|
|
|
if isRemoteOctave
|
|
|
|
[fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
|
|
|
|
else
|
|
|
|
globalVars = struct('M_',M_, ...
|
|
|
|
'options_', options_);
|
2014-06-23 11:08:48 +02:00
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
[fout] = masterParallel(options_.parallel, 1, M_.exo_nbr,NamFileInput,'PosteriorIRF_core2', localVars, globalVars, options_.parallel_info);
|
|
|
|
end
|
2011-04-06 14:22:34 +02:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
else
|
|
|
|
[fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
|
2010-06-24 18:11:08 +02:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
% END parallel code!
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2016-12-21 08:59:57 +01:00
|
|
|
end
|
2010-02-10 18:46:24 +01:00
|
|
|
|
2014-04-30 10:10:30 +02:00
|
|
|
fprintf('Estimation::mcmc: Posterior IRFs, done!\n');
|