2008-02-03 11:28:36 +01:00
/*
2016-05-04 16:04:44 +02:00
* Copyright ( C ) 2003 - 2016 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
* along with Dynare . If not , see < http : //www.gnu.org/licenses/>.
*/
2009-10-16 19:23:57 +02:00
# include <cassert>
# include <cstdlib>
2008-02-03 11:28:36 +01:00
# include <iostream>
# include "Shocks.hh"
AbstractShocksStatement : : AbstractShocksStatement ( bool mshocks_arg ,
2014-04-10 11:54:49 +02:00
bool overwrite_arg ,
2010-09-16 19:00:48 +02:00
const det_shocks_t & det_shocks_arg ,
2009-01-23 11:59:37 +01:00
const SymbolTable & symbol_table_arg ) :
2008-02-03 11:28:36 +01:00
mshocks ( mshocks_arg ) ,
2014-04-10 11:54:49 +02:00
overwrite ( overwrite_arg ) ,
2008-02-03 11:28:36 +01:00
det_shocks ( det_shocks_arg ) ,
symbol_table ( symbol_table_arg )
{
}
void
AbstractShocksStatement : : writeDetShocks ( ostream & output ) const
{
int exo_det_length = 0 ;
2010-09-16 19:00:48 +02:00
for ( det_shocks_t : : const_iterator it = det_shocks . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = det_shocks . end ( ) ; it + + )
2008-02-03 11:28:36 +01:00
{
2009-02-27 13:19:25 +01:00
int id = symbol_table . getTypeSpecificID ( it - > first ) + 1 ;
2008-02-03 11:28:36 +01:00
bool exo_det = ( symbol_table . getType ( it - > first ) = = eExogenousDet ) ;
2013-12-31 01:57:30 +01:00
for ( size_t i = 0 ; i < it - > second . size ( ) ; i + + )
2008-02-03 11:28:36 +01:00
{
2013-12-31 01:57:30 +01:00
const int & period1 = it - > second [ i ] . period1 ;
const int & period2 = it - > second [ i ] . period2 ;
const expr_t value = it - > second [ i ] . value ;
2008-02-03 11:28:36 +01:00
2014-04-09 15:23:20 +02:00
output < < " M_.det_shocks = [ M_.det_shocks; " < < endl
< < " struct('exo_det', " < < ( int ) exo_det
< < " ,'exo_id', " < < id
< < " ,'multiplicative', " < < ( int ) mshocks
< < " ,'periods', " < < period1 < < " : " < < period2
< < " ,'value', " ;
2014-04-08 17:43:58 +02:00
value - > writeOutput ( output ) ;
2014-04-09 15:23:20 +02:00
output < < " ) ]; " < < endl ;
2008-02-03 11:28:36 +01:00
if ( exo_det & & ( period2 > exo_det_length ) )
exo_det_length = period2 ;
}
}
output < < " M_.exo_det_length = " < < exo_det_length < < " ; \n " ;
}
2014-04-10 11:54:49 +02:00
ShocksStatement : : ShocksStatement ( bool overwrite_arg ,
const det_shocks_t & det_shocks_arg ,
2010-09-16 19:00:48 +02:00
const var_and_std_shocks_t & var_shocks_arg ,
const var_and_std_shocks_t & std_shocks_arg ,
const covar_and_corr_shocks_t & covar_shocks_arg ,
const covar_and_corr_shocks_t & corr_shocks_arg ,
2009-10-29 18:16:10 +01:00
const SymbolTable & symbol_table_arg ) :
2014-04-10 11:54:49 +02:00
AbstractShocksStatement ( false , overwrite_arg , det_shocks_arg , symbol_table_arg ) ,
2009-10-29 18:16:10 +01:00
var_shocks ( var_shocks_arg ) ,
std_shocks ( std_shocks_arg ) ,
covar_shocks ( covar_shocks_arg ) ,
corr_shocks ( corr_shocks_arg )
{
}
void
2015-05-28 11:42:12 +02:00
ShocksStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-10-29 18:16:10 +01:00
{
output < < " % " < < endl
< < " % SHOCKS instructions " < < endl
< < " % " < < endl ;
2014-04-10 11:54:49 +02:00
if ( overwrite )
{
output < < " M_.det_shocks = []; " < < endl ;
output < < " M_.Sigma_e = zeros( " < < symbol_table . exo_nbr ( ) < < " , "
< < symbol_table . exo_nbr ( ) < < " ); " < < endl
< < " M_.Correlation_matrix = eye( " < < symbol_table . exo_nbr ( ) < < " , "
< < symbol_table . exo_nbr ( ) < < " ); " < < endl ;
if ( has_calibrated_measurement_errors ( ) )
output < < " M_.H = zeros( " < < symbol_table . observedVariablesNbr ( ) < < " , "
< < symbol_table . observedVariablesNbr ( ) < < " ); " < < endl
< < " M_.Correlation_matrix_ME = eye( " < < symbol_table . observedVariablesNbr ( ) < < " , "
< < symbol_table . observedVariablesNbr ( ) < < " ); " < < endl ;
else
output < < " M_.H = 0; " < < endl
< < " M_.Correlation_matrix_ME = 1; " < < endl ;
}
2009-10-29 18:16:10 +01:00
writeDetShocks ( output ) ;
writeVarAndStdShocks ( output ) ;
writeCovarAndCorrShocks ( output ) ;
2014-04-10 11:43:26 +02:00
/* M_.sigma_e_is_diagonal is initialized to 1 by ModFile.cc.
If there are no off - diagonal elements , and we are not in overwrite mode ,
then we don ' t reset it to 1 , since there might be previous shocks blocks
with off - diagonal elements . */
2009-10-29 18:16:10 +01:00
if ( covar_shocks . size ( ) + corr_shocks . size ( ) > 0 )
output < < " M_.sigma_e_is_diagonal = 0; " < < endl ;
2014-04-10 11:43:26 +02:00
else if ( overwrite )
2009-10-29 18:16:10 +01:00
output < < " M_.sigma_e_is_diagonal = 1; " < < endl ;
}
2010-04-14 15:03:41 +02:00
void
2010-09-16 19:00:48 +02:00
ShocksStatement : : writeVarOrStdShock ( ostream & output , var_and_std_shocks_t : : const_iterator & it ,
2010-04-15 17:46:05 +02:00
bool stddev ) const
2010-04-14 15:03:41 +02:00
{
SymbolType type = symbol_table . getType ( it - > first ) ;
assert ( type = = eExogenous | | symbol_table . isObservedVariable ( it - > first ) ) ;
int id ;
if ( type = = eExogenous )
{
output < < " M_.Sigma_e( " ;
id = symbol_table . getTypeSpecificID ( it - > first ) + 1 ;
}
else
{
output < < " M_.H( " ;
id = symbol_table . getObservedVariableIndex ( it - > first ) + 1 ;
}
output < < id < < " , " < < id < < " ) = " ;
2010-04-15 17:46:05 +02:00
if ( stddev )
2010-04-14 15:03:41 +02:00
output < < " ( " ;
it - > second - > writeOutput ( output ) ;
2010-04-15 17:46:05 +02:00
if ( stddev )
2010-04-14 15:03:41 +02:00
output < < " )^2 " ;
output < < " ; " < < endl ;
}
2009-10-29 18:16:10 +01:00
void
ShocksStatement : : writeVarAndStdShocks ( ostream & output ) const
2008-02-03 11:28:36 +01:00
{
2010-09-16 19:00:48 +02:00
var_and_std_shocks_t : : const_iterator it ;
2008-02-03 11:28:36 +01:00
2009-12-16 18:13:23 +01:00
for ( it = var_shocks . begin ( ) ; it ! = var_shocks . end ( ) ; it + + )
2010-04-14 15:03:41 +02:00
writeVarOrStdShock ( output , it , false ) ;
2008-02-03 11:28:36 +01:00
2009-12-16 18:13:23 +01:00
for ( it = std_shocks . begin ( ) ; it ! = std_shocks . end ( ) ; it + + )
2010-04-14 15:03:41 +02:00
writeVarOrStdShock ( output , it , true ) ;
}
void
2010-09-16 19:00:48 +02:00
ShocksStatement : : writeCovarOrCorrShock ( ostream & output , covar_and_corr_shocks_t : : const_iterator & it ,
2010-04-14 15:03:41 +02:00
bool corr ) const
{
SymbolType type1 = symbol_table . getType ( it - > first . first ) ;
SymbolType type2 = symbol_table . getType ( it - > first . second ) ;
assert ( ( type1 = = eExogenous & & type2 = = eExogenous )
| | ( symbol_table . isObservedVariable ( it - > first . first ) & & symbol_table . isObservedVariable ( it - > first . second ) ) ) ;
2013-10-28 15:29:41 +01:00
string matrix , corr_matrix ;
2010-04-14 15:03:41 +02:00
int id1 , id2 ;
if ( type1 = = eExogenous )
2008-02-03 11:28:36 +01:00
{
2010-04-14 15:03:41 +02:00
matrix = " M_.Sigma_e " ;
2013-10-28 15:29:41 +01:00
corr_matrix = " M_.Correlation_matrix " ;
2010-04-14 15:03:41 +02:00
id1 = symbol_table . getTypeSpecificID ( it - > first . first ) + 1 ;
id2 = symbol_table . getTypeSpecificID ( it - > first . second ) + 1 ;
}
else
{
matrix = " M_.H " ;
2013-10-28 15:29:41 +01:00
corr_matrix = " M_.Correlation_matrix_ME " ;
2010-04-14 15:03:41 +02:00
id1 = symbol_table . getObservedVariableIndex ( it - > first . first ) + 1 ;
id2 = symbol_table . getObservedVariableIndex ( it - > first . second ) + 1 ;
2008-02-03 11:28:36 +01:00
}
2010-04-14 15:03:41 +02:00
output < < matrix < < " ( " < < id1 < < " , " < < id2 < < " ) = " ;
it - > second - > writeOutput ( output ) ;
if ( corr )
output < < " *sqrt( " < < matrix < < " ( " < < id1 < < " , " < < id1 < < " )* "
< < matrix < < " ( " < < id2 < < " , " < < id2 < < " )) " ;
output < < " ; " < < endl
< < matrix < < " ( " < < id2 < < " , " < < id1 < < " ) = "
< < matrix < < " ( " < < id1 < < " , " < < id2 < < " ); " < < endl ;
2013-10-28 15:29:41 +01:00
if ( corr )
{
output < < corr_matrix < < " ( " < < id1 < < " , " < < id2 < < " ) = " ;
it - > second - > writeOutput ( output ) ;
output < < " ; " < < endl
< < corr_matrix < < " ( " < < id2 < < " , " < < id1 < < " ) = "
< < corr_matrix < < " ( " < < id1 < < " , " < < id2 < < " ); " < < endl ;
}
2008-02-03 11:28:36 +01:00
}
void
2009-10-29 18:16:10 +01:00
ShocksStatement : : writeCovarAndCorrShocks ( ostream & output ) const
2008-02-03 11:28:36 +01:00
{
2010-09-16 19:00:48 +02:00
covar_and_corr_shocks_t : : const_iterator it ;
2008-02-03 11:28:36 +01:00
2009-12-16 18:13:23 +01:00
for ( it = covar_shocks . begin ( ) ; it ! = covar_shocks . end ( ) ; it + + )
2010-04-14 15:03:41 +02:00
writeCovarOrCorrShock ( output , it , false ) ;
2008-02-03 11:28:36 +01:00
2009-12-16 18:13:23 +01:00
for ( it = corr_shocks . begin ( ) ; it ! = corr_shocks . end ( ) ; it + + )
2010-04-14 15:03:41 +02:00
writeCovarOrCorrShock ( output , it , true ) ;
}
void
2012-02-02 21:10:47 +01:00
ShocksStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2010-04-14 15:03:41 +02:00
{
2013-08-27 10:38:54 +02:00
/* Error out if variables are not of the right type. This must be done here
and not at parsing time ( see # 448 ) .
Also Determine if there is a calibrated measurement error */
2010-09-16 19:00:48 +02:00
for ( var_and_std_shocks_t : : const_iterator it = var_shocks . begin ( ) ;
2010-04-14 15:03:41 +02:00
it ! = var_shocks . end ( ) ; it + + )
2013-08-27 10:38:54 +02:00
{
if ( symbol_table . getType ( it - > first ) ! = eExogenous
& & ! symbol_table . isObservedVariable ( it - > first ) )
{
cerr < < " shocks: setting a variance on ' "
< < symbol_table . getName ( it - > first ) < < " ' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2010-04-14 15:03:41 +02:00
2010-09-16 19:00:48 +02:00
for ( var_and_std_shocks_t : : const_iterator it = std_shocks . begin ( ) ;
2010-04-14 15:03:41 +02:00
it ! = std_shocks . end ( ) ; it + + )
2013-08-27 10:38:54 +02:00
{
if ( symbol_table . getType ( it - > first ) ! = eExogenous
& & ! symbol_table . isObservedVariable ( it - > first ) )
{
cerr < < " shocks: setting a standard error on ' "
< < symbol_table . getName ( it - > first ) < < " ' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2010-04-14 15:03:41 +02:00
2010-09-16 19:00:48 +02:00
for ( covar_and_corr_shocks_t : : const_iterator it = covar_shocks . begin ( ) ;
2010-04-14 15:03:41 +02:00
it ! = covar_shocks . end ( ) ; it + + )
2013-08-27 10:38:54 +02:00
{
int symb_id1 = it - > first . first ;
int symb_id2 = it - > first . second ;
if ( ! ( ( symbol_table . getType ( symb_id1 ) = = eExogenous
& & symbol_table . getType ( symb_id2 ) = = eExogenous )
| | ( symbol_table . isObservedVariable ( symb_id1 )
& & symbol_table . isObservedVariable ( symb_id2 ) ) ) )
{
cerr < < " shocks: setting a covariance between ' "
< < symbol_table . getName ( symb_id1 ) < < " ' and ' "
< < symbol_table . getName ( symb_id2 ) < < " 'is not allowed; covariances can only be specified for exogenous or observed endogenous variables of same type " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2010-04-14 15:03:41 +02:00
2010-09-16 19:00:48 +02:00
for ( covar_and_corr_shocks_t : : const_iterator it = corr_shocks . begin ( ) ;
2010-04-14 15:03:41 +02:00
it ! = corr_shocks . end ( ) ; it + + )
2013-08-27 10:38:54 +02:00
{
int symb_id1 = it - > first . first ;
int symb_id2 = it - > first . second ;
if ( ! ( ( symbol_table . getType ( symb_id1 ) = = eExogenous
& & symbol_table . getType ( symb_id2 ) = = eExogenous )
| | ( symbol_table . isObservedVariable ( symb_id1 )
& & symbol_table . isObservedVariable ( symb_id2 ) ) ) )
{
cerr < < " shocks: setting a correlation between ' "
< < symbol_table . getName ( symb_id1 ) < < " ' and ' "
< < symbol_table . getName ( symb_id2 ) < < " 'is not allowed; correlations can only be specified for exogenous or observed endogenous variables of same type " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
2013-11-29 14:50:58 +01:00
2014-04-10 11:54:49 +02:00
// Determine if there is a calibrated measurement error
mod_file_struct . calibrated_measurement_errors | = has_calibrated_measurement_errors ( ) ;
2013-11-29 14:50:58 +01:00
// Fill in mod_file_struct.parameters_with_shocks_values (related to #469)
for ( var_and_std_shocks_t : : const_iterator it = var_shocks . begin ( ) ;
it ! = var_shocks . end ( ) ; + + it )
2013-11-29 15:32:49 +01:00
it - > second - > collectVariables ( eParameter , mod_file_struct . parameters_within_shocks_values ) ;
2013-11-29 14:50:58 +01:00
for ( var_and_std_shocks_t : : const_iterator it = std_shocks . begin ( ) ;
it ! = std_shocks . end ( ) ; + + it )
2013-11-29 15:32:49 +01:00
it - > second - > collectVariables ( eParameter , mod_file_struct . parameters_within_shocks_values ) ;
2013-11-29 14:50:58 +01:00
for ( covar_and_corr_shocks_t : : const_iterator it = covar_shocks . begin ( ) ;
it ! = covar_shocks . end ( ) ; + + it )
2013-11-29 15:32:49 +01:00
it - > second - > collectVariables ( eParameter , mod_file_struct . parameters_within_shocks_values ) ;
2013-11-29 14:50:58 +01:00
for ( covar_and_corr_shocks_t : : const_iterator it = corr_shocks . begin ( ) ;
it ! = corr_shocks . end ( ) ; + + it )
2013-11-29 15:32:49 +01:00
it - > second - > collectVariables ( eParameter , mod_file_struct . parameters_within_shocks_values ) ;
2014-04-10 11:54:49 +02:00
2008-02-03 11:28:36 +01:00
}
2014-04-10 11:54:49 +02:00
bool
ShocksStatement : : has_calibrated_measurement_errors ( ) const
{
for ( var_and_std_shocks_t : : const_iterator it = var_shocks . begin ( ) ;
it ! = var_shocks . end ( ) ; it + + )
if ( symbol_table . isObservedVariable ( it - > first ) )
return true ;
for ( var_and_std_shocks_t : : const_iterator it = std_shocks . begin ( ) ;
it ! = std_shocks . end ( ) ; it + + )
if ( symbol_table . isObservedVariable ( it - > first ) )
return true ;
for ( covar_and_corr_shocks_t : : const_iterator it = covar_shocks . begin ( ) ;
it ! = covar_shocks . end ( ) ; it + + )
if ( symbol_table . isObservedVariable ( it - > first . first )
| | symbol_table . isObservedVariable ( it - > first . second ) )
return true ;
for ( covar_and_corr_shocks_t : : const_iterator it = corr_shocks . begin ( ) ;
it ! = corr_shocks . end ( ) ; it + + )
if ( symbol_table . isObservedVariable ( it - > first . first )
| | symbol_table . isObservedVariable ( it - > first . second ) )
return true ;
return false ;
}
MShocksStatement : : MShocksStatement ( bool overwrite_arg ,
const det_shocks_t & det_shocks_arg ,
2008-02-03 11:28:36 +01:00
const SymbolTable & symbol_table_arg ) :
2014-04-10 11:54:49 +02:00
AbstractShocksStatement ( true , overwrite_arg , det_shocks_arg , symbol_table_arg )
2008-02-03 11:28:36 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
MShocksStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2008-02-03 11:28:36 +01:00
{
2008-06-16 18:33:28 +02:00
output < < " % " < < endl
2009-10-29 18:16:10 +01:00
< < " % MSHOCKS instructions " < < endl
2008-06-16 18:33:28 +02:00
< < " % " < < endl ;
2008-02-03 11:28:36 +01:00
2014-04-10 11:54:49 +02:00
if ( overwrite )
output < < " M_.det_shocks = []; " < < endl ;
2008-02-03 11:28:36 +01:00
writeDetShocks ( output ) ;
}
2009-10-16 19:23:57 +02:00
2016-09-06 14:43:06 +02:00
ConditionalForecastPathsStatement : : ConditionalForecastPathsStatement ( const AbstractShocksStatement : : det_shocks_t & paths_arg ,
const SymbolTable & symbol_table_arg ) :
2009-10-16 19:23:57 +02:00
paths ( paths_arg ) ,
2016-09-06 14:43:06 +02:00
symbol_table ( symbol_table_arg ) ,
2009-10-16 19:23:57 +02:00
path_length ( - 1 )
{
}
void
2012-02-02 21:10:47 +01:00
ConditionalForecastPathsStatement : : checkPass ( ModFileStructure & mod_file_struct , WarningConsolidation & warnings )
2009-10-16 19:23:57 +02:00
{
2010-09-16 19:00:48 +02:00
for ( AbstractShocksStatement : : det_shocks_t : : const_iterator it = paths . begin ( ) ;
2009-12-16 18:13:23 +01:00
it ! = paths . end ( ) ; it + + )
2009-10-16 19:23:57 +02:00
{
int this_path_length = 0 ;
2013-12-31 01:57:30 +01:00
const vector < AbstractShocksStatement : : DetShockElement > & elems = it - > second ;
2009-12-16 18:13:23 +01:00
for ( int i = 0 ; i < ( int ) elems . size ( ) ; i + + )
2009-10-16 19:23:57 +02:00
// Period1 < Period2, as enforced in ParsingDriver::add_period()
this_path_length = max ( this_path_length , elems [ i ] . period2 ) ;
if ( path_length = = - 1 )
path_length = this_path_length ;
else if ( path_length ! = this_path_length )
{
cerr < < " conditional_forecast_paths: all constrained paths must have the same length! " < < endl ;
exit ( EXIT_FAILURE ) ;
}
}
}
void
2015-05-28 11:42:12 +02:00
ConditionalForecastPathsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2009-10-16 19:23:57 +02:00
{
assert ( path_length > 0 ) ;
output < < " constrained_vars_ = []; " < < endl
< < " constrained_paths_ = zeros( " < < paths . size ( ) < < " , " < < path_length < < " ); " < < endl ;
int k = 1 ;
2010-09-16 19:00:48 +02:00
for ( AbstractShocksStatement : : det_shocks_t : : const_iterator it = paths . begin ( ) ;
2016-09-06 14:58:09 +02:00
it ! = paths . end ( ) ; it + + , k + + )
2009-10-16 19:23:57 +02:00
{
2010-09-26 13:42:41 +02:00
if ( it = = paths . begin ( ) )
2016-09-06 14:58:09 +02:00
output < < " constrained_vars_ = " < < symbol_table . getTypeSpecificID ( it - > first ) + 1 < < " ; " < < endl ;
2010-09-26 13:42:41 +02:00
else
2016-09-06 14:58:09 +02:00
output < < " constrained_vars_ = [constrained_vars_; " < < symbol_table . getTypeSpecificID ( it - > first ) + 1 < < " ]; " < < endl ;
2010-09-26 13:42:41 +02:00
2013-12-31 01:57:30 +01:00
const vector < AbstractShocksStatement : : DetShockElement > & elems = it - > second ;
2009-12-16 18:13:23 +01:00
for ( int i = 0 ; i < ( int ) elems . size ( ) ; i + + )
for ( int j = elems [ i ] . period1 ; j < = elems [ i ] . period2 ; j + + )
2009-10-16 19:23:57 +02:00
{
output < < " constrained_paths_( " < < k < < " , " < < j < < " )= " ;
elems [ i ] . value - > writeOutput ( output ) ;
output < < " ; " < < endl ;
}
}
}
2014-02-10 19:22:54 +01:00
MomentCalibration : : MomentCalibration ( const constraints_t & constraints_arg ,
const SymbolTable & symbol_table_arg )
: constraints ( constraints_arg ) , symbol_table ( symbol_table_arg )
{
}
void
2015-05-28 11:42:12 +02:00
MomentCalibration : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-02-10 19:22:54 +01:00
{
2014-03-17 16:45:43 +01:00
output < < " options_.endogenous_prior_restrictions.moment = { " < < endl ;
2014-02-10 19:22:54 +01:00
for ( size_t i = 0 ; i < constraints . size ( ) ; i + + )
{
const Constraint & c = constraints [ i ] ;
output < < " ' " < < symbol_table . getName ( c . endo1 ) < < " ', "
< < " ' " < < symbol_table . getName ( c . endo2 ) < < " ', "
2014-03-17 18:10:44 +01:00
< < c . lags < < " , "
2014-02-10 19:22:54 +01:00
< < " [ " < < c . lower_bound < < " , " < < c . upper_bound < < " ]; "
< < endl ;
}
output < < " }; " < < endl ;
}
IrfCalibration : : IrfCalibration ( const constraints_t & constraints_arg ,
2015-09-07 11:39:33 +02:00
const SymbolTable & symbol_table_arg ,
const OptionsList & options_list_arg )
: constraints ( constraints_arg ) , symbol_table ( symbol_table_arg ) , options_list ( options_list_arg )
2014-02-10 19:22:54 +01:00
{
}
void
2015-05-28 11:42:12 +02:00
IrfCalibration : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
2014-02-10 19:22:54 +01:00
{
2015-09-07 11:39:33 +02:00
options_list . writeOutput ( output ) ;
2014-03-17 16:45:43 +01:00
output < < " options_.endogenous_prior_restrictions.irf = { " < < endl ;
2014-02-10 19:22:54 +01:00
for ( size_t i = 0 ; i < constraints . size ( ) ; i + + )
{
const Constraint & c = constraints [ i ] ;
output < < " ' " < < symbol_table . getName ( c . endo ) < < " ', "
< < " ' " < < symbol_table . getName ( c . exo ) < < " ', "
2014-03-17 18:10:44 +01:00
< < c . periods < < " , "
2014-02-10 19:22:54 +01:00
< < " [ " < < c . lower_bound < < " , " < < c . upper_bound < < " ]; "
< < endl ;
}
output < < " }; " < < endl ;
}
2016-04-10 18:55:17 +02:00
ShockGroupsStatement : : ShockGroupsStatement ( const group_t & shock_groups_arg , const string & name_arg )
: shock_groups ( shock_groups_arg ) , name ( name_arg )
{
}
void
ShockGroupsStatement : : writeOutput ( ostream & output , const string & basename , bool minimal_workspace ) const
{
2016-09-14 14:03:03 +02:00
int i = 1 ;
bool unique_label = true ;
for ( vector < Group > : : const_iterator it = shock_groups . begin ( ) ; it ! = shock_groups . end ( ) ; it + + , unique_label = true )
2016-04-10 18:55:17 +02:00
{
2016-09-14 14:03:03 +02:00
for ( vector < Group > : : const_iterator it1 = it + 1 ; it1 ! = shock_groups . end ( ) ; it1 + + )
if ( it - > name = = it1 - > name )
{
unique_label = false ;
cerr < < " Warning: shock group label ' " < < it - > name < < " ' has been reused. "
< < " Only using the last definition. " < < endl ;
break ;
}
if ( unique_label )
{
output < < " M_.shock_groups. " < < name
< < " .group " < < i < < " .label = ' " < < it - > name < < " '; " < < endl
< < " M_.shock_groups. " < < name
< < " .group " < < i < < " .shocks = { " ;
for ( vector < string > : : const_iterator it1 = it - > list . begin ( ) ; it1 ! = it - > list . end ( ) ; it1 + + )
output < < " ' " < < * it1 < < " ' " ;
output < < " }; " < < endl ;
i + + ;
}
2016-04-10 18:55:17 +02:00
}
}