Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
0f001abb
Commit
0f001abb
authored
Jul 29, 2011
by
Houtan Bastani
Browse files
MS-SBVAR: input options that allow code to be called with previous output files
parent
676f201e
Changes
27
Hide whitespace changes
Inline
Side-by-side
matlab/ms-sbvar/clean_files_for_second_type_of_mex.m
0 → 100644
View file @
0f001abb
function
clean_files_for_second_type_of_mex
(
M_
,
options_
,
type
)
%function clean_files_for_second_type_of_mex()
% clean the files for the appropriate file tag and mex function
%
% INPUTS
% M_: (struct) model structure
% options_: (struct) options
% type: (string) one of irf, forecast or
% variance_decomposition
%
% 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/>.
if
isfield
(
options_
.
ms
,
'estimation_file_tag'
)
tagtouse
=
options_
.
ms
.
estimation_file_tag
;
else
tagtouse
=
options_
.
ms
.
file_tag
;
end
if
~
strcmp
(
tagtouse
,
options_
.
ms
.
output_file_tag
)
||
...
~
strcmp
(
M_
.
fname
,
options_
.
ms
.
output_file_tag
)
tagtouse
=
options_
.
ms
.
output_file_tag
;
end
switch
type
case
'irf'
clean_ms_irf_files
(
tagtouse
);
case
'forecast'
clean_ms_forecast_files
(
tagtouse
);
case
'variance_decomposition'
clean_ms_variance_decomposition_files
(
tagtouse
);
otherwise
error
(
'clean_files_for_second_type_of_mex: should not arrive here'
);
end
matlab/ms-sbvar/clean_ms_forecast_files.m
0 → 100644
View file @
0f001abb
function
clean_ms_forecast_files
(
file_tag
)
% function clean_ms_forecast_files()
% removes MS forecast files
%
% INPUTS
% file_tag: string indicating tag to use when deleting files
%
% OUTPUTS
% none
%
% 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/>.
delete_dir_if_exists
([
file_tag
filesep
'Forecast'
]);
delete_dir_if_exists
([
file_tag
filesep
'Output'
filesep
'Forecast'
]);
end
matlab/ms-sbvar/clean_ms_irf_files.m
0 → 100644
View file @
0f001abb
function
clean_ms_irf_files
(
file_tag
)
% function clean_ms_irf_files()
% removes MS irf files
%
% INPUTS
% file_tag: string indicating tag to use when deleting files
%
% OUTPUTS
% none
%
% 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/>.
delete_dir_if_exists
([
file_tag
filesep
'IRF'
]);
delete_dir_if_exists
([
file_tag
filesep
'Output'
filesep
'IRF'
]);
end
matlab/ms-sbvar/clean_ms_probabilities_files.m
View file @
0f001abb
...
...
@@ -30,4 +30,5 @@ function clean_ms_probabilities_files(file_tag)
delete_if_exists
([
'smoothed_'
file_tag
'.out'
]);
delete_if_exists
([
'filtered_'
file_tag
'.out'
]);
delete_dir_if_exists
([
file_tag
filesep
'Output'
filesep
'Probabilities'
]);
end
matlab/ms-sbvar/clean_ms_variance_decomposition_files.m
0 → 100644
View file @
0f001abb
function
clean_ms_variance_decomposition_files
(
file_tag
)
% function clean_ms_variance_decomposition_files()
% removes MS variance decomposition files
%
% INPUTS
% file_tag: string indicating tag to use when deleting files
%
% OUTPUTS
% none
%
% 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/>.
delete_dir_if_exists
([
file_tag
filesep
'Variance_Decomposition'
]);
delete_dir_if_exists
([
file_tag
filesep
'Output'
filesep
'Variance_Decomposition'
]);
end
matlab/ms-sbvar/create_dir.m
0 → 100644
View file @
0f001abb
function
create_dir
(
dirname
)
% function create_dir()
% creates directory if it doesn't exist
%
% INPUTS
% dirname: string indicating name of directory
%
% OUTPUTS
% none
%
% 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/>.
if
~
exist
(
dirname
,
'dir'
)
mkdir
(
dirname
);
end
end
matlab/ms-sbvar/delete_dir_if_exists.m
0 → 100644
View file @
0f001abb
function
delete_dir_if_exists
(
dirname
)
% function delete_dir_if_exists()
% removes directory if it exists
%
% INPUTS
% dirname: directory to delete
%
% OUTPUTS
% none
%
% 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/>.
if
exist
(
dirname
,
'dir'
)
rmdir
(
dirname
,
's'
);
end
end
matlab/ms-sbvar/dyn_save_graph.m
View file @
0f001abb
...
...
@@ -30,7 +30,8 @@ function dyn_save_graph(dirname,graph_name,graph_formats,TeX,names,texnames,capt
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
graph_name
=
[
dirname
filesep
'Output'
filesep
regexprep
(
graph_name
,
' '
,
'_'
)];
create_dir
(
dirname
);
graph_name
=
[
dirname
filesep
regexprep
(
graph_name
,
' '
,
'_'
)];
if
nargin
<=
2
TeX
=
0
;
elseif
nargin
<=
4
...
...
@@ -66,4 +67,3 @@ function dyn_save_graph(dirname,graph_name,graph_formats,TeX,names,texnames,capt
fprintf
(
fh
,
'%% End of TeX file.\n'
);
fclose
(
fh
);
end
matlab/ms-sbvar/initialize_ms_sbvar_options.m
View file @
0f001abb
...
...
@@ -32,7 +32,27 @@ function options_=initialize_ms_sbvar_options(M_, options_)
% MS SBVAR
% all mex functions
options_
.
ms
.
file_tag
=
M_
.
fname
;
options_
.
ms
.
output_file_tag
=
M_
.
fname
;
if
isfield
(
options_
.
ms
,
'initialization_file_tag'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'initialization_file_tag'
);
end
if
isfield
(
options_
.
ms
,
'init_file'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'init_file'
);
end
if
isfield
(
options_
.
ms
,
'estimation_file_tag'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'estimation_file_tag'
);
end
if
isfield
(
options_
.
ms
,
'free_param_file'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'free_param_file'
);
end
if
isfield
(
options_
.
ms
,
'simulation_file_tag'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'simulation_file_tag'
);
end
if
isfield
(
options_
.
ms
,
'mh_file'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'mh_file'
);
end
if
isfield
(
options_
.
ms
,
'output_file_tag'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'output_file_tag'
);
end
% prepare ms sbvar & estimation
options_
.
ms
.
coefficients_prior_hyperparameters
=
[
1.0
1.0
0.1
1.2
1.0
1.0
];
options_
.
ms
.
freq
=
4
;
...
...
@@ -97,10 +117,4 @@ options_.ms.shocks_per_parameter = 10;
options_
.
ms
.
median
=
0
;
% forecast
options_
.
ms
.
forecast_data_obs
=
0
;
if
isfield
(
options_
.
ms
,
'free_parameters'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'free_parameters'
);
end
if
isfield
(
options_
.
ms
,
'simulation_file'
)
options_
.
ms
=
rmfield
(
options_
.
ms
,
'simulation_file'
);
end
end
matlab/ms-sbvar/ms_compute_mdd.m
View file @
0f001abb
function
[
options_
,
oo_
]
=
ms_compute_mdd
(
M_
,
options_
,
oo_
)
%function ms_compute_mdd()
% Compute
m
arginal
d
ata
d
ensity
%
MS Sbvar
Compute
M
arginal
D
ata
D
ensity
%
% INPUTS
% M_: (struct) model structure
...
...
@@ -31,15 +31,17 @@ function [options_, oo_]=ms_compute_mdd(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Marginal Data Density'
);
clean_ms_mdd_files
(
options_
.
ms
.
outpu
t_file_tag
,
options_
.
ms
.
mdd_proposal_type
(
1
)
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
options_
=
set_ms_
simul
ation_f
lags_for_other_mex
(
options_
);
o
o
_
=
set_
oo_w_estimation_output
(
options_
,
oo_
);
disp
(
'
MS-SBVAR
Marginal Data Density'
);
options_
=
se
t_file_tag
s
(
options_
);
clean_ms_mdd_files
(
options_
.
ms
.
output_file_tag
,
options_
.
ms
.
mdd_proposal_type
(
1
)
);
[
options_
,
oo_
]
=
set_ms_
estim
ation_f
ile
(
options_
,
oo_
);
o
ptions
_
=
set_
ms_simulation_file
(
options_
);
% setup command line options
opt
=
[
'-mdd -seed '
num2str
(
options_
.
DynareRandomStreams
.
seed
)];
opt
=
[
opt
' -ft '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -ft '
options_
.
ms
.
simulation_file_tag
];
opt
=
[
opt
' -fto '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -pf '
options_
.
ms
.
mh_file
];
opt
=
[
opt
' -d '
num2str
(
options_
.
ms
.
mdd_proposal_draws
)];
if
options_
.
ms
.
mdd_use_mean_center
opt
=
[
opt
' -use_mean'
];
...
...
@@ -54,7 +56,7 @@ end
% compute mdd
[
err
]
=
ms_sbvar_command_line
(
opt
);
mexErrCheck
(
'ms_
sbvar_command_line
mdd'
,
err
);
mexErrCheck
(
'ms_
compute_
mdd'
,
err
);
% grab the muller/bridge log mdd from the output file
mull_exp
=
'Muller \w+\(\w+\) \= (\d+.\d+e\+\d+)'
;
...
...
matlab/ms-sbvar/ms_compute_probabilities.m
View file @
0f001abb
function
[
options_
,
oo_
]
=
ms_compute_probabilities
(
M_
,
options_
,
oo_
)
%function ms_simulation()
% Compute
p
osterior
m
ode
r
egime
p
robabilities
%
MS Sbvar
Compute
P
osterior
M
ode
R
egime
P
robabilities
%
% INPUTS
% M_: (struct) model structure
...
...
@@ -31,14 +31,15 @@ function [options_, oo_]=ms_compute_probabilities(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Compute Regime Probabilities'
);
options_
=
set_
ms_estimation_flags_for_other_mex
(
options_
);
options_
=
set_ms_simulation_flags_for_other_mex
(
options_
);
oo_
=
set_
oo_w
_estimation_
output
(
options_
,
oo_
);
disp
(
'
MS-SBVAR
Compute Regime Probabilities'
);
options_
=
set_
file_tags
(
options_
);
clean_ms_probabilities_files
(
options_
.
ms
.
output_file_tag
);
[
options_
,
oo_
]
=
set_
ms
_estimation_
file
(
options_
,
oo_
);
% setup command line options
opt
=
[
'-probabilities -seed '
num2str
(
options_
.
DynareRandomStreams
.
seed
)];
opt
=
[
opt
' -ft '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -ft '
options_
.
ms
.
estimation_file_tag
];
opt
=
[
opt
' -fto '
options_
.
ms
.
output_file_tag
];
if
options_
.
ms
.
filtered_probabilities
opt
=
[
opt
' -filtered'
];
...
...
@@ -53,12 +54,12 @@ end
% compute probabilities
[
err
]
=
ms_sbvar_command_line
(
opt
);
mexErrCheck
(
'ms_
sbvar_command_line
probabilities'
,
err
);
mexErrCheck
(
'ms_
compute_
probabilities'
,
err
);
% now we want to plot the probabilities for each chain
if
ischar
(
prob_out_file
)
computed_probabilities
=
load
(
prob_out_file
);
plot_ms_probabilities
(
computed_probabilities
,
options_
,
M_
.
fname
);
plot_ms_probabilities
(
computed_probabilities
,
options_
);
end
options_
=
initialize_ms_sbvar_options
(
M_
,
options_
);
end
matlab/ms-sbvar/ms_estimation.m
View file @
0f001abb
...
...
@@ -31,18 +31,21 @@ function [options_, oo_]=ms_estimation(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Estimation'
);
% cleanup old files
clean_ms_init_files
(
options_
.
ms
.
output_file_tag
);
disp
(
'MS-SBVAR Estimation'
);
options_
=
set_file_tags
(
options_
);
clean_ms_estimation_files
(
options_
.
ms
.
output_file_tag
);
% general setup
ms_sbvar_setup
(
options_
);
if
~
isfield
(
options_
.
ms
,
'initialization_file_tag'
)
clean_ms_init_files
(
options_
.
ms
.
output_file_tag
);
ms_sbvar_setup
(
options_
);
end
options_
=
set_ms_init_file
(
options_
);
% setup command line options
opt
=
[
'-estimate -seed '
num2str
(
options_
.
DynareRandomStreams
.
seed
)];
opt
=
[
opt
' -ft '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -ft '
options_
.
ms
.
file_tag
];
opt
=
[
opt
' -fto '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -cb '
num2str
(
options_
.
ms
.
convergence_starting_value
)];
opt
=
[
opt
' -ce '
num2str
(
options_
.
ms
.
convergence_ending_value
)];
opt
=
[
opt
' -ci '
num2str
(
options_
.
ms
.
convergence_increment_value
)];
...
...
@@ -61,9 +64,11 @@ opt = [opt ' -random_tol_parms ' num2str(options_.ms.random_parameter_convergenc
% estimation
[
err
]
=
ms_sbvar_command_line
(
opt
);
mexErrCheck
(
'ms_
sbvar_command_line
estimation'
,
err
);
mexErrCheck
(
'ms_estimation'
,
err
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
oo_
=
set_oo_w_estimation_output
(
options_
,
oo_
);
[
options_
,
oo_
]
=
set_ms_estimation_file
(
options_
,
oo_
);
[
err
,
oo_
.
ms
.
A0
,
oo_
.
ms
.
Aplus
,
oo_
.
ms
.
Zeta
,
oo_
.
ms
.
Q
]
=
...
mex_ms_convert_free_parameters
(
options_
.
ms
.
estimation_file_tag
,
oo_
.
ms
.
maxparams
);
mexErrCheck
(
'mex_ms_convert_free_parameters'
,
err
);
options_
=
initialize_ms_sbvar_options
(
M_
,
options_
);
end
matlab/ms-sbvar/ms_forecast.m
View file @
0f001abb
function
[
options_
,
oo_
]
=
ms_forecast
(
M_
,
options_
,
oo_
)
%function ms_forecast()
%
calls ms irf mex function
%
MS-SBVAR Forecast
%
% INPUTS
% M_: (struct) model structure
...
...
@@ -31,12 +31,15 @@ function [options_, oo_]=ms_forecast(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Forecasts'
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
options_
=
set_ms_simulation_flags_for_other_mex
(
options_
);
oo_
=
set_oo_w_estimation_output
(
options_
,
oo_
);
disp
(
'MS-SBVAR Forecasts'
);
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_
,
'forecast'
)
forecastdir
=
[
options_
.
ms
.
output_file_tag
filesep
'Forecast'
];
create_dir
(
forecastdir
);
opt
=
{
options_
.
ms
.
output
_file_tag
,
...
opt
=
{
options_
.
ms
.
estimation
_file_tag
,
...
'seed'
,
options_
.
DynareRandomStreams
.
seed
,
...
'horizon'
,
options_
.
ms
.
horizon
,
...
'data'
,
options_
.
ms
.
forecast_data_obs
...
...
...
@@ -46,22 +49,22 @@ opt = {options_.ms.output_file_tag, ...
[
err
,
forecast
]
=
mex_ms_forecast
(
opt
{:},
'free_parameters'
,
oo_
.
ms
.
maxparams
,
'shocks_per_parameter'
,
options_
.
ms
.
shock_draws
);
mexErrCheck
(
'mex_ms_forecast ergodic '
,
err
);
plot_ms_forecast
(
M_
,
forecast
,
'Forecast'
,
options_
.
graph_save_formats
,
options_
.
TeX
);
plot_ms_forecast
(
M_
,
options_
,
forecast
,
'Forecast'
,
options_
.
graph_save_formats
,
options_
.
TeX
);
[
err
,
regime_forecast
]
=
mex_ms_forecast
(
opt
{:},
'free_parameters'
,
oo_
.
ms
.
maxparams
,
'shocks_per_parameter'
,
options_
.
ms
.
shock_draws
,
'regimes'
);
mexErrCheck
(
'mex_ms_forecast ergodic regimes'
,
err
);
save
([
M_
.
fname
'/'
options_
.
ms
.
output_file_tag
'
_
ergodic_forecast.mat'
],
'forecast'
,
'regime_forecast'
);
save
([
forecastdir
filesep
'ergodic_forecast.mat'
],
'forecast'
,
'regime_forecast'
);
if
exist
(
options_
.
ms
.
load_
mh_file
,
'file'
)
>
0
if
exist
(
options_
.
ms
.
mh_file
,
'file'
)
>
0
[
err
,
forecast
]
=
mex_ms_forecast
(
opt
{:},
'free_parameters'
,
oo_
.
ms
.
maxparams
,
'shocks_per_parameter'
,
options_
.
ms
.
shocks_per_parameter
,
...
'simulation_file'
,
options_
.
ms
.
load_
mh_file
,
'parameter_uncertainty'
);
'simulation_file'
,
options_
.
ms
.
mh_file
,
'parameter_uncertainty'
);
mexErrCheck
(
'mex_ms_forecast bayesian '
,
err
);
plot_ms_forecast
(
M_
,
forecast
,
'Forecast w/ Parameter Uncertainty'
,
options_
.
graph_save_formats
,
options_
.
TeX
);
plot_ms_forecast
(
M_
,
options_
,
forecast
,
'Forecast w/ Parameter Uncertainty'
,
options_
.
graph_save_formats
,
options_
.
TeX
);
[
err
,
regime_forecast
]
=
mex_ms_forecast
(
opt
{:},
'free_parameters'
,
oo_
.
ms
.
maxparams
,
'shocks_per_parameter'
,
options_
.
ms
.
shocks_per_parameter
,
...
'simulation_file'
,
options_
.
ms
.
load_
mh_file
,
'parameter_uncertainty'
,
'regimes'
);
'simulation_file'
,
options_
.
ms
.
mh_file
,
'parameter_uncertainty'
,
'regimes'
);
mexErrCheck
(
'mex_ms_forecast bayesian regimes '
,
err
);
save
([
M_
.
fname
'/'
options_
.
ms
.
output_file_tag
'
_
bayesian_forecast.mat'
],
'forecast'
,
'regime_forecast'
);
save
([
forecastdir
filesep
'bayesian_forecast.mat'
],
'forecast'
,
'regime_forecast'
);
end
options_
=
initialize_ms_sbvar_options
(
M_
,
options_
);
end
matlab/ms-sbvar/ms_irf.m
View file @
0f001abb
function
[
options_
,
oo_
]
=
ms_irf
(
varlist
,
M_
,
options_
,
oo_
)
%function ms_irf()
%
calls ms irf mex f
unction
%
MS-SBVAR Impulse Response F
unction
%
% INPUTS
% varlist: (chararray) list of selected endogenous variables
...
...
@@ -32,12 +32,15 @@ function [options_, oo_]=ms_irf(varlist,M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'IRFs'
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
options_
=
set_ms_simulation_flags_for_other_mex
(
options_
);
oo_
=
set_oo_w_estimation_output
(
options_
,
oo_
);
disp
(
'MS-SBVAR Impulse Response Function'
);
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_
,
'irf'
)
irfdir
=
[
options_
.
ms
.
output_file_tag
filesep
'IRF'
];
create_dir
(
irfdir
);
opt
=
{
options_
.
ms
.
output
_file_tag
,
...
opt
=
{
options_
.
ms
.
estimation
_file_tag
,
...
'seed'
,
options_
.
DynareRandomStreams
.
seed
,
...
'horizon'
,
options_
.
ms
.
horizon
,
...
'filtered'
,
options_
.
ms
.
filtered_probabilities
,
...
...
...
@@ -55,22 +58,22 @@ for i=1:size(regime_irfs,1)
plot_ms_irf
(
M_
,
options_
,
squeeze
(
regime_irfs
(
i
,:,:,:)),
options_
.
varobs
,[
'Ergodic '
...
'Impulse Responses State '
int2str
(
i
)],
varlist
);
end
save
([
M_
.
fname
'/'
options_
.
ms
.
output_file_tag
'
_
ergodic_irf.mat'
],
'irf'
,
'regime_irfs'
);
save
([
irfdir
filesep
'ergodic_irf.mat'
],
'irf'
,
'regime_irfs'
);
if
exist
(
options_
.
ms
.
load_
mh_file
,
'file'
)
>
0
if
exist
(
options_
.
ms
.
mh_file
,
'file'
)
>
0
[
err
,
irf
]
=
mex_ms_irf
(
opt
{:},
'shocks_per_parameter'
,
options_
.
ms
.
shocks_per_parameter
,
...
'parameter_uncertainty'
,
'simulation_file'
,
options_
.
ms
.
load_
mh_file
);
'parameter_uncertainty'
,
'simulation_file'
,
options_
.
ms
.
mh_file
);
mexErrCheck
(
'mex_ms_irf bayesian '
,
err
);
plot_ms_irf
(
M_
,
options_
,
irf
,
options_
.
varobs
,
'Impulse Responses with Parameter Uncertainty'
,
varlist
);
[
err
,
regime_irfs
]
=
mex_ms_irf
(
opt
{:},
'shocks_per_parameter'
,
options_
.
ms
.
shocks_per_parameter
,
...
'simulation_file'
,
options_
.
ms
.
load_
mh_file
,
'parameter_uncertainty'
,
'regimes'
);
'simulation_file'
,
options_
.
ms
.
mh_file
,
'parameter_uncertainty'
,
'regimes'
);
mexErrCheck
(
'mex_ms_irf bayesian regimes '
,
err
);
for
i
=
1
:
size
(
regime_irfs
,
1
)
plot_ms_irf
(
M_
,
options_
,
squeeze
(
regime_irfs
(
i
,:,:,:)),
options_
.
varobs
,[
'Impulse '
...
'Responses with Parameter Uncertainty State '
int2str
(
i
)],
varlist
);
end
save
([
M_
.
fname
'/'
options_
.
ms
.
output_file_tag
'
_
bayesian_irf.mat'
],
'irf'
,
'regime_irfs'
);
save
([
irfdir
filesep
'bayesian_irf.mat'
],
'irf'
,
'regime_irfs'
);
end
options_
=
initialize_ms_sbvar_options
(
M_
,
options_
);
end
matlab/ms-sbvar/ms_simulation.m
View file @
0f001abb
...
...
@@ -31,14 +31,15 @@ function [options_, oo_]=ms_simulation(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Simulation'
);
disp
(
'MS-SBVAR Simulation'
);
options_
=
set_file_tags
(
options_
);
clean_ms_simulation_files
(
options_
.
ms
.
output_file_tag
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
oo_
=
set_oo_w_estimation_output
(
options_
,
oo_
);
[
options_
,
oo_
]
=
set_ms_estimation_file
(
options_
,
oo_
);
% setup command line options
opt
=
[
'-simulate -seed '
num2str
(
options_
.
DynareRandomStreams
.
seed
)];
opt
=
[
opt
' -ft '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -ft '
options_
.
ms
.
estimation_file_tag
];
opt
=
[
opt
' -fto '
options_
.
ms
.
output_file_tag
];
opt
=
[
opt
' -ndraws '
num2str
(
options_
.
ms
.
mh_replic
)];
opt
=
[
opt
' -burnin '
num2str
(
options_
.
ms
.
drop
)];
opt
=
[
opt
' -thin '
num2str
(
options_
.
ms
.
thinning_factor
)];
...
...
@@ -46,8 +47,7 @@ opt = [opt ' -mh ' num2str(options_.ms.adaptive_mh_draws)];
% simulation
[
err
]
=
ms_sbvar_command_line
(
opt
);
mexErrCheck
(
'ms_
sbvar_command_line
simulat
e
'
,
err
);
mexErrCheck
(
'ms_simulat
ion
'
,
err
);
options_
.
ms
.
simulation_file_tag
=
options_
.
ms
.
output_file_tag
;
options_
=
initialize_ms_sbvar_options
(
M_
,
options_
);
end
matlab/ms-sbvar/ms_variance_decomposition.m
View file @
0f001abb
function
[
options_
,
oo_
]
=
ms_variance_decomposition
(
M_
,
options_
,
oo_
)
%function ms_variance_decomposition()
%
calls ms_v
ariance
_d
ecomposition
mex function
%
MS-SBVAR V
ariance
D
ecomposition
%
% INPUTS
% M_: (struct) model structure
...
...
@@ -31,14 +31,17 @@ function [options_, oo_]=ms_variance_decomposition(M_, options_, oo_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
disp
(
'Variance Decomposition'
);
options_
=
set_ms_estimation_flags_for_other_mex
(
options_
);
options_
=
set_ms_simulation_flags_for_other_mex
(
options_
);
oo_
=
set_oo_w_estimation_output
(
options_
,
oo_
);
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
);
% NOTICE THAT VARIANCE DECOMPOSITION DEFAULTS TO USING THE MEAN, NOT MEDIAN OR BANDED
opt
=
{
options_
.
ms
.
output
_file_tag
,
...
opt
=
{
options_
.
ms
.
estimation
_file_tag
,
...
'seed'
,
options_
.
DynareRandomStreams
.
seed
,
...
'horizon'
,
options_
.
ms
.
horizon
,
...
'filtered'
,
options_
.
ms
.
filtered_probabilities
,
...
...
...
@@ -49,19 +52,19 @@ opt = {options_.ms.output_file_tag, ...
[
err
,
vd
]
=
mex_ms_variance_decomposition
(
opt
{:},
'free_parameters'
,
oo_
.
ms
.
maxparams
,
'shocks'
,
options_
.
ms
.
shock_draws
);
mexErrCheck
(
'mex_ms_variance_decomposition ergodic '
,
err
);
plot_ms_