Shocks.cc 5.62 KB
Newer Older
michel's avatar
michel committed
1
2
3
4
5
6
7
8
9
/*! \file 
 \version 1.0
 \date 04/09/2004
 \par This file implements the Shocks class methodes.
*/
//------------------------------------------------------------------------------
#include <iostream>
using namespace std;
//------------------------------------------------------------------------------
sebastien's avatar
sebastien committed
10
11
12
#include "Shocks.hh"
#include "ModelParameters.hh"
#include "Interface.hh"
13
14
15
16

static int mshock_flag = 0;
static int exo_det_length = 0;

michel's avatar
michel committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//------------------------------------------------------------------------------
//ostringstream	Shocks::output;
//------------------------------------------------------------------------------
Shocks::Shocks()
{ 
	// Empty
}
//------------------------------------------------------------------------------
Shocks::~Shocks()
{
	// Empty
}
//------------------------------------------------------------------------------
void Shocks::setOutput(ostringstream* iOutput)
{
	output = iOutput;	
}
//------------------------------------------------------------------------------
void Shocks::BeginShocks(void)
{	
37
38
  mshock_flag = 0;
  // Writing a Matlab comment
39
40
  *output << interfaces::comment() << "\n" << interfaces::comment() << "SHOCKS instructions \n"
          << interfaces::comment() << "\n";
41
42
43
44
45
46
47
48
  //Writing intstruction that initialize a shocks 
  *output << "make_ex_;\n";
}							
//------------------------------------------------------------------------------
void Shocks::BeginMShocks(void)
{	
  mshock_flag = 1;
  // Writing a Matlab comment
49
50
  *output << interfaces::comment() << "\n" << interfaces::comment() << "MSHOCKS instructions \n"
          << interfaces::comment() << "\n";
51
52
53
54
55
56
  //Writing intstruction that initialize a shocks 
  *output << "make_ex_;\n";
}
void Shocks::EndShocks(void)
{
  *output << "M_.exo_det_length = " << exo_det_length << ";\n";
michel's avatar
michel committed
57
58
}							
//------------------------------------------------------------------------------
59
void Shocks::AddDetShockExo(int id1)
michel's avatar
michel committed
60
{
61
62
63
64
65
66
67
68
69
70
71
  if (mPeriod1.size() != mPeriod2.size() ||
      mPeriod1.size() != mValues.size())
    {
      string msg = "in shocks statement, number of periods and values dont agree";
      (* error) (msg.c_str());
    }
  for (unsigned int i = 0; i < mPeriod1.size(); i++)
    {
      string period1 = mPeriod1[i];
      string period2 = mPeriod2[i];
      if (period1 == period2)
michel's avatar
michel committed
72
	{
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	  *output << "set_shocks(" << mshock_flag << "," << period1 
		  << ", " << id1+1 << ", " << mValues[i] 
		  << ");\n";
	}
      else
	{
	  *output << "set_shocks(" << mshock_flag << "," << period1
		  << ":" << period2 << ", " << id1+1 
		  << ", " << mValues[i] << ");\n";
	}
    }
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
}
void Shocks::AddDetShockExoDet(int id1)
{
  if (mPeriod1.size() != mPeriod2.size() ||
      mPeriod1.size() != mValues.size())
    {
      string msg = "in shocks statement, number of periods and values dont agree";
      (* error) (msg.c_str());
    }
  for (unsigned int i = 0; i < mPeriod1.size(); i++)
    {
      string period1 = mPeriod1[i];
      string period2 = mPeriod2[i];
      if (period1 == period2)
	{
	  *output << "set_shocks(" << mshock_flag + 2 << "," << period1 
		  << ", " << id1+1 << ", " << mValues[i] 
		  << ");\n";
	}
      else
	{
	  *output << "set_shocks(" << mshock_flag+2 << "," << period1
		  << ":" << period2 << ", " << id1+1 
		  << ", " << mValues[i] << ");\n";
	}
      int p2_int = atoi(period2.c_str()); 
      if (p2_int > exo_det_length)
	{
	  exo_det_length = p2_int;
	}
    }
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
}
void Shocks::AddSTDShock(int id1, std::string value)
{
  *output << "M_.Sigma_e(" << id1+1 << ", " << id1+1 << ") = " << value << "^2;\n";
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
}
void Shocks::AddVARShock(int id1, std::string value)
{
  *output << "M_.Sigma_e(" << id1+1 << ", " << id1+1 << ") = " << value << ";\n";
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
}
void Shocks::AddCOVAShock(int id1, int id2 , std::string value)
{
  *output << "M_.Sigma_e(" << id1+1 << ", " << id2+1 << ") = " <<	value <<
    "; M_.Sigma_e(" << id2+1 << ", " << id1+1 << ") = M_.Sigma_e(" << 
    id1+1 << ", " << id2+1 << ");\n";
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
}
void Shocks::AddCORRShock(int id1, int id2 , std::string value)
{
  *output << "M_.Sigma_e(" << id1+1 << ", " << id2+1 << ") = " <<
    value << "*sqrt(M_.Sigma_e(" << id1 << ", " << id1+1 << ")*M_.Sigma_e(" <<
    id2 << ", " << id2+1 << "); M_.Sigma_e(" << id2+1 << ", " << 
    id1 << ") = M_.Sigma_e(" << id1+1 << ", " << id2+1 << ");\n";
  mPeriod1.clear();
  mPeriod2.clear();
  mValues.clear();
michel's avatar
michel committed
154
}
155
156
157
158
159
160
  /*
    sets a shock 
    for type == 0, set type, id1, shock_elem will be set by another method
    for type == 1 or 2 set type, id1 and value
    for type == 3 or 4 set type, id1, id2 and value
  */
michel's avatar
michel committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//------------------------------------------------------------------------------
/*
string Shocks::get(void)
{
	return output.str();
}
*/
//------------------------------------------------------------------------------
void Shocks::AddPeriod(string p1, string p2)
{
	mPeriod1.push_back(p1);
	mPeriod2.push_back(p2);
}
//------------------------------------------------------------------------------
void Shocks::AddPeriod(string p1)
{
	mPeriod1.push_back(p1);
	mPeriod2.push_back(p1);

}
//------------------------------------------------------------------------------
void Shocks::AddValue(string value)
{
	mValues.push_back(value);
}
//------------------------------------------------------------------------------