2006-11-05 00:31:17 +01:00
|
|
|
/*! \file
|
|
|
|
\version 1.0
|
|
|
|
\date 04/09/2004
|
|
|
|
\par This file implements the Shocks class methodes.
|
|
|
|
*/
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#include "Shocks.hh"
|
|
|
|
#include "Interface.hh"
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
AbstractShocksStatement::AbstractShocksStatement(bool mshocks_arg,
|
|
|
|
const det_shocks_type &det_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &var_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &std_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &covar_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &corr_shocks_arg,
|
|
|
|
const SymbolTable &symbol_table_arg) :
|
|
|
|
mshocks(mshocks_arg),
|
|
|
|
det_shocks(det_shocks_arg),
|
|
|
|
var_shocks(var_shocks_arg),
|
|
|
|
std_shocks(std_shocks_arg),
|
|
|
|
covar_shocks(covar_shocks_arg),
|
|
|
|
corr_shocks(corr_shocks_arg),
|
|
|
|
symbol_table(symbol_table_arg)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
|
|
|
AbstractShocksStatement::writeDetShocks(ostream &output) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
int exo_det_length = 0;
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
for(det_shocks_type::const_iterator it = det_shocks.begin();
|
|
|
|
it != det_shocks.end(); it++)
|
|
|
|
{
|
|
|
|
int id = symbol_table.getID(it->first) + 1;
|
|
|
|
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet);
|
|
|
|
int set_shocks_index = ((int) mshocks) + 2 * ((int) exo_det);
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
for (unsigned int i = 0; i < it->second.size(); i++)
|
|
|
|
{
|
|
|
|
const int &period1 = it->second[i].period1;
|
|
|
|
const int &period2 = it->second[i].period2;
|
2007-03-09 18:27:46 +01:00
|
|
|
const NodeID value = it->second[i].value;
|
2006-12-12 12:54:30 +01:00
|
|
|
|
|
|
|
if (period1 == period2)
|
2007-03-09 18:27:46 +01:00
|
|
|
{
|
|
|
|
output << "set_shocks(" << set_shocks_index << "," << period1
|
|
|
|
<< ", " << id << ", ";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << ");" << endl;
|
|
|
|
}
|
2006-12-12 12:54:30 +01:00
|
|
|
else
|
2007-03-09 18:27:46 +01:00
|
|
|
{
|
|
|
|
output << "set_shocks(" << set_shocks_index << "," << period1
|
|
|
|
<< ":" << period2 << ", " << id << ", ";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << ");" << endl;
|
|
|
|
}
|
2006-12-12 12:54:30 +01:00
|
|
|
|
|
|
|
if (exo_det && (period2 > exo_det_length))
|
|
|
|
exo_det_length = period2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output << "M_.exo_det_length = " << exo_det_length << ";\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
|
|
|
AbstractShocksStatement::writeVarAndStdShocks(ostream &output) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
var_and_std_shocks_type::const_iterator it;
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
for(it = var_shocks.begin(); it != var_shocks.end(); it++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
int id = symbol_table.getID(it->first) + 1;
|
2007-03-09 18:27:46 +01:00
|
|
|
const NodeID value = it->second;
|
|
|
|
output << "M_.Sigma_e(" << id << ", " << id << ") = ";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << ";" << endl;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2006-12-12 12:54:30 +01:00
|
|
|
|
|
|
|
for(it = std_shocks.begin(); it != std_shocks.end(); it++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
int id = symbol_table.getID(it->first) + 1;
|
2007-03-09 18:27:46 +01:00
|
|
|
const NodeID value = it->second;
|
|
|
|
output << "M_.Sigma_e(" << id << ", " << id << ") = (";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << ")^2;" << endl;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
|
|
|
AbstractShocksStatement::writeCovarAndCorrShocks(ostream &output) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
covar_and_corr_shocks_type::const_iterator it;
|
|
|
|
|
|
|
|
for(it = covar_shocks.begin(); it != covar_shocks.end(); it++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
int id1 = symbol_table.getID(it->first.first) + 1;
|
|
|
|
int id2 = symbol_table.getID(it->first.second) + 1;
|
2007-03-09 18:27:46 +01:00
|
|
|
const NodeID value = it->second;
|
|
|
|
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = ";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << "; M_.Sigma_e(" << id2 << ", " << id1 << ") = M_.Sigma_e("
|
2006-12-12 12:54:30 +01:00
|
|
|
<< id1 << ", " << id2 << ");\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2006-12-12 12:54:30 +01:00
|
|
|
|
|
|
|
for(it = corr_shocks.begin(); it != corr_shocks.end(); it++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
int id1 = symbol_table.getID(it->first.first) + 1;
|
|
|
|
int id2 = symbol_table.getID(it->first.second) + 1;
|
2007-03-09 18:27:46 +01:00
|
|
|
const NodeID value = it->second;
|
|
|
|
output << "M_.Sigma_e(" << id1 << ", " << id2 << ") = ";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << "*sqrt(M_.Sigma_e(" << id1 << ", " << id1 << ")*M_.Sigma_e("
|
2006-12-12 12:54:30 +01:00
|
|
|
<< id2 << ", " << id2 << "); M_.Sigma_e(" << id2 << ", "
|
|
|
|
<< id1 << ") = M_.Sigma_e(" << id1 << ", " << id2 << ");\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
ShocksStatement::ShocksStatement(const det_shocks_type &det_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &var_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &std_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &covar_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &corr_shocks_arg,
|
|
|
|
const SymbolTable &symbol_table_arg) :
|
|
|
|
AbstractShocksStatement(false, det_shocks_arg, var_shocks_arg, std_shocks_arg,
|
|
|
|
covar_shocks_arg, corr_shocks_arg, symbol_table_arg)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
2006-12-19 00:28:52 +01:00
|
|
|
ShocksStatement::writeOutput(ostream &output, const string &basename) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
output << interfaces::comment() << endl << interfaces::comment();
|
|
|
|
output << "SHOCKS instructions \n";
|
|
|
|
output << interfaces::comment() << "\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
// Write instruction that initializes a shock
|
|
|
|
output << "make_ex_;\n";
|
|
|
|
|
|
|
|
writeDetShocks(output);
|
|
|
|
writeVarAndStdShocks(output);
|
|
|
|
writeCovarAndCorrShocks(output);
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
MShocksStatement::MShocksStatement(const det_shocks_type &det_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &var_shocks_arg,
|
|
|
|
const var_and_std_shocks_type &std_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &covar_shocks_arg,
|
|
|
|
const covar_and_corr_shocks_type &corr_shocks_arg,
|
|
|
|
const SymbolTable &symbol_table_arg) :
|
|
|
|
AbstractShocksStatement(true, det_shocks_arg, var_shocks_arg, std_shocks_arg,
|
|
|
|
covar_shocks_arg, corr_shocks_arg, symbol_table_arg)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
2006-12-19 00:28:52 +01:00
|
|
|
MShocksStatement::writeOutput(ostream &output, const string &basename) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-12-12 12:54:30 +01:00
|
|
|
output << interfaces::comment() << endl << interfaces::comment();
|
|
|
|
output << "SHOCKS instructions \n";
|
|
|
|
output << interfaces::comment() << "\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
// Write instruction that initializes a shock
|
|
|
|
output << "make_ex_;\n";
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
writeDetShocks(output);
|
|
|
|
writeVarAndStdShocks(output);
|
|
|
|
writeCovarAndCorrShocks(output);
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|