Commit 7044c8da authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Add new command "calib_smoother"

Closes: #233
parent 31281406
......@@ -4520,6 +4520,42 @@ See @file{bvar-a-la-sims.pdf}, which comes with Dynare distribution,
for more information on this command.
@end deffn
@deffn Command calib_smoother [@var{VARIABLE_NAME}]@dots{};
@deffnx Command calib_smoother (@var{OPTIONS}@dots{}) [@var{VARIABLE_NAME}]@dots{};
@descriptionhead
This command computes the smoothed variables (and possible the filtered
variables) on a @code{calibrated} model.
A datafile must be provided, and the observable variables declared with
@code{varobs}.
@vindex{oo_.SmoothedVariables}
@vindex{oo_.SmoothedShocks}
@vindex{oo_.UpdatedVariables}
By default, the command computes the smoothed variables and shocks and stores the
results in @code{oo_.SmoothedVariables} and
@code{oo_.SmoothedShocks}. It also fills @code{oo_.UpdatedVariables}.
@optionshead
@table @code
@item datafile = @var{FILENAME}
@xref{datafile}.
@item filtered_vars
Triggers the computation of filtered variables. @xref{filtered_vars} for
more details.
@item filter_step_ahead = [@var{INTEGER1}:@var{INTEGER2}]
@xref{filter_step_ahead}.
@end table
@end deffn
@node Forecasting
@section Forecasting
......
......@@ -56,7 +56,7 @@ end
if isempty(varlist)
disp(' ')
disp(['You did not declare endogenous variables after the estimation command.'])
disp(['You did not declare endogenous variables after the estimation/calib_smoother command.'])
cas = [];
if options_.bayesian_irf
cas = 'Posterior IRFs';
......@@ -70,30 +70,23 @@ if isempty(varlist)
end
if options_.smoother
if isempty(cas)
cas = 'Posterior smoothed variables';
cas = 'Smoothed variables';
else
cas = [ cas , ', posterior smoothed variables'];
end
end
if options_.smoother
if isempty(cas)
cas = 'Posterior smoothed variables';
else
cas = [ cas , ', posterior smoothed variables'];
cas = [ cas , ', smoothed variables'];
end
end
if ~isempty(options_.filter_step_ahead)
if isempty(cas)
cas = 'Posterior k-step ahead filtered variables';
cas = 'k-step ahead filtered variables';
else
cas = [ cas , ', posterior k-step ahead filtered variables'];
cas = [ cas , ', k-step ahead filtered variables'];
end
end
if options_.forecast
if isempty(cas)
cas = 'Posterior forecasts';
cas = 'Forecasts';
else
cas = [ cas , ' and posterior forecats'];
cas = [ cas , ' and forecats'];
end
end
if ~isempty(cas)
......
......@@ -2300,3 +2300,19 @@ OptionsEqualStatement::writeOutput(ostream &output, const string &basename) cons
output << lhs_field << " = " << rhs_field << ";" << endl;
}
CalibSmootherStatement::CalibSmootherStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg)
: symbol_list(symbol_list_arg), options_list(options_list_arg)
{
}
void
CalibSmootherStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
symbol_list.writeOutput("var_list_", output);
output << "options_.mode_compute = 0;" << endl
<< "options_.smoother = 1;" << endl
<< "dynare_estimation(var_list_);" << endl;
}
......@@ -508,6 +508,17 @@ public:
virtual void writeOutput(ostream &output, const string &basename) const;
};
class CalibSmootherStatement : public Statement
{
private:
const SymbolList symbol_list;
const OptionsList options_list;
public:
CalibSmootherStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};
class SvarIdentificationStatement : public Statement
{
public:
......
......@@ -95,7 +95,7 @@ class ParsingDriver;
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
%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 CALIB_SMOOTHER CHANGE_TYPE CHECK CONDITIONAL_FORECAST CONDITIONAL_FORECAST_PATHS CONF_SIG CONSTANT CONTROLLED_VAREXO CORR COVAR CUTOFF
%token DATAFILE FILE DOUBLING 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 LAST_OBS SET_TIME
......@@ -268,6 +268,7 @@ statement : parameters
| ms_forecast
| ms_irf
| ms_variance_decomposition
| calib_smoother
;
dsample : DSAMPLE INT_NUMBER ';'
......@@ -2113,6 +2114,25 @@ steady_state_equation : symbol EQUAL expression ';'
{ driver.add_steady_state_model_equal_multiple($5); }
;
calib_smoother : CALIB_SMOOTHER ';'
{ driver.calib_smoother(); }
| CALIB_SMOOTHER '(' calib_smoother_options_list ')' ';'
{ driver.calib_smoother(); }
| CALIB_SMOOTHER symbol_list ';'
{ driver.calib_smoother(); }
| CALIB_SMOOTHER '(' calib_smoother_options_list ')' symbol_list ';'
{ driver.calib_smoother(); }
;
calib_smoother_options_list : calib_smoother_option COMMA calib_smoother_options_list
| calib_smoother_option
;
calib_smoother_option : o_filtered_vars
| o_filter_step_ahead
| o_datafile
;
o_dr_algo : DR_ALGO EQUAL INT_NUMBER {
if (*$3 == string("0"))
driver.warning("dr_algo option is now deprecated, and may be removed in a future version of Dynare");
......
......@@ -156,6 +156,7 @@ string eofbuff;
<INITIAL>svar {BEGIN DYNARE_STATEMENT; return token::SVAR;}
<INITIAL>external_function {BEGIN DYNARE_STATEMENT; return token::EXTERNAL_FUNCTION;}
/* End of a Dynare statement */
<INITIAL>calib_smoother { BEGIN DYNARE_STATEMENT; return token::CALIB_SMOOTHER; }
<DYNARE_STATEMENT>; {
if (!sigma_e)
......
......@@ -1932,6 +1932,14 @@ ParsingDriver::conditional_forecast_paths()
det_shocks.clear();
}
void
ParsingDriver::calib_smoother()
{
mod_file->addStatement(new CalibSmootherStatement(symbol_list, options_list));
symbol_list.clear();
options_list.clear();
}
expr_t
ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2)
{
......
......@@ -514,6 +514,8 @@ public:
void conditional_forecast_paths();
//! Plot conditional forecast statement
void plot_conditional_forecast(string *periods = NULL);
//! Smoother on calibrated models
void calib_smoother();
//! Writes token "arg1=arg2" to model tree
expr_t add_model_equal(expr_t arg1, expr_t arg2);
//! Writes token "arg=0" to model tree
......
......@@ -22,6 +22,7 @@ MODFILES = \
predetermined_variables.mod \
fs2000_nonstationary.mod \
fs2000_ssfile.mod \
fs2000_calib.mod \
comments.mod \
histval_sto.mod \
histval_det.mod \
......
// 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;
varobs gp_obs gy_obs;
calib_smoother(datafile=fsdat_simul, filtered_vars, filter_step_ahead = [3:4]) m P c e W R k d n l y dA;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment