Shocks.cc 5.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*! \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 "ModelParameters.hh"
#include "Interface.hh"

14
Shocks::Shocks() : mshock_flag(0), exo_det_length(0)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
154
155
156
157
158
159
160
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
187
188
189
190
191
192
193
194
195
{
  // Empty
}

//------------------------------------------------------------------------------
Shocks::~Shocks()
{
  // Empty
}

//------------------------------------------------------------------------------
void Shocks::setOutput(ostringstream* iOutput)
{
  output = iOutput;
}

//------------------------------------------------------------------------------
void Shocks::BeginShocks(void)
{
  mshock_flag = 0;
  // Writing a Matlab comment
  *output << interfaces::comment() << "\n" << interfaces::comment() << "SHOCKS instructions \n"
          << interfaces::comment() << "\n";
  //Writing intstruction that initialize a shocks
  *output << "make_ex_;\n";
}

//------------------------------------------------------------------------------
void Shocks::BeginMShocks(void)
{
  mshock_flag = 1;
  // Writing a Matlab comment
  *output << interfaces::comment() << "\n" << interfaces::comment() << "MSHOCKS instructions \n"
          << interfaces::comment() << "\n";
  //Writing intstruction that initialize a shocks
  *output << "make_ex_;\n";
}

void Shocks::EndShocks(void)
{
  *output << "M_.exo_det_length = " << exo_det_length << ";\n";
}

//------------------------------------------------------------------------------
void Shocks::AddDetShockExo(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 << "," << 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();
}

/*
  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
*/
//------------------------------------------------------------------------------
/*
  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);
}

//------------------------------------------------------------------------------