2008-02-03 11:28:36 +01:00
/*
2023-10-18 19:48:45 +02:00
* Copyright © 2003 - 2023 Dynare Team
2008-02-03 11:28:36 +01:00
*
* 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
2021-06-09 16:52:20 +02:00
* along with Dynare . If not , see < https : //www.gnu.org/licenses/>.
2008-02-03 11:28:36 +01:00
*/
# ifndef _SHOCKS_HH
# define _SHOCKS_HH
# include <string>
# include <vector>
# include <map>
# include "Statement.hh"
# include "SymbolTable.hh"
# include "ExprNode.hh"
2022-01-06 14:54:57 +01:00
using namespace std ;
2008-02-03 11:28:36 +01:00
class AbstractShocksStatement : public Statement
{
public :
2021-07-13 16:24:37 +02:00
// The tuple is (period1, period2, value)
using det_shocks_t = map < int , vector < tuple < int , int , expr_t > > > ;
2023-10-18 19:48:45 +02:00
enum class ShockType
{
level , // The value is the level of the exogenous (“values” statement in “shocks”)
multiplySteadyState , // The value is the ratio of the exogenous over its (terminal) steady state (“values” statement in “mshocks”)
multiplyInitialSteadyState // The value is the ratio of the exogenous over its initial steady state (“values” statement in “mshocks(relative_to_initval)”)
} ;
2008-02-03 11:28:36 +01:00
protected :
2014-04-10 11:54:49 +02:00
//! Does this "shocks" statement replace the previous ones?
const bool overwrite ;
2023-10-18 19:48:45 +02:00
const ShockType type ; // Type of shocks represented by this block
2010-09-16 19:00:48 +02:00
const det_shocks_t det_shocks ;
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table ;
void writeDetShocks ( ostream & output ) const ;
2017-02-08 18:29:57 +01:00
void writeJsonDetShocks ( ostream & output ) const ;
2023-10-18 19:48:45 +02:00
static string typeToString ( ShockType type ) ;
2015-06-09 16:42:51 +02:00
2023-10-18 19:48:45 +02:00
AbstractShocksStatement ( bool overwrite_arg , ShockType type_arg ,
2018-06-04 12:31:07 +02:00
det_shocks_t det_shocks_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) ;
} ;
class ShocksStatement : public AbstractShocksStatement
{
2009-10-29 18:16:10 +01:00
public :
2018-06-04 14:31:26 +02:00
using var_and_std_shocks_t = map < int , expr_t > ;
using covar_and_corr_shocks_t = map < pair < int , int > , expr_t > ;
2009-10-29 18:16:10 +01:00
private :
2010-09-16 19:00:48 +02:00
const var_and_std_shocks_t var_shocks , std_shocks ;
const covar_and_corr_shocks_t covar_shocks , corr_shocks ;
2022-06-02 10:50:21 +02:00
void writeVarOrStdShock ( ostream & output , const pair < int , expr_t > & it , bool stddev ) const ;
2009-10-29 18:16:10 +01:00
void writeVarAndStdShocks ( ostream & output ) const ;
2022-06-02 10:50:21 +02:00
void writeCovarOrCorrShock ( ostream & output , const pair < pair < int , int > , expr_t > & it , bool corr ) const ;
2009-10-29 18:16:10 +01:00
void writeCovarAndCorrShocks ( ostream & output ) const ;
2014-04-10 11:54:49 +02:00
bool has_calibrated_measurement_errors ( ) const ;
2008-02-03 11:28:36 +01:00
public :
2014-04-10 11:54:49 +02:00
ShocksStatement ( bool overwrite_arg ,
2021-07-13 16:24:37 +02:00
det_shocks_t det_shocks_arg ,
2018-06-04 12:31:07 +02:00
var_and_std_shocks_t var_shocks_arg ,
var_and_std_shocks_t std_shocks_arg ,
covar_and_corr_shocks_t covar_shocks_arg ,
covar_and_corr_shocks_t corr_shocks_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) ;
2018-06-04 12:53:26 +02:00
void checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings ) override ;
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
2008-02-03 11:28:36 +01:00
} ;
class MShocksStatement : public AbstractShocksStatement
{
public :
2023-10-18 19:48:45 +02:00
const bool relative_to_initval ;
MShocksStatement ( bool overwrite_arg , bool relative_to_initval_arg ,
2021-07-13 16:24:37 +02:00
det_shocks_t det_shocks_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
2020-11-26 16:23:26 +01:00
void writeJsonOutput ( ostream & output ) const override ;
2008-02-03 11:28:36 +01:00
} ;
2021-07-13 17:07:53 +02:00
/* Represents a shocks(surprise) block.
Given the differences with the plain “ shocks ” block , it was easier to make
it a separate class . * /
class ShocksSurpriseStatement : public Statement
{
public :
//! Does this "shocks(surprise)" statement replace the previous ones?
const bool overwrite ;
const AbstractShocksStatement : : det_shocks_t surprise_shocks ;
private :
const SymbolTable & symbol_table ;
public :
ShocksSurpriseStatement ( bool overwrite_arg ,
AbstractShocksStatement : : det_shocks_t surprise_shocks_arg ,
const SymbolTable & symbol_table_arg ) ;
void checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings ) override ;
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
} ;
2023-10-17 20:52:00 +02:00
/* Represents a shocks(learnt_in=…) or mshocks(learnt_in=…) block.
Given the differences with the plain “ shocks ” and “ mshocks ” blocks ,
it was easier to make it a separate class . * /
2022-04-20 16:57:39 +02:00
class ShocksLearntInStatement : public Statement
{
public :
const int learnt_in_period ;
2023-10-17 20:52:00 +02:00
//! Does this “shocks(learnt_in=…)” or “mshocks(learnt_in=…)” block replace the previous ones?
2022-04-20 16:57:39 +02:00
const bool overwrite ;
2022-04-26 15:21:45 +02:00
enum class LearntShockType
{
2023-10-17 20:52:00 +02:00
level , // The value is the level of the exogenous (“values” statement in “shocks(learnt_in=…)”)
add , // The value is the additive change of the exogenous compared to previous information period (“add” statement in “shocks(learnt_in=…)”)
multiply , // The value is the multiplicative change of the exogenous compared to previous information period (“multiply” statement in “shocks(learnt_in=…)”)
2023-10-18 19:48:45 +02:00
multiplySteadyState , // The value is the ratio of the exogenous over its (terminal) steady state as anticipated in the same informational period (“values” statement in “mshocks(learnt_in=…)”)
multiplyInitialSteadyState // The value is the ratio of the exogenous over its initial steady state as anticipated in the same informational period (“values” statement in “mshocks(learnt_in=…, relative_to_initval)”)
2022-04-26 15:21:45 +02:00
} ;
// The tuple is (type, period1, period2, value)
using learnt_shocks_t = map < int , vector < tuple < LearntShockType , int , int , expr_t > > > ;
const learnt_shocks_t learnt_shocks ;
2022-04-20 16:57:39 +02:00
private :
const SymbolTable & symbol_table ;
2022-04-26 15:21:45 +02:00
static string typeToString ( LearntShockType type ) ;
2022-04-20 16:57:39 +02:00
public :
ShocksLearntInStatement ( int learnt_in_period_arg , bool overwrite_arg ,
2022-04-26 15:21:45 +02:00
learnt_shocks_t learnt_shocks_arg ,
2022-04-20 16:57:39 +02:00
const SymbolTable & symbol_table_arg ) ;
void checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings ) override ;
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
} ;
2009-10-16 19:23:57 +02:00
class ConditionalForecastPathsStatement : public Statement
{
private :
2010-09-16 19:00:48 +02:00
const AbstractShocksStatement : : det_shocks_t paths ;
2016-09-06 14:43:06 +02:00
const SymbolTable & symbol_table ;
2022-06-02 10:50:21 +02:00
const int path_length ;
2009-10-16 19:23:57 +02:00
public :
2018-06-04 12:31:07 +02:00
ConditionalForecastPathsStatement ( AbstractShocksStatement : : det_shocks_t paths_arg ,
2016-09-06 14:43:06 +02:00
const SymbolTable & symbol_table_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
2019-03-29 17:02:29 +01:00
void writeJsonOutput ( ostream & output ) const override ;
2022-06-02 10:50:21 +02:00
static int computePathLength ( const AbstractShocksStatement : : det_shocks_t & paths ) ;
2009-10-16 19:23:57 +02:00
} ;
2014-02-10 19:22:54 +01:00
class MomentCalibration : public Statement
{
public :
struct Constraint
{
int endo1 , endo2 ;
2014-03-17 18:10:44 +01:00
string lags ;
2019-09-25 12:02:44 +02:00
expr_t lower_bound , upper_bound ;
2014-02-10 19:22:54 +01:00
} ;
2018-06-04 14:07:13 +02:00
using constraints_t = vector < Constraint > ;
2014-02-10 19:22:54 +01:00
private :
constraints_t constraints ;
const SymbolTable & symbol_table ;
public :
2018-06-04 12:31:07 +02:00
MomentCalibration ( constraints_t constraints_arg ,
2014-02-10 19:22:54 +01:00
const SymbolTable & symbol_table_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
2014-02-10 19:22:54 +01:00
} ;
class IrfCalibration : public Statement
{
public :
struct Constraint
{
2014-03-17 18:10:44 +01:00
int endo ;
2014-02-10 19:22:54 +01:00
int exo ;
2019-09-25 12:02:44 +02:00
string periods ;
expr_t lower_bound , upper_bound ;
2014-02-10 19:22:54 +01:00
} ;
2018-06-04 14:07:13 +02:00
using constraints_t = vector < Constraint > ;
2014-02-10 19:22:54 +01:00
private :
constraints_t constraints ;
const SymbolTable & symbol_table ;
2015-09-07 11:39:33 +02:00
const OptionsList options_list ;
2014-02-10 19:22:54 +01:00
public :
2018-06-04 12:31:07 +02:00
IrfCalibration ( constraints_t constraints_arg ,
2015-09-07 11:39:33 +02:00
const SymbolTable & symbol_table_arg ,
2018-06-04 12:31:07 +02:00
OptionsList options_list_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
2014-02-10 19:22:54 +01:00
} ;
2016-04-10 18:55:17 +02:00
class ShockGroupsStatement : public Statement
{
public :
struct Group
{
string name ;
vector < string > list ;
} ;
2018-06-04 14:07:13 +02:00
using group_t = vector < Group > ;
2016-04-10 18:55:17 +02:00
private :
group_t shock_groups ;
string name ;
public :
2018-06-04 12:31:07 +02:00
ShockGroupsStatement ( group_t shock_groups_arg , string name_arg ) ;
2018-06-04 12:53:26 +02:00
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
2019-04-12 14:16:42 +02:00
void writeJsonOutput ( ostream & output ) const override ;
2016-04-10 18:55:17 +02:00
} ;
2017-06-14 07:01:31 +02:00
2019-12-02 11:18:21 +01:00
class Init2shocksStatement : public Statement
{
private :
const vector < pair < int , int > > init2shocks ;
const string name ;
const SymbolTable & symbol_table ;
public :
Init2shocksStatement ( vector < pair < int , int > > init2shocks_arg , string name_arg , const SymbolTable & symbol_table_arg ) ;
void checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings ) override ;
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
} ;
2021-05-26 18:00:06 +02:00
class HeteroskedasticShocksStatement : public Statement
{
public :
// Maps exo symb_id to list of tuples (period1, period2, value/scale)
using heteroskedastic_shocks_t = map < int , vector < tuple < int , int , expr_t > > > ;
private :
const bool overwrite ;
const heteroskedastic_shocks_t values , scales ;
const SymbolTable & symbol_table ;
public :
2022-10-04 15:59:18 +02:00
HeteroskedasticShocksStatement ( bool overwrite_arg , heteroskedastic_shocks_t values_arg ,
heteroskedastic_shocks_t scales_arg ,
2021-05-26 18:00:06 +02:00
const SymbolTable & symbol_table_arg ) ;
void writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const override ;
void writeJsonOutput ( ostream & output ) const override ;
} ;
2008-02-03 11:28:36 +01:00
# endif