New syntax used to call the conditional forecast using the extended path method. It allows to match the endogenous and the shock that are flipped.

time-shift
ferhat 2013-12-31 16:36:35 +01:00
parent bae79d62a4
commit dfbff7fc32
5 changed files with 1128 additions and 411 deletions

View File

@ -2404,10 +2404,6 @@ values (xx);
end;
@end example
In case of conditional forecasts using an extended path method,
the shock command is extended in order to determine the nature of the expectation
on the endogenous variable paths. The command @code{expectation} has, in this case,
to be added after the @code{values} command (@pxref{Forecasting}).
@customhead{In stochastic context}
@ -4210,7 +4206,7 @@ apply.
The following line:
@example
corr eps_1, eps_2, 0.5,  ,  , beta_pdf, 0, 0.3, -1, 1;
corr eps_1, eps_2, 0.5, , , beta_pdf, 0, 0.3, -1, 1;
@end example
sets a generalized beta prior for the correlation between @code{eps_1} and
@code{eps_2} with mean 0 and variance 0.3. By setting
@ -4222,7 +4218,7 @@ respectively. The initial value is set to 0.5.
Similarly, the following line:
@example
corr eps_1, eps_2, 0.5,  -0.5,  1, beta_pdf, 0, 0.3, -1, 1;
corr eps_1, eps_2, 0.5, -0.5, 1, beta_pdf, 0, 0.3, -1, 1;
@end example
sets the same generalized beta distribution as before, but now truncates
this distribution to [-0.5,1] through the use of @var{LOWER_BOUND} and
@ -5559,13 +5555,6 @@ DSGE model, by finding the structural shocks that are needed to match
the restricted paths. Use @code{conditional_forecast},
@code{conditional_forecast_paths} and @code{plot_conditional_forecast}
for that purpose.
If the model contains strong non-linearities, the conditional forecasts
can be computed using an extended path method with the @code{simulation_type}
option in @code{conditional_forecast} command set to @code{deterministic}.
Because in this case deterministic simulations are carried out,
the nature of the shocks (surprise or perfect foresight) has to be indicated
in the @code{conditional_forecast_paths} block, using the command @code{expectation}
for each endogenous path. The forecasts are plotted using the @code{rplot} command.
Finally, it is possible to do forecasting with a Bayesian VAR using
the @code{bvar_forecast} command.
@ -5726,10 +5715,7 @@ command has to be called after estimation.
Use @code{conditional_forecast_paths} block to give the list of
constrained endogenous, and their constrained future path.
If an extended path method is applied on the original dsge model,
the nature of the expectation on the constrained endogenous has to be
specified using expectation command. Option
@code{controlled_varexo} is used to specify the structural shocks
Option @code{controlled_varexo} is used to specify the structural shocks
which will be matched to generate the constrained path.
Use @code{plot_conditional_forecast} to graph the results.
@ -5756,14 +5742,6 @@ Number of simulations. Default: @code{5000}.
@item conf_sig = @var{DOUBLE}
Level of significance for confidence interval. Default: @code{0.80}
@item simulation_type = @code{stochastic} | @code{deterministic}
Indicates the nature of simulations used to compute the conditional forecast.
The default value @code{stochastic} is used, when simulations are computed
using the reduced form representation of the DSGE model.
If the model has to be simulated using extended path method on the original
DSGE model, @code{simulation_type} has to be set equal to @code{deterministic}.
@end table
@outputhead
@ -5833,31 +5811,6 @@ plot_conditional_forecast(periods = 10) a y;
@end example
@examplehead
@example
/* conditional forecast using extended path method
with perfect foresight on r path*/
var y r
varexo e u;
@dots{}
conditional_forecast_paths;
var y;
periods 1:3, 4:5;
values 2, 5;
var r
periods 1:5;
values 3;
expectation perfect_foresight;
end;
conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), simulation_type=deterministic);
rplot a;
rplot y;
@end example
@end deffn
@deffn Block conditional_forecast_paths ;
@ -5870,10 +5823,6 @@ example.
The syntax of the block is the same than the deterministic shocks in
the @code{shocks} blocks (@pxref{Shocks on exogenous variables}).
If the conditional forecast is carried out using the extended path method
on the original DSGE model, the nature of the expectation have to be specified
for each endogenous path, using the @code{expectation} = @code{surprise} | @code{perfect_foresight}.
By default, @code{expectation} is equal to @code{surprise}.
@end deffn
@ -5907,6 +5856,67 @@ See @file{bvar-a-la-sims.pdf}, which comes with Dynare distribution,
for more information on this command.
@end deffn
If the model contains strong non-linearities or if some perfectly expected shocks are considered, the forecasts and the conditional forecasts
can be computed using an extended path method. The forecast scenario describing the shocks and/or the constrained paths on some endogenous variables should be build.
The first step is the forecast scenario initialization using the function @code{init_plan}:
@anchor{init_plan}
@deffn {MATLAB/Octave command} HANDLE = init_plan(DATES) ;
Creates a new forecast scenario for a forecast period (indicated as a dates class, see @ref{dates class members}). This function return a handle on the new forecast scenario.
@end deffn
The forecast scenario can contain some simple shocks on the exogenous variables. This shocks are described using the function @code{basic_plan}:
@anchor{basic_plan}
@deffn {MATLAB/Octave command} HANDLE = basic_plan(HANDLE, 'VARIABLE_NAME', 'SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE | [DOUBLE | EXPRESSION [DOUBLE | | EXPRESSION] ] ) ;
Adds to the forecast scenario a shock on the exogenous variable indicated between quotes in the second argument. The shock type has to be specified in the third argument between quotes: 'surprise' in case of an unexpected shock or 'perfect_foresight' for a perfectly anticipated shock. The fourth argument indicates the period of the shock using a dates class (see @ref{dates class members}). The last argument is the shock path indicated as a Matlab vector of double. This function return the handle of the updated forecast scenario.
@end deffn
The forecast scenario can also contain a constrained path on an endogenous variable. The values of the related exogenous variable compatible with the constrained path are in this case computed. In other words, a conditional forecast is performed. This kind of shock is described with the function @code{flip_plan}:
@anchor{flip_plan}
@deffn {MATLAB/Octave command} HANDLE = flip_plan(HANDLE, 'VARIABLE_NAME, 'VARIABLE_NAME', 'SHOCK_TYPE', DATES, MATLAB VECTOR OF DOUBLE | [DOUBLE | EXPRESSION [DOUBLE | | EXPRESSION] ] ) ;
Adds to the forecast scenario a constrained path on the endogenous variable specified between quotes in the second argument. The associated exogenous variable provided in the third argument between quotes, is considered as an endogenous variable and its values compatible with the constrained path on the endogenous variable will be computed. The nature of the expectation on the constrained path has to be specified in the fourth argument between quotes: 'surprise' in case of an unexpected path or 'perfect_foresight' for a perfectly anticipated path. The fifth argument indicates the period where the path of the endogenous variable is constrained using a dates class (see @ref{dates class members}). The last argument contains the constrained path as a Matlab vector of double. This function return the handle of the updated forecast scenario.
@end deffn
Once the forecast scenario if fully described, the forecast is computed with the command @code{det_cond_forecast}:
@anchor{det_cond_forecast}
@deffn {MATLAB/Octave command} DSERIES = det_cond_forecast(HANDLE[, DSERIES [, DATES]]) ;
Computes the forecast or the conditional forecast using an extended path method for the given forecast scenario (first argument). The past values of the endogenous and exogenous variables provided with a dseries class (see @ref{dseries class members}) can be indicated in the second argument. By default, the past values of the variables are equal to their steady-state values. The initial date of the forecast can be provided in the third argument. By default, the forecast will start at the first date indicated in the @code{init_plan} command. This function returns a dset containing the historical and forecast values for the endogenous and exogenous variables.
@end deffn
@examplehead
@example
/* conditional forecast using extended path method
with perfect foresight on r path*/
var y r
varexo e u;
@dots{}
smoothed = dseries('smoothed_variables.csv');
fplan = init_plan(2013Q4:2029Q4);
fplan = flip_plan(fplan, 'y', 'u', 'surprise', 2013Q4:2014Q4, [1 1.1 1.2 1.1 ]);
fplan = flip_plan(fplan, 'r', 'e', 'perfect_foresight', 2013Q4:2014Q4, [2 1.9 1.9 1.9 ]);
dset_forecast = det_cond_forecast(fplan, smoothed);
plot(dset_forecast.{'y','u'});
plot(dset_forecast.{'r','e'});
@end example
@node Optimal policy
@section Optimal policy

82
matlab/basic_plan.m Normal file
View File

@ -0,0 +1,82 @@
function plan = basic_plan(plan, exogenous, expectation_type, date, value)
% Adds a simple shock to the forecast scenario plan
%
% INPUTS
% o plan [structure] A structure describing the different shocks and the implied variables, the date of the shocks and the path of the shock (forecast scenario).
% The plan structure is created by the functions init_plan, basic_plan and flip_plan
% o exogenous [string] A string containing the name of the exognous shock.
% o expectation_type [string] A string indicating the type of expectation: 'surprise' for an unexpected shock, and 'perfect_foresight' for a perfectly anticpated shock.
% o date [dates] The period of the shock
% o value [array of double] A vector of double containing the values of the exogenous variable
%
%
% OUTPUTS
% plan [structure] Returns a structure containing the updated forecast scenario.
%
%
% Copyright (C) 2013-2014 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 ~ischar(expectation_type) || size(expectation_type,1) ~= 1
error(['in basic_plan the third argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']);
end
exogenous = strtrim(exogenous);
ix = find(strcmp(exogenous, plan.exo_names));
if isempty(ix)
error(['in basic_plan the second argument ' exogenous ' is not an exogenous variable']);
end;
sdate = length(date);
if sdate > 1
if date(1) < plan.date(1) || date(end) > plan.date(end)
error(['in basic_plan the forth argument (date=' date ') must lay inside the plan.date ' plan.date]);
end
else
if date < plan.date(1) || date > plan.date(end)
error(['in basic_plan the forth argument (date=' date ') must lay iside the plan.date ' plan.date]);
end
end
if ~isempty(plan.options_cond_fcst_.controlled_varexo)
common_var = find(ix == plan.options_cond_fcst_.controlled_varexo);
if ~isempty(common_var)
common_date = intersect(date, plan.constrained_date_{common_var});
if ~isempty(common_date)
if common_date.length > 1
the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))];
else
the_dates = cell2mat(strings(common_date));
end
error(['Impossible case: ' plan.exo_names{plan.options_cond_fcst_.controlled_varexo(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{plan.constrained_vars_(common_var)} ' at the dates ' the_dates]);
end
end
end
if isempty(plan.shock_vars_)
plan.shock_vars_ = ix;
if strcmp(expectation_type, 'perfect_foresight')
plan.shock_perfect_foresight_ = 1;
else
plan.shock_perfect_foresight_ = 0;
end
else
plan.shock_vars_ = [plan.shock_vars_ ; ix];
if strcmp(expectation_type, 'perfect_foresight')
plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 1];
else
plan.shock_perfect_foresight_ = [plan.shock_perfect_foresight_ ; 0];
end
end
plan.shock_date_{length(plan.shock_date_) + 1} = date;
plan.shock_paths_{length(plan.shock_paths_) + 1} = value;

File diff suppressed because it is too large Load Diff

89
matlab/flip_plan.m Normal file
View File

@ -0,0 +1,89 @@
function plan = flip_plan(plan, exogenous, endogenous, expectation_type, date, value)
% Adds to the forecast scenario a conditional forecast shock (the path of an endogenous variable is constrained and the values compatible values of the related exogenous variable will be compued)
%
% INPUTS
% o plan [structure] A structure describing the different shocks and the implied variables, the date of the shocks and the path of the shock (forecast scenario).
% The plan structure is created by the functions init_plan, basic_plan and flip_plan
% o exogenous [string] A string containing the name of the endogenous variable with a constrained path.
% o endogenous [string] A string containing the name of the exogenous. This exogenous variable will be en endogenous variable when the conditional forecast will be perform.
% o expectation_type [string] A string indicating the type of expectation: 'surprise' for an unexpected shock, and 'perfect_foresight' for a perfectly anticpated shock.
% o date [dates] The period of the shock
% o value [array of double] A vector of double containing the constrined path on the endogenous variable
%
%
% OUTPUTS
% plan [structure] Returns a structure containing the updated forecast scenario.
%
%
% Copyright (C) 2013-2014 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 ~ischar(expectation_type) || size(expectation_type,1) ~= 1
error(['in flip_plan the fourth argument should be a string containing the simulation type (''perfect_foresight'' or ''surprise'')']);
end
exogenous = strtrim(exogenous);
ix = find(strcmp(exogenous, plan.endo_names));
if isempty(ix)
error(['in flip_plan the second argument ' exogenous ' is not an endogenous variable']);
end;
endogenous = strtrim(endogenous);
iy = find(strcmp(endogenous, plan.exo_names));
if isempty(iy)
error(['in flip_plan the third argument ' endogenous ' is not an exogenous variable']);
end;
sdate = length(date);
if sdate > 1
if date(1) < plan.date(1) || date(end) > plan.date(end)
error(['in flip_plan the fifth argument (date=' date ') must lay inside the plan.date ' plan.date]);
end
else
if date < plan.date(1) || date > plan.date(end)
error(['in flip_plan the fifth argument (date=' date ') must lay iside the plan.date ' plan.date]);
end
end
if ~isempty(plan.shock_vars_)
common_var = find(iy == plan.shock_vars_);
if ~isempty(common_var)
common_date = intersect(date, plan.shock_date_{common_var});
if ~isempty(common_date)
if common_date.length > 1
the_dates = [cell2mat(strings(common_date(1))) ':' cell2mat(strings(common_date(end)))];
else
the_dates = cell2mat(strings(common_date));
end
error(['Impossible case: ' plan.exo_names{plan.shock_vars_(common_var)} ' is used both as a shock and as an endogenous variable to control the path of ' plan.endo_names{ix} ' at the dates ' the_dates]);
end
end
end
if isempty(plan.constrained_vars_)
plan.constrained_vars_ = ix;
plan.options_cond_fcst_.controlled_varexo = iy;
if strcmp(expectation_type, 'perfect_foresight')
plan.constrained_perfect_foresight_ = 1;
else
plan.constrained_perfect_foresight_ = 0;
end
else
plan.constrained_vars_ = [plan.constrained_vars_ ; ix];
plan.options_cond_fcst_.controlled_varexo = [plan.options_cond_fcst_.controlled_varexo ; iy];
if strcmp(expectation_type, 'perfect_foresight')
plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 1];
else
plan.constrained_perfect_foresight_ = [plan.constrained_perfect_foresight_ ; 0];
end
end
plan.constrained_date_{length(plan.constrained_date_) + 1} = date;
plan.constrained_paths_{length(plan.constrained_paths_) + 1} = value;

47
matlab/init_plan.m Normal file
View File

@ -0,0 +1,47 @@
function plan = init_plan(date)
% Creates and initializes a new forecast scenario
%
% INPUTS
% o date [dates] The period of the forecast
%
%
% OUTPUTS
% plan [structure] Returns a structure containing a new forecast scenario
%
%
% Copyright (C) 2013-2014 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/>.
global M_
plan = struct();
plan.date = date;
endo_names_length = size(M_.endo_names,2);
plan.endo_names = deblank(mat2cell(M_.endo_names(1:M_.orig_endo_nbr,:),ones(1,M_.orig_endo_nbr),endo_names_length));
exo_names_length = size(M_.exo_names,2);
plan.exo_names = deblank(mat2cell(M_.exo_names(1:M_.exo_nbr,:),ones(1,M_.exo_nbr),exo_names_length));
plan.constrained_vars_ = [];
plan.constrained_paths_ = [];
plan.constrained_date_ = [];
plan.constrained_perfect_foresight_ = [];
plan.shock_vars_ = [];
plan.shock_paths_ = [];
plan.shock_date_ = [];
plan.shock_perfect_foresight_ = [];
plan.options_cond_fcst_ = struct();
plan.options_cond_fcst_.parameter_set = 'calibration';
plan.options_cond_fcst_.simulation_type = 'deterministic';
plan.options_cond_fcst_.controlled_varexo = [];