Skip to content
Snippets Groups Projects
Commit ac93cd08 authored by MichelJuillard's avatar MichelJuillard
Browse files

added possibility to do conditional forecast with a calibrated model + bug...

added possibility to do conditional forecast with a calibrated model + bug correction + new test file
parent 5cd7ef32
No related branches found
No related tags found
No related merge requests found
......@@ -4322,7 +4322,7 @@ Use @code{plot_conditional_forecast} to graph the results.
@table @code
@item parameter_set = @code{prior_mode} | @code{prior_mean} | @code{posterior_mode} | @code{posterior_mean} | @code{posterior_median}
@item parameter_set = @code{calibration} | @code{prior_mode} | @code{prior_mean} | @code{posterior_mode} | @code{posterior_mean} | @code{posterior_median}
Specify the parameter set to use for the forecasting. No default
value, mandatory option.
......@@ -4362,7 +4362,7 @@ end;
conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), replic = 3000);
plot_conditional_forecast(periods = 10) e u;
plot_conditional_forecast(periods = 10) a y;
@end example
@end deffn
......
......@@ -45,10 +45,29 @@ function imcforecast(constrained_paths, constrained_vars, options_cond_fcst)
global options_ oo_ M_ bayestopt_
if isfield(options_cond_fcst,'parameter_set') || isempty(options_cond_fcst.parameter_set)
if ~isfield(options_cond_fcst,'parameter_set') || isempty(options_cond_fcst.parameter_set)
options_cond_fcst.parameter_set = 'posterior_mode';
end
if ~isfield(options_cond_fcst,'replic') || isempty(options_cond_fcst.replic)
options_cond_fcst.replic = 5000;
end
if ~isfield(options_cond_fcst,'periods') || isempty(options_cond_fcst.periods)
options_cond_fcst.periods = 40;
end
if ~isfield(options_cond_fcst,'conf_sig') || isempty(options_cond_fcst.conf_sig)
options_cond_fcst.conf_sig = .8;
end
if isequal(options_cond_fcst.parameter_set,'calibration')
estimated_model = 0;
else
estimated_model = 1;
end
if estimated_model
if ischar(options_cond_fcst.parameter_set)
switch options_cond_fcst.parameter_set
case 'posterior_mode'
......@@ -62,7 +81,8 @@ if ischar(options_cond_fcst.parameter_set)
case 'prior_mean'
xparam = bayestopt_.p1;
otherwise
disp('eval_likelihood:: If the input argument is a string, then it has to be equal to:')
disp('imcforecast:: If the input argument is a string, then it has to be equal to:')
disp(' ''calibration'', ')
disp(' ''posterior_mode'', ')
disp(' ''posterior_mean'', ')
disp(' ''posterior_median'', ')
......@@ -77,18 +97,6 @@ else
end
end
if ~isfield(options_cond_fcst,'replic') || isempty(options_cond_fcst.replic)
options_cond_fcst.replic = 5000;
end
if ~isfield(options_cond_fcst,'periods') || isempty(options_cond_fcst.periods)
options_cond_fcst.periods = 40;
end
if ~isfield(options_cond_fcst,'conf_sig') || isempty(options_cond_fcst.conf_sig)
options_cond_fcst.conf_sig = .8;
end
set_parameters(xparam);
n_varobs = size(options_.varobs,1);
......@@ -139,6 +147,14 @@ end
trend = trend(oo_.dr.order_var,:);
InitState(:,1) = atT(:,end);
else
InitState(:,1) = zeros(M_.endo_nbr,1);
trend = repmat(oo_.steady_state(oo_.dr.order_var),1,options_cond_fcst.periods+1);
end
if isempty(options_.qz_criterium)
options_.qz_criterium = 1+1e-6;
end
[T,R,ys,info] = dynare_resolve;
sQ = sqrt(M_.Sigma_e);
......@@ -146,9 +162,7 @@ sQ = sqrt(M_.Sigma_e);
NumberOfStates = length(InitState);
FORCS1 = zeros(NumberOfStates,options_cond_fcst.periods+1,options_cond_fcst.replic);
for b=1:options_cond_fcst.replic
FORCS1(:,1,b) = InitState;
end
FORCS1(:,1,:) = repmat(InitState,1,options_cond_fcst.replic);
EndoSize = M_.endo_nbr;
ExoSize = M_.exo_nbr;
......@@ -164,7 +178,7 @@ idx = [];
jdx = [];
for i = 1:n1
idx = [idx ; oo_.dr.inv_order_var(strmatch(deblank(constrained_vars(i,:)),M_.endo_names,'exact'))];
idx = [idx ; oo_.dr.inv_order_var(constrained_vars(i,:))];
jdx = [jdx ; strmatch(deblank(options_cond_fcst.controlled_varexo(i,:)),M_.exo_names,'exact')];
end
mv = zeros(n1,NumberOfStates);
......@@ -182,7 +196,7 @@ end
constrained_paths = bsxfun(@minus,constrained_paths,trend(idx,1:cL));
randn('state',0);
%randn('state',0);
for b=1:options_cond_fcst.replic
shocks = sQ*randn(ExoSize,options_cond_fcst.periods);
......
......@@ -94,7 +94,7 @@ class ParsingDriver;
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
%token BVAR_REPLIC BYTECODE
%token CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE CALIBRATION
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER
......@@ -1969,6 +1969,8 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
{ driver.option_str("parameter_set", "posterior_mode"); }
| PARAMETER_SET EQUAL POSTERIOR_MEDIAN
{ driver.option_str("parameter_set", "posterior_median"); }
| PARAMETER_SET EQUAL CALIBRATION
{ driver.option_str("parameter_set", "calibration"); }
;
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
o_labels : LABELS EQUAL '(' symbol_list ')' { driver.option_symbol_list("labels"); };
......
......@@ -443,6 +443,7 @@ string eofbuff;
<DYNARE_STATEMENT>mh_recover {return token::MH_RECOVER;}
<DYNARE_STATEMENT>planner_discount {return token::PLANNER_DISCOUNT;}
<DYNARE_STATEMENT>labels {return token::LABELS;}
<DYNARE_STATEMENT>calibration {return token::CALIBRATION;}
<DYNARE_BLOCK>equation {return token::EQUATION;}
<DYNARE_BLOCK>exclusion {return token::EXCLUSION;}
......
......@@ -289,9 +289,9 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
it != paths.end(); it++)
{
if (it == paths.begin())
output << "constrained_vars_ = '" << it->first << "';" << endl;
output << "constrained_vars_ = " << it->first << ";" << endl;
else
output << "constrained_vars_ = char(constrained_vars_, '" << it->first << "');" << endl;
output << "constrained_vars_ = [constrained_vars_; " << it->first << "];" << endl;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
for (int i = 0; i < (int) elems.size(); i++)
......
// See fs2000.mod in the examples/ directory for details on the model
var m P c e W R k d n l gy_obs gp_obs y dA;
varexo e_a e_m;
parameters alp bet gam mst rho psi del;
alp = 0.33;
bet = 0.99;
gam = 0.003;
mst = 1.011;
rho = 0.7;
psi = 0.787;
del = 0.02;
model;
dA = exp(gam+e_a);
log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
W = l/n;
-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
P*c = m;
m-1+d = l;
e = exp(e_a);
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
gy_obs = dA*y/y(-1);
gp_obs = (P/P(-1))*m(-1)/dA;
end;
initval;
k = 6;
m = mst;
P = 2.25;
c = 0.45;
e = 1;
W = 4;
R = 1.02;
d = 0.85;
n = 0.19;
l = 0.86;
y = 0.6;
gy_obs = exp(gam);
gp_obs = exp(-gam);
dA = exp(gam);
end;
shocks;
var e_a; stderr 0.014;
var e_m; stderr 0.005;
end;
steady;
check;
stoch_simul(irf=0);
conditional_forecast_paths;
var gy_obs;
periods 1 2 3:5;
values 0.01 -0.02 0;
var gp_obs;
periods 1:5;
values 0.05;
end;
conditional_forecast(parameter_set=calibration, controlled_varexo=(e_a,e_m));
plot_conditional_forecast(periods=10) gy_obs gp_obs;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment