Save conditional forecast output in oo_. Closes: Dynare/dynare#1672
parent
f2205ed4a1
commit
b9af92eb8a
|
@ -7675,9 +7675,7 @@ the :comm:`bvar_forecast` command.
|
|||
|
||||
*Output*
|
||||
|
||||
The results are not stored in the ``oo_`` structure but in a
|
||||
separate structure ``forecasts``, described below, saved to the
|
||||
hard disk into a file called ``conditional_forecasts.mat.``
|
||||
The results are stored in ``oo_.conditional_forecast``, which is described below.
|
||||
|
||||
*Example*
|
||||
|
||||
|
@ -7702,7 +7700,7 @@ the :comm:`bvar_forecast` command.
|
|||
plot_conditional_forecast(periods = 10) a y;
|
||||
|
||||
|
||||
.. matvar:: forecasts.cond
|
||||
.. matvar:: oo_.conditional_forecast.cond
|
||||
|
||||
Variable set by the ``conditional_forecast`` command. It
|
||||
stores the conditional forecasts. Fields are ``periods+1`` by
|
||||
|
@ -7710,7 +7708,7 @@ the :comm:`bvar_forecast` command.
|
|||
subsequent ``periods`` forecasts periods. Fields are of the
|
||||
form::
|
||||
|
||||
forecasts.cond.FORECAST_MOMENT.VARIABLE_NAME
|
||||
oo_.conditional_forecast.cond.FORECAST_MOMENT.VARIABLE_NAME
|
||||
|
||||
where FORECAST_MOMENT is one of the following:
|
||||
|
||||
|
@ -7724,12 +7722,12 @@ the :comm:`bvar_forecast` command.
|
|||
distribution. The size corresponds to ``conf_sig``.
|
||||
|
||||
|
||||
.. matvar:: forecasts.uncond
|
||||
.. matvar:: oo_.conditional_forecast.uncond
|
||||
|
||||
Variable set by the ``conditional_forecast`` command. It stores
|
||||
the unconditional forecasts. Fields are of the form::
|
||||
|
||||
forecasts.uncond.FORECAST_MOMENT.VARIABLE_NAME
|
||||
oo_.conditional_forecast.uncond.FORECAST_MOMENT.VARIABLE_NAME
|
||||
|
||||
|
||||
.. matvar:: forecasts.instruments
|
||||
|
@ -7738,14 +7736,14 @@ the :comm:`bvar_forecast` command.
|
|||
the names of the exogenous instruments.
|
||||
|
||||
|
||||
.. matvar:: forecasts.controlled_variables
|
||||
.. matvar:: oo_.conditional_forecast.controlled_variables
|
||||
|
||||
Variable set by the ``conditional_forecast`` command. Stores
|
||||
the position of the constrained endogenous variables in
|
||||
declaration order.
|
||||
|
||||
|
||||
.. matvar:: forecasts.controlled_exo_variables
|
||||
.. matvar:: oo_.conditional_forecast.controlled_exo_variables
|
||||
|
||||
Variable set by the ``conditional_forecast`` command. Stores
|
||||
the values of the controlled exogenous variables underlying
|
||||
|
@ -7753,9 +7751,9 @@ the :comm:`bvar_forecast` command.
|
|||
endogenous variables. Fields are ``[number of constrained
|
||||
periods]`` by ``1`` vectors and are of the form::
|
||||
|
||||
forecasts.controlled_exo_variables.FORECAST_MOMENT.SHOCK_NAME
|
||||
oo_.conditional_forecast.controlled_exo_variables.FORECAST_MOMENT.SHOCK_NAME
|
||||
|
||||
.. matvar:: forecasts.graphs
|
||||
.. matvar:: oo_.conditional_forecast.graphs
|
||||
|
||||
Variable set by the ``conditional_forecast`` command. Stores
|
||||
the information for generating the conditional forecast plots.
|
||||
|
|
|
@ -25,10 +25,10 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
|
|||
% This routine has to be called after an estimation statement or an estimated_params block.
|
||||
%
|
||||
% REMARKS
|
||||
% [1] Results are stored in a structure which is saved in a mat file called conditional_forecasts.mat.
|
||||
% [1] Results are stored in oo_.conditional_forecast.
|
||||
% [2] Use the function plot_icforecast to plot the results.
|
||||
|
||||
% Copyright (C) 2006-2018 Dynare Team
|
||||
% Copyright (C) 2006-2019 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -310,5 +310,4 @@ forecasts.graph.fname = M_.fname;
|
|||
|
||||
%reset qz_criterium
|
||||
options_.qz_criterium=qz_criterium_old;
|
||||
|
||||
save('conditional_forecasts.mat','forecasts');
|
||||
oo_.conditional_forecast = forecasts;
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
function plot_icforecast(Variables,periods,options_)
|
||||
function plot_icforecast(Variables,periods,options_,oo_)
|
||||
% Build plots for the conditional forecasts.
|
||||
%
|
||||
% INPUTS
|
||||
% o Variables [cell] names of the endogenous variables to be plotted.
|
||||
% o Variables [cell] Names of the endogenous variables to be plotted.
|
||||
% o periods [int] Number of periods to be plotted.
|
||||
% o options_ [structure] Options.
|
||||
% o oo_ [structure] Storage of results.
|
||||
%
|
||||
% OUTPUTS
|
||||
% None.
|
||||
|
@ -10,7 +13,7 @@ function plot_icforecast(Variables,periods,options_)
|
|||
% SPECIAL REQUIREMENTS
|
||||
% This routine has to be called after imcforecast.m.
|
||||
|
||||
% Copyright (C) 2006-2018 Dynare Team
|
||||
% Copyright (C) 2006-2019 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -27,7 +30,11 @@ function plot_icforecast(Variables,periods,options_)
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
load conditional_forecasts;
|
||||
if ~isfield(oo_, 'conditional_forecast')
|
||||
error('Can''t find conditional forecasts');
|
||||
else
|
||||
forecasts = oo_.conditional_forecast;
|
||||
end
|
||||
|
||||
forecast_periods = length(forecasts.cond.Mean.(Variables{1}));
|
||||
if nargin==1 || isempty(periods) % Set default number of periods.
|
||||
|
|
|
@ -85,8 +85,8 @@ plot_conditional_forecast(periods=100) gy_obs gp_obs k;
|
|||
forecast(periods=100);
|
||||
|
||||
%compare unconditional forecasts
|
||||
cond_forecast=load('conditional_forecasts.mat');
|
||||
if max(abs(cond_forecast.forecasts.uncond.Mean.k(2:end)-oo_.forecast.Mean.k))>1e-8
|
||||
cond_forecast=oo_.conditional_forecast;
|
||||
if max(abs(cond_forecast.uncond.Mean.k(2:end)-oo_.forecast.Mean.k))>1e-8
|
||||
error('Unconditional Forecasts do not match')
|
||||
end
|
||||
|
||||
|
@ -94,11 +94,11 @@ end
|
|||
%conditions need to be set with histval;
|
||||
initial_condition_states = oo_.dr.ys;
|
||||
shock_matrix = zeros(options_cond_fcst_.periods ,M_.exo_nbr); %create shock matrix with found controlled shocks
|
||||
shock_matrix(1:5,strmatch('e_a',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_a; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_m',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_m; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_a',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_a; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_m',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_m; %set controlled shocks to their values
|
||||
|
||||
y_simult = simult_(M_,options_,initial_condition_states,oo_.dr,shock_matrix,1);
|
||||
|
||||
if max(abs(y_simult(strmatch('k',M_.endo_names,'exact'),:)'-cond_forecast.forecasts.cond.Mean.k))>1e-8
|
||||
if max(abs(y_simult(strmatch('k',M_.endo_names,'exact'),:)'-cond_forecast.cond.Mean.k))>1e-8
|
||||
error('Unconditional Forecasts do not match')
|
||||
end
|
||||
|
|
|
@ -86,8 +86,8 @@ plot_conditional_forecast(periods=100) gy_obs gp_obs k;
|
|||
forecast(periods=100);
|
||||
|
||||
%compare unconditional forecasts
|
||||
cond_forecast=load('conditional_forecasts.mat');
|
||||
if max(abs(cond_forecast.forecasts.uncond.Mean.k(2:end)-oo_.forecast.Mean.k))>1e-8
|
||||
cond_forecast=oo_.conditional_forecast;
|
||||
if max(abs(cond_forecast.uncond.Mean.k(2:end)-oo_.forecast.Mean.k))>1e-8
|
||||
error('Unconditional Forecasts do not match')
|
||||
end
|
||||
|
||||
|
@ -95,11 +95,11 @@ end
|
|||
initial_condition_states = oo_.dr.ys;
|
||||
initial_condition_states(strmatch('k',M_.endo_names,'exact')) = 6;
|
||||
shock_matrix = zeros(options_cond_fcst_.periods ,M_.exo_nbr); %create shock matrix with found controlled shocks
|
||||
shock_matrix(1:5,strmatch('e_a',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_a; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_m',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_m; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_a',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_a; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_m',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_m; %set controlled shocks to their values
|
||||
|
||||
y_simult = simult_(M_,options_,initial_condition_states,oo_.dr,shock_matrix,1);
|
||||
|
||||
if max(abs(y_simult(strmatch('k',M_.endo_names,'exact'),:)'-cond_forecast.forecasts.cond.Mean.k))>1e-8
|
||||
if max(abs(y_simult(strmatch('k',M_.endo_names,'exact'),:)'-cond_forecast.cond.Mean.k))>1e-8
|
||||
error('Unconditional Forecasts do not match')
|
||||
end
|
||||
|
|
|
@ -77,6 +77,5 @@ end;
|
|||
conditional_forecast(parameter_set=calibration, controlled_varexo=(u,e));
|
||||
|
||||
oo_exp=oo_;
|
||||
load('conditional_forecasts.mat')
|
||||
conditional_forecasts_exp=forecasts;
|
||||
conditional_forecasts_exp=oo_.conditional_forecast;
|
||||
save results_exp.mat oo_exp conditional_forecasts_exp
|
|
@ -85,8 +85,7 @@ end;
|
|||
conditional_forecast(parameter_set=calibration, controlled_varexo=(u,e));
|
||||
|
||||
oo_exp=oo_;
|
||||
load('conditional_forecasts.mat')
|
||||
conditional_forecasts_exp=forecasts;
|
||||
conditional_forecasts_exp=oo_.conditional_forecast;
|
||||
|
||||
oo_exp=oo_;
|
||||
save results_exp_histval.mat oo_exp conditional_forecasts_exp
|
||||
|
|
|
@ -118,7 +118,7 @@ if max(max(abs(struct2array(oo_.forecast.Mean)-struct2array(oo_exp.forecast.Mean
|
|||
error('Option loglinear wrong, forecast not equal')
|
||||
end
|
||||
|
||||
load('conditional_forecasts.mat')
|
||||
forecasts=oo_.conditional_forecast;
|
||||
|
||||
if max(max(abs(struct2array(forecasts.cond.Mean)-struct2array(conditional_forecasts_exp.cond.Mean))))>1e-10 || ...
|
||||
max(max(abs(struct2array(forecasts.cond.ci)-struct2array(conditional_forecasts_exp.cond.ci))))>1e-10 || ...
|
||||
|
|
|
@ -114,7 +114,7 @@ end;
|
|||
conditional_forecast(parameter_set=calibration, controlled_varexo=(u,e));
|
||||
|
||||
|
||||
load('conditional_forecasts.mat')
|
||||
forecasts=oo_.conditional_forecast;
|
||||
|
||||
if max(max(abs(struct2array(forecasts.cond.Mean)-struct2array(conditional_forecasts_exp.cond.Mean))))>1e-10 || ...
|
||||
max(max(abs(struct2array(forecasts.cond.ci)-struct2array(conditional_forecasts_exp.cond.ci))))>1e-10 || ...
|
||||
|
|
|
@ -12,8 +12,8 @@ conditional_forecast(periods=100,parameter_set=posterior_mode,replic=1000, contr
|
|||
plot_conditional_forecast(periods=100) Y_obs P_obs;
|
||||
|
||||
%compare unconditional forecasts
|
||||
cond_forecast=load('conditional_forecasts.mat');
|
||||
if max(abs(cond_forecast.forecasts.uncond.Mean.P_obs(2:end)-oo_.forecast.Mean.P_obs))>1e-8
|
||||
cond_forecast=oo_.conditional_forecast;
|
||||
if max(abs(cond_forecast.uncond.Mean.P_obs(2:end)-oo_.forecast.Mean.P_obs))>1e-8
|
||||
error('Unconditional Forecasts do not match')
|
||||
end
|
||||
|
||||
|
@ -24,16 +24,16 @@ initial_condition_states(strmatch('P_obs',M_.endo_names,'exact')) = oo_.Smoothed
|
|||
initial_condition_states(strmatch('junk1',M_.endo_names,'exact')) = oo_.SmoothedVariables.junk1(end);
|
||||
initial_condition_states(strmatch('junk2',M_.endo_names,'exact')) = oo_.SmoothedVariables.junk2(end)-oo_.Smoother.Trend.junk2(end);
|
||||
shock_matrix = zeros(options_cond_fcst_.periods ,M_.exo_nbr); %create shock matrix with found controlled shocks
|
||||
shock_matrix(1:5,strmatch('e_y',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_y; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_p',M_.exo_names,'exact')) = cond_forecast.forecasts.controlled_exo_variables.Mean.e_p; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_y',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_y; %set controlled shocks to their values
|
||||
shock_matrix(1:5,strmatch('e_p',M_.exo_names,'exact')) = cond_forecast.controlled_exo_variables.Mean.e_p; %set controlled shocks to their values
|
||||
|
||||
y_simult = simult_(M_,options_,initial_condition_states,oo_.dr,shock_matrix,1);
|
||||
|
||||
if max(abs(y_simult(strmatch('Y_obs',M_.endo_names,'exact'),:)'+(options_.first_obs-1+options_.nobs:options_.first_obs-1+options_.nobs+options_.forecast)'*g_y-cond_forecast.forecasts.cond.Mean.Y_obs))>1e-8
|
||||
if max(abs(y_simult(strmatch('Y_obs',M_.endo_names,'exact'),:)'+(options_.first_obs-1+options_.nobs:options_.first_obs-1+options_.nobs+options_.forecast)'*g_y-cond_forecast.cond.Mean.Y_obs))>1e-8
|
||||
error('Conditional Forecasts do not match')
|
||||
end
|
||||
|
||||
if max(abs(y_simult(strmatch('P_obs',M_.endo_names,'exact'),:)'+(options_.first_obs-1+options_.nobs:options_.first_obs-1+options_.nobs+options_.forecast)'*g_p-cond_forecast.forecasts.cond.Mean.P_obs))>1e-8
|
||||
if max(abs(y_simult(strmatch('P_obs',M_.endo_names,'exact'),:)'+(options_.first_obs-1+options_.nobs:options_.first_obs-1+options_.nobs+options_.forecast)'*g_p-cond_forecast.cond.Mean.P_obs))>1e-8
|
||||
error('Conditional Forecasts do not match')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue