2015-08-07 16:57:28 +02:00
|
|
|
function oo_=disp_moments(y,var_list,M_,options_,oo_)
|
|
|
|
% function disp_moments(y,var_list,M_,options_,oo_)
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
% Displays moments of simulated variables
|
2015-08-07 16:57:28 +02:00
|
|
|
% INPUTS
|
|
|
|
% y [double] nvar*nperiods vector of simulated variables.
|
|
|
|
% var_list [char] nvar character array with names of variables.
|
|
|
|
% M_ [structure] Dynare's model structure
|
|
|
|
% oo_ [structure] Dynare's results structure
|
|
|
|
% options_ [structure] Dynare's options structure
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2015-08-07 16:57:28 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% oo_ [structure] Dynare's results structure,
|
2008-08-01 20:53:30 +02:00
|
|
|
|
2020-04-07 12:24:16 +02:00
|
|
|
% Copyright (C) 2001-2020 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
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
warning_old_state = warning;
|
|
|
|
warning off
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
if isempty(var_list)
|
|
|
|
var_list = M_.endo_names(1:M_.orig_endo_nbr);
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
nvar = length(var_list);
|
2009-12-16 18:17:34 +01:00
|
|
|
ivar=zeros(nvar,1);
|
|
|
|
for i=1:nvar
|
2017-10-10 10:05:59 +02:00
|
|
|
i_tmp = strmatch(var_list{i}, M_.endo_names, 'exact');
|
2009-12-16 18:17:34 +01:00
|
|
|
if isempty(i_tmp)
|
2020-06-08 17:54:58 +02:00
|
|
|
error('The variable %s specified is not an endogenous variable',var_list{i});
|
2009-12-16 18:17:34 +01:00
|
|
|
else
|
2010-01-05 11:46:10 +01:00
|
|
|
ivar(i) = i_tmp;
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2011-01-02 16:54:08 +01:00
|
|
|
y = y(ivar,options_.drop+1:end)';
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
|
2017-09-09 08:42:08 +02:00
|
|
|
ME_present=0;
|
|
|
|
if ~all(M_.H==0)
|
2020-04-07 12:24:16 +02:00
|
|
|
if isoctave
|
2019-02-15 16:31:24 +01:00
|
|
|
[observable_pos_requested_vars, index_subset, index_observables] = intersect_stable(ivar, options_.varobs_id);
|
|
|
|
else
|
|
|
|
[observable_pos_requested_vars, index_subset, index_observables] = intersect(ivar, options_.varobs_id, 'stable');
|
|
|
|
end
|
2017-09-09 08:42:08 +02:00
|
|
|
if ~isempty(observable_pos_requested_vars)
|
|
|
|
ME_present=1;
|
|
|
|
i_ME = setdiff([1:size(M_.H,1)],find(diag(M_.H) == 0)); % find ME with 0 variance
|
|
|
|
chol_S = chol(M_.H(i_ME,i_ME)); %decompose rest
|
|
|
|
shock_mat=zeros(options_.periods,size(M_.H,1)); %initialize
|
|
|
|
shock_mat(:,i_ME)=randn(length(i_ME),options_.periods)'*chol_S;
|
2019-12-20 16:28:06 +01:00
|
|
|
y_ME = y(:,index_subset)+shock_mat(options_.drop+1:end,index_observables);
|
|
|
|
y_ME_only = shock_mat(options_.drop+1:end,index_observables);
|
2017-09-09 08:42:08 +02:00
|
|
|
m_ME = mean(y_ME);
|
|
|
|
y_ME=get_filtered_time_series(y_ME,m_ME,options_);
|
|
|
|
y_ME_only_filtered=get_filtered_time_series(y_ME_only,mean(y_ME_only),options_);
|
|
|
|
s2_ME = mean(y_ME.*y_ME);
|
2020-06-25 09:41:39 +02:00
|
|
|
s_ME = sqrt(s2_ME);
|
|
|
|
zero_variance_ME_var_index=index_subset(abs(s_ME')<options_.zero_moments_tolerance);
|
2017-09-09 08:42:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
m = mean(y);
|
2010-02-10 14:20:28 +01:00
|
|
|
|
2015-08-10 17:05:56 +02:00
|
|
|
% filter series
|
|
|
|
y=get_filtered_time_series(y,m,options_);
|
2010-02-10 14:20:28 +01:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
s2 = mean(y.*y);
|
|
|
|
s = sqrt(s2);
|
|
|
|
oo_.mean = transpose(m);
|
|
|
|
oo_.var = y'*y/size(y,1);
|
2017-05-16 15:10:20 +02:00
|
|
|
oo_.skewness = (mean(y.^3)./s2.^1.5)';
|
2016-04-06 09:23:54 +02:00
|
|
|
oo_.kurtosis = (mean(y.^4)./(s2.*s2)-3)';
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2020-06-25 09:41:39 +02:00
|
|
|
zero_variance_var_index=find(abs(s)<options_.zero_moments_tolerance);
|
|
|
|
oo_.skewness(zero_variance_var_index)=NaN;
|
|
|
|
oo_.kurtosis(zero_variance_var_index)=NaN;
|
|
|
|
s(zero_variance_var_index)=0;
|
|
|
|
s2(zero_variance_var_index)=0;
|
|
|
|
oo_.var(zero_variance_var_index,:)=0;
|
|
|
|
oo_.var(:,zero_variance_var_index)=0;
|
|
|
|
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
labels = M_.endo_names(ivar);
|
|
|
|
labels_TeX = M_.endo_names_tex(ivar);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
2019-03-19 14:26:16 +01:00
|
|
|
if ~options_.nomoments
|
2020-06-25 09:41:39 +02:00
|
|
|
z = [ m' s' s2' oo_.skewness oo_.kurtosis ];
|
2005-02-18 20:54:39 +01:00
|
|
|
title='MOMENTS OF SIMULATED VARIABLES';
|
2017-10-10 10:05:59 +02:00
|
|
|
title=add_filter_subtitle(title, options_);
|
|
|
|
headers = {'VARIABLE'; 'MEAN'; 'STD. DEV.'; 'VARIANCE'; 'SKEWNESS'; 'KURTOSIS'};
|
|
|
|
dyntable(options_, title, headers, labels, z, cellofchararraymaxlength(labels)+2, 16, 6);
|
2015-08-17 13:12:22 +02:00
|
|
|
if options_.TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
dyn_latex_table(M_, options_, title, 'sim_moments', headers, labels_TeX, z, cellofchararraymaxlength(labels)+2, 16, 6);
|
2015-08-17 13:12:22 +02:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2019-03-19 14:26:16 +01:00
|
|
|
if ~options_.nocorr
|
2005-02-18 20:54:39 +01:00
|
|
|
corr = (y'*y/size(y,1))./(s'*s);
|
2020-06-25 09:41:39 +02:00
|
|
|
corr(zero_variance_var_index,:)=NaN;
|
|
|
|
corr(:,zero_variance_var_index)=NaN;
|
2017-05-16 15:10:20 +02:00
|
|
|
if options_.contemporaneous_correlation
|
2015-08-10 21:36:48 +02:00
|
|
|
oo_.contemporaneous_correlation = corr;
|
|
|
|
end
|
2019-03-19 14:26:16 +01:00
|
|
|
if ~options_.noprint
|
2011-07-26 13:51:00 +02:00
|
|
|
title = 'CORRELATION OF SIMULATED VARIABLES';
|
2015-08-10 17:43:58 +02:00
|
|
|
title=add_filter_subtitle(title,options_);
|
2017-10-10 10:05:59 +02:00
|
|
|
headers = vertcat('VARIABLE', M_.endo_names(ivar));
|
|
|
|
dyntable(options_, title, headers, labels, corr, cellofchararraymaxlength(labels)+2, 8, 4);
|
2015-08-17 13:12:22 +02:00
|
|
|
if options_.TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
headers = vertcat('VARIABLE', M_.endo_names_tex(ivar));
|
|
|
|
lh = cellofchararraymaxlength(labels)+2;
|
|
|
|
dyn_latex_table(M_, options_, title, 'sim_corr_matrix', headers, labels_TeX, corr, lh, 8,4);
|
2015-08-17 13:12:22 +02:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2019-03-19 14:26:16 +01:00
|
|
|
if ~options_.noprint && length(options_.conditional_variance_decomposition)
|
2017-05-16 15:10:20 +02:00
|
|
|
fprintf('\nSTOCH_SIMUL: conditional_variance_decomposition requires theoretical moments, i.e. periods=0.\n')
|
2014-04-07 11:29:05 +02:00
|
|
|
end
|
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
ar = options_.ar;
|
|
|
|
if ar > 0
|
2005-02-18 20:54:39 +01:00
|
|
|
autocorr = [];
|
|
|
|
for i=1:ar
|
2011-01-12 11:23:44 +01:00
|
|
|
oo_.autocorr{i} = y(ar+1:end,:)'*y(ar+1-i:end-i,:)./((size(y,1)-ar)*std(y(ar+1:end,:))'*std(y(ar+1-i:end-i,:)));
|
2020-06-25 09:41:39 +02:00
|
|
|
oo_.autocorr{i}(zero_variance_var_index,:)=NaN;
|
|
|
|
oo_.autocorr{i}(:,zero_variance_var_index)=NaN;
|
2009-12-16 18:17:34 +01:00
|
|
|
autocorr = [ autocorr diag(oo_.autocorr{i}) ];
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2019-03-19 14:26:16 +01:00
|
|
|
if ~options_.noprint
|
2011-07-26 13:51:00 +02:00
|
|
|
title = 'AUTOCORRELATION OF SIMULATED VARIABLES';
|
2015-08-10 17:43:58 +02:00
|
|
|
title=add_filter_subtitle(title,options_);
|
2017-10-10 10:05:59 +02:00
|
|
|
headers = vertcat('VARIABLE', cellstr(int2str([1:ar]')));
|
|
|
|
dyntable(options_, title, headers, labels, autocorr, cellofchararraymaxlength(labels)+2, 8, 4);
|
2015-08-17 13:12:22 +02:00
|
|
|
if options_.TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
headers = vertcat('VARIABLE', cellstr(int2str([1:ar]')));
|
|
|
|
lh = cellofchararraymaxlength(labels)+2;
|
|
|
|
dyn_latex_table(M_, options_, title, 'sim_autocorr_matrix', headers, labels_TeX, autocorr, cellofchararraymaxlength(labels_TeX)+2, 8, 4);
|
2015-08-17 13:12:22 +02:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
end
|
|
|
|
|
2015-08-10 17:05:56 +02:00
|
|
|
|
|
|
|
if ~options_.nodecomposition
|
|
|
|
if M_.exo_nbr == 1
|
|
|
|
oo_.variance_decomposition = 100*ones(nvar,1);
|
|
|
|
else
|
|
|
|
oo_.variance_decomposition=zeros(nvar,M_.exo_nbr);
|
|
|
|
%get starting values
|
|
|
|
if isempty(M_.endo_histval)
|
|
|
|
y0 = oo_.dr.ys;
|
|
|
|
else
|
2017-02-14 12:54:22 +01:00
|
|
|
if options_.loglinear
|
|
|
|
y0 = log_variable(1:M_.endo_nbr,M_.endo_histval,M_);
|
|
|
|
else
|
|
|
|
y0 = M_.endo_histval;
|
|
|
|
end
|
2015-08-10 17:05:56 +02:00
|
|
|
end
|
|
|
|
%back out shock matrix used for generating y
|
|
|
|
i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0)); % find shocks with 0 variance
|
|
|
|
chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var)); %decompose rest
|
|
|
|
shock_mat=zeros(options_.periods,M_.exo_nbr); %initialize
|
|
|
|
shock_mat(:,i_exo_var)=oo_.exo_simul(:,i_exo_var)/chol_S; %invert construction of oo_.exo_simul from simult.m
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2015-08-10 17:05:56 +02:00
|
|
|
for shock_iter=1:length(i_exo_var)
|
|
|
|
temp_shock_mat=zeros(size(shock_mat));
|
|
|
|
temp_shock_mat(:,i_exo_var(shock_iter))=shock_mat(:,i_exo_var(shock_iter));
|
|
|
|
temp_shock_mat(:,i_exo_var) = temp_shock_mat(:,i_exo_var)*chol_S;
|
2019-09-10 17:02:20 +02:00
|
|
|
y_sim_one_shock = simult_(M_,options_,y0,oo_.dr,temp_shock_mat,options_.order);
|
2015-08-10 17:05:56 +02:00
|
|
|
y_sim_one_shock=y_sim_one_shock(ivar,1+options_.drop+1:end)';
|
|
|
|
y_sim_one_shock=get_filtered_time_series(y_sim_one_shock,mean(y_sim_one_shock),options_);
|
2020-06-25 09:41:39 +02:00
|
|
|
oo_.variance_decomposition(:,i_exo_var(shock_iter))=var(y_sim_one_shock)./s2*100;
|
2015-08-10 17:05:56 +02:00
|
|
|
end
|
2020-06-25 09:41:39 +02:00
|
|
|
oo_.variance_decomposition(zero_variance_var_index,:)=NaN;
|
2017-09-09 08:42:08 +02:00
|
|
|
if ME_present
|
|
|
|
oo_.variance_decomposition_ME=oo_.variance_decomposition(index_subset,:)...
|
|
|
|
.*repmat((s2(index_subset)./s2_ME)',1,length(i_exo_var));
|
|
|
|
oo_.variance_decomposition_ME(:,end+1)=var(y_ME_only_filtered)./s2_ME*100;
|
2020-06-25 09:41:39 +02:00
|
|
|
oo_.variance_decomposition_ME(ismember(observable_pos_requested_vars,intersect(zero_variance_ME_var_index,zero_variance_var_index)),:)=NaN;
|
|
|
|
oo_.variance_decomposition_ME(ismember(observable_pos_requested_vars,setdiff(zero_variance_var_index,zero_variance_ME_var_index)),1:end-1)=0;
|
|
|
|
oo_.variance_decomposition_ME(ismember(observable_pos_requested_vars,setdiff(zero_variance_var_index,zero_variance_ME_var_index)),end)=1;
|
2019-12-20 16:28:06 +01:00
|
|
|
end
|
2015-08-10 17:05:56 +02:00
|
|
|
if ~options_.noprint %options_.nomoments == 0
|
|
|
|
skipline()
|
|
|
|
title='VARIANCE DECOMPOSITION SIMULATING ONE SHOCK AT A TIME (in percent)';
|
2015-08-10 17:43:58 +02:00
|
|
|
title=add_filter_subtitle(title,options_);
|
2015-08-10 17:05:56 +02:00
|
|
|
headers = M_.exo_names;
|
2017-10-10 10:05:59 +02:00
|
|
|
headers(M_.exo_names_orig_ord) = headers;
|
|
|
|
headers = vertcat(' ', headers);
|
|
|
|
lh = cellofchararraymaxlength(M_.endo_names(ivar))+2;
|
|
|
|
dyntable(options_, title, vertcat(headers, 'Tot. lin. contr.'), ...
|
|
|
|
M_.endo_names(ivar), [oo_.variance_decomposition sum(oo_.variance_decomposition,2)], lh, 8, 2);
|
2017-09-09 08:42:08 +02:00
|
|
|
if ME_present
|
2017-10-10 10:05:59 +02:00
|
|
|
headers_ME = vertcat(headers, 'ME');
|
|
|
|
dyntable(options_, [title,' WITH MEASUREMENT ERROR'], vertcat(headers_ME, 'Tot. lin. contr.'), M_.endo_names(ivar(index_subset)), ...
|
|
|
|
[oo_.variance_decomposition_ME sum(oo_.variance_decomposition_ME, 2)], lh, 8, 2);
|
2017-09-09 08:42:08 +02:00
|
|
|
end
|
2015-08-17 13:12:22 +02:00
|
|
|
if options_.TeX
|
2017-10-10 10:05:59 +02:00
|
|
|
headers = M_.exo_names_tex;
|
|
|
|
headers = vertcat(' ', headers);
|
|
|
|
labels = M_.endo_names_tex(ivar);
|
|
|
|
lh = cellofchararraymaxlength(labels)+2;
|
|
|
|
dyn_latex_table(M_, options_, title, 'sim_var_decomp', vertcat(headers, 'Tot. lin. contr.'), ...
|
|
|
|
labels_TeX, [oo_.variance_decomposition sum(oo_.variance_decomposition, 2)], lh, 8, 2);
|
2017-09-09 08:42:08 +02:00
|
|
|
if ME_present
|
2017-10-10 10:05:59 +02:00
|
|
|
headers_ME = vertcat(headers, 'ME');
|
|
|
|
dyn_latex_table(M_, options_, [title, ' WITH MEASUREMENT ERROR'], 'sim_var_decomp_ME', ...
|
2019-12-20 16:28:06 +01:00
|
|
|
vertcat(headers_ME, 'Tot. lin. contr.'), ...
|
|
|
|
labels_TeX(ivar(index_subset)), ...
|
|
|
|
[oo_.variance_decomposition_ME sum(oo_.variance_decomposition_ME, 2)], lh, 8, 2);
|
2017-09-09 08:42:08 +02:00
|
|
|
end
|
2015-08-17 13:12:22 +02:00
|
|
|
end
|
|
|
|
|
2015-08-10 17:05:56 +02:00
|
|
|
if options_.order == 1
|
|
|
|
fprintf('Note: numbers do not add up to 100 due to non-zero correlation of simulated shocks in small samples\n\n')
|
|
|
|
else
|
|
|
|
fprintf('Note: numbers do not add up to 100 due to i) non-zero correlation of simulated shocks in small samples and ii) nonlinearity\n\n')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2009-12-16 18:17:34 +01:00
|
|
|
warning(warning_old_state);
|
2015-08-10 17:05:56 +02:00
|
|
|
end
|
|
|
|
|
2017-10-10 10:05:59 +02:00
|
|
|
function y = get_filtered_time_series(y, m, options_)
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2015-08-10 17:43:58 +02:00
|
|
|
if options_.hp_filter && ~options_.one_sided_hp_filter && ~options_.bandpass.indicator
|
2015-08-10 17:05:56 +02:00
|
|
|
[hptrend,y] = sample_hp_filter(y,options_.hp_filter);
|
|
|
|
elseif ~options_.hp_filter && options_.one_sided_hp_filter && ~options_.bandpass.indicator
|
2015-10-13 20:20:33 +02:00
|
|
|
[hptrend,y] = one_sided_hp_filter(y,options_.one_sided_hp_filter);
|
2015-08-10 17:05:56 +02:00
|
|
|
elseif ~options_.hp_filter && ~options_.one_sided_hp_filter && options_.bandpass.indicator
|
|
|
|
data_temp=dseries(y,'0q1');
|
2016-04-15 09:23:35 +02:00
|
|
|
data_temp=baxter_king_filter(data_temp,options_.bandpass.passband(1),options_.bandpass.passband(2),options_.bandpass.K);
|
2015-08-10 17:05:56 +02:00
|
|
|
y=data_temp.data;
|
|
|
|
elseif ~options_.hp_filter && ~options_.one_sided_hp_filter && ~options_.bandpass.indicator
|
|
|
|
y = bsxfun(@minus, y, m);
|
2017-05-16 15:10:20 +02:00
|
|
|
else
|
2015-08-10 17:05:56 +02:00
|
|
|
error('disp_moments:: You cannot use more than one filter at the same time')
|
|
|
|
end
|
2017-05-16 15:10:20 +02:00
|
|
|
|
2019-03-19 14:26:16 +01:00
|
|
|
end
|