Added declaration of observed exogenous variables.

With integration test.
time-shift
Stéphane Adjemian (Charybdis) 2016-10-13 18:19:38 +02:00
parent 5282e737e7
commit e1033c76b9
8 changed files with 143 additions and 1 deletions

View File

@ -129,7 +129,7 @@ class ParsingDriver;
%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
%token <string_val> TEX_NAME
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
%token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES
%token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP
%left COMMA
@ -232,6 +232,7 @@ statement : parameters
| options_eq
| varobs
| observation_trends
| varexobs
| unit_root_vars
| dsample
| rplot
@ -1893,6 +1894,16 @@ varobs_list : varobs_list symbol
{ driver.add_varobs($1); }
;
varexobs : VAREXOBS { driver.check_varexobs(); } varexobs_list ';';
varexobs_list : varexobs_list symbol
{ driver.add_varexobs($2); }
| varexobs_list COMMA symbol
{ driver.add_varexobs($3); }
| symbol
{ driver.add_varexobs($1); }
;
observation_trends : OBSERVATION_TRENDS ';' trend_list END ';' { driver.set_trends(); };
trend_list : trend_list trend_element

View File

@ -117,6 +117,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<INITIAL>set_time {BEGIN DYNARE_STATEMENT; return token::SET_TIME;}
<INITIAL>data {BEGIN DYNARE_STATEMENT; return token::DATA;}
<INITIAL>varobs {BEGIN DYNARE_STATEMENT; return token::VAROBS;}
<INITIAL>varexobs {BEGIN DYNARE_STATEMENT; return token::VAREXOBS;}
<INITIAL>unit_root_vars {BEGIN DYNARE_STATEMENT; return token::UNIT_ROOT_VARS;}
<INITIAL>rplot {BEGIN DYNARE_STATEMENT; return token::RPLOT;}
<INITIAL>osr_params {BEGIN DYNARE_STATEMENT; return token::OSR_PARAMS;}
@ -761,6 +762,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<DYNARE_STATEMENT,DYNARE_BLOCK>steady_state {return token::STEADY_STATE;}
<DYNARE_STATEMENT,DYNARE_BLOCK>expectation {return token::EXPECTATION;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varobs {return token::VAROBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>varexobs {return token::VAREXOBS;}
<DYNARE_STATEMENT,DYNARE_BLOCK>full {return token::FULL;}
<DYNARE_STATEMENT,DYNARE_BLOCK>nan {return token::NAN_CONSTANT;}
<DYNARE_STATEMENT,DYNARE_BLOCK>inf {return token::INF_CONSTANT;}

View File

@ -1776,6 +1776,24 @@ ParsingDriver::add_varobs(string *name)
delete name;
}
void
ParsingDriver::check_varexobs()
{
if (mod_file->symbol_table.observedExogenousVariablesNbr() > 0)
error("varexobs: you cannot have several 'varexobs' statements in the same MOD file");
}
void
ParsingDriver::add_varexobs(string *name)
{
check_symbol_existence(*name);
int symb_id = mod_file->symbol_table.getID(*name);
if (mod_file->symbol_table.getType(symb_id) != eExogenous)
error("varexobs: " + *name + " is not an exogenous variable");
mod_file->symbol_table.addObservedExogenousVariable(symb_id);
delete name;
}
void
ParsingDriver::set_trends()
{

View File

@ -486,6 +486,10 @@ public:
void check_varobs();
//! Add a new observed variable
void add_varobs(string *name);
//! Check that no observed exogenous variable has yet be defined
void check_varexobs();
//! Add a new observed exogenous variable
void add_varexobs(string *name);
//! Svar_Identification Statement
void begin_svar_identification();
void end_svar_identification();

View File

@ -394,6 +394,21 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
output << getTypeSpecificID(*it)+1 << " ";
output << " ];" << endl;
}
if (observedExogenousVariablesNbr() > 0)
{
int ic = 1;
output << "options_.varexobs = cell(1);" << endl;
for (vector<int>::const_iterator it = varexobs.begin();
it != varexobs.end(); it++, ic++)
output << "options_.varexobs(" << ic << ") = {'" << getName(*it) << "'};" << endl;
output << "options_.varexobs_id = [ ";
for (vector<int>::const_iterator it = varexobs.begin();
it != varexobs.end(); it++)
output << getTypeSpecificID(*it)+1 << " ";
output << " ];" << endl;
}
}
void
@ -491,6 +506,20 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
}
output << "};" << endl;
}
output << "int observedExogenousVariablesNbr = " << observedExogenousVariablesNbr() << ";" << endl;
if (observedExogenousVariablesNbr() > 0)
{
output << "int varexobs[" << observedExogenousVariablesNbr() << "] = {";
for (vector<int>::const_iterator it = varexobs.begin();
it != varexobs.end(); it++)
{
if ( it != varexobs.begin() )
output << ",";
output << getTypeSpecificID(*it);
}
output << "};" << endl;
}
}
void
@ -549,6 +578,10 @@ SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
for (vector<int>::const_iterator it = varobs.begin();
it != varobs.end(); it++)
output << "varobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
for (vector<int>::const_iterator it = varexobs.begin();
it != varexobs.end(); it++)
output << "varexobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
}
int
@ -776,6 +809,36 @@ SymbolTable::getObservedVariableIndex(int symb_id) const
return (int) (it - varobs.begin());
}
void
SymbolTable::addObservedExogenousVariable(int symb_id) throw (UnknownSymbolIDException)
{
if (symb_id < 0 || symb_id >= size)
throw UnknownSymbolIDException(symb_id);
assert(getType(symb_id) != eEndogenous);
varexobs.push_back(symb_id);
}
int
SymbolTable::observedExogenousVariablesNbr() const
{
return (int) varexobs.size();
}
bool
SymbolTable::isObservedExogenousVariable(int symb_id) const
{
return (find(varexobs.begin(), varexobs.end(), symb_id) != varexobs.end());
}
int
SymbolTable::getObservedExogenousVariableIndex(int symb_id) const
{
vector<int>::const_iterator it = find(varexobs.begin(), varexobs.end(), symb_id);
assert(it != varexobs.end());
return (int) (it - varexobs.begin());
}
vector <int>
SymbolTable::getTrendVarIds() const
{

View File

@ -121,6 +121,9 @@ private:
//! Stores the list of observed variables
vector<int> varobs;
//! Stores the list of observed exogenous variables
vector<int> varexobs;
public:
SymbolTable();
//! Thrown when trying to access an unknown symbol (by name)
@ -314,6 +317,14 @@ public:
bool isObservedVariable(int symb_id) const;
//! Return the index of a given observed variable in the vector of all observed variables
int getObservedVariableIndex(int symb_id) const;
//! Add an observed exogenous variable
void addObservedExogenousVariable(int symb_id) throw (UnknownSymbolIDException);
//! Return the number of observed exogenous variables
int observedExogenousVariablesNbr() const;
//! Is a given symbol in the set of observed exogenous variables
bool isObservedExogenousVariable(int symb_id) const;
//! Return the index of a given observed exogenous variable in the vector of all observed variables
int getObservedExogenousVariableIndex(int symb_id) const;
vector <int> getTrendVarIds() const;
//! Get list of exogenous variables
set <int> getExogenous() const;

View File

@ -27,6 +27,7 @@ MODFILES = \
ms-sbvar/test_ms_variances_repeated_runs.mod \
fs2000/fs2000.mod \
ep/rbc.mod \
exogenous-observed-variables/preprocessor.mod \
estimation/fs2000_with_weibull_prior.mod \
estimation/fs2000_initialize_from_calib.mod \
estimation/fs2000_calibrated_covariance.mod \

View File

@ -0,0 +1,32 @@
var y z;
varexo e x u;
parameters rho;
rho = .9;
model(linear);
y = z + e ;
z = rho*z(-1) + u;
end;
shocks;
var e; stderr .01;
var u; stderr .01;
end;
varobs y;
varexobs x;
assert(length(options_.varobs)==1);
assert(length(options_.varexobs)==1);
assert(length(options_.varobs_id)==1);
assert(length(options_.varexobs_id)==1);
assert(options_.varobs_id==1);
assert(options_.varexobs_id==2);
assert(options_.varobs{1}=='y');
assert(options_.varexobs{1}=='x');