ms_variance_decomposition.m 3.15 KB
Newer Older
1
2
function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
%function ms_variance_decomposition()
3
% MS-SBVAR Variance Decomposition
4
5
%
% INPUTS
Houtan Bastani's avatar
Houtan Bastani committed
6
7
8
%    M_:          (struct)    model structure
%    options_:    (struct)    options
%    oo_:         (struct)    results
9
10
%
% OUTPUTS
Houtan Bastani's avatar
Houtan Bastani committed
11
12
%    options_:    (struct)    options
%    oo_:         (struct)    results
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%
% SPECIAL REQUIREMENTS
%    none

% Copyright (C) 2011 Dynare Team
%
% 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/>.

34
35
36
37
38
39
40
disp('MS-SBVAR Variance Decomposition');
options_ = set_file_tags(options_);
[options_, oo_] = set_ms_estimation_file(options_, oo_);
options_ = set_ms_simulation_file(options_);
clean_files_for_second_type_of_mex(M_, options_, 'variance_decomposition')
vddir = [options_.ms.output_file_tag filesep 'Variance_Decomposition'];
create_dir(vddir);
41
42
43

% NOTICE THAT VARIANCE DECOMPOSITION DEFAULTS TO USING THE MEAN, NOT MEDIAN OR BANDED

44
45
46
47
48
49
50
51
52
53
opt = {
    {'file_tag', options_.ms.estimation_file_tag}, ...
    {'seed', options_.DynareRandomStreams.seed}, ...
    {'horizon', options_.ms.horizon}, ...
    {'filtered', options_.ms.filtered_probabilities}, ...
    {'error_bands', options_.ms.error_bands}, ...
    {'percentiles', options_.ms.error_band_percentiles}, ...
    {'thin', options_.ms.thinning_factor}, ...
    {'mean'} ...
    };
54

55
56
57
58
if options_.ms.median
    opt = [opt(:)' {{'median'}}];
end

59
60
[err, vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
    {'shocks', options_.ms.shock_draws}}]);
61
mexErrCheck('mex_ms_variance_decomposition ergodic ', err);
62
plot_ms_variance_decomposition(M_,options_,vd, 'Ergodic Variance Decomposition',options_.graph_save_formats,options_.TeX);
63

64
65
[err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'free_parameters',oo_.ms.maxparams}, ...
    {'shocks', options_.ms.shock_draws}, {'regimes'}}]);
66
mexErrCheck('mex_ms_variance_decomposition ergodic regimes', err);
67
save([vddir filesep 'ergodic_vd.mat'], 'vd', 'regime_vd');
68

69
if exist(options_.ms.mh_file,'file') > 0
70
71
    [err, vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
        {'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}}]);
72
73
    mexErrCheck('mex_ms_variance_decomposition bayesian ', err);

74
75
    [err, regime_vd] = mex_ms_variance_decomposition([opt(:)', {{'simulation_file',options_.ms.mh_file}, ...
        {'shocks', options_.ms.shocks_per_parameter}, {'parameter_uncertainty'}, {'regimes'}}]);
76
    mexErrCheck('mex_ms_variance_decomposition bayesian regimes ', err);
77
    save([vddir filesep 'bayesian_vd.mat'], 'vd', 'regime_vd');
78
79
end
end