-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathntradetgtab.h
236 lines (208 loc) · 8 KB
/
ntradetgtab.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#ifndef NTRADETGTAB_H
#define NTRADETGTAB_H
#include "narray.h"
#include "nmatrix.h"
#include "iobjectecsv.h"
#include "neuroproject.h"
#include "ntrade.h"
#include <string>
using namespace std;
template <typename NType>
struct NTradeTgTab: public IObjectECSV
{
NArray<string> date;
NArray<string> time;
NArray<NType> open_real;
NArray<NType> high_real;
NArray<NType> low_real;
NArray<NType> close_real;
NArray<NType> volume_real;
NArray<NType> high_calc;
NArray<NType> low_calc;
NArray<NType> energy;
NArray<NSetType> typeExample;
int getLenRow();
int getLenColumn();
void init(int len);
void deinit();
void convertMatrix(NMatrix<string>& mtrx);
NMatrix<string>& toMatrix(NMatrix<string>& mtrx);
void copyData(NTradeTgTab<NType>& obj, NSetType st);
virtual void saveECSV(DataECSV& dt, string& parent);
virtual void loadECSV(DataECSV& dt, string& parent);
};
template <typename NType>
int NTradeTgTab<NType>::getLenRow()
{
return this->close_real.getLength();
}
template <typename NType>
int NTradeTgTab<NType>::getLenColumn()
{
if(this->high_calc.empty() || this->low_calc.empty()) {return 7;}
else if(this->typeExample.empty()) {return 10;}
else {return 11;}
}
template <typename NType>
void NTradeTgTab<NType>::init(int len)
{
this->date.init(len, "");
this->time.init(len, "");
this->open_real.init(len, 0);
this->high_real.init(len, 0);
this->low_real.init(len, 0);
this->close_real.init(len, 0);
this->volume_real.init(len, 0);
this->high_calc.init(len, 0);
this->low_calc.init(len, 0);
this->energy.init(len, 0);
this->typeExample.init(len, NSetType::NSetNone);
}
template <typename NType>
void NTradeTgTab<NType>::deinit()
{
this->date.clear();
this->time.clear();
this->open_real.clear();
this->high_real.clear();
this->low_real.clear();
this->close_real.clear();
this->volume_real.clear();
this->high_calc.clear();
this->low_calc.clear();
this->energy.clear();
this->typeExample.clear();
}
template <typename NType>
void NTradeTgTab<NType>::convertMatrix(NMatrix<string>& mtrx)
{
vector<string> str_vec;
mtrx.getColumn(0, this->date);
mtrx.getColumn(1, this->time);
mtrx.getColumn(2, str_vec); to_array_value(this->open_real, str_vec);
mtrx.getColumn(3, str_vec); to_array_value(this->high_real, str_vec);
mtrx.getColumn(4, str_vec); to_array_value(this->low_real, str_vec);
mtrx.getColumn(5, str_vec); to_array_value(this->close_real, str_vec);
mtrx.getColumn(6, str_vec); to_array_value(this->volume_real, str_vec);
if(mtrx.getLenColumn() >= 10)
{
mtrx.getColumn(7, str_vec); to_array_value(this->high_calc, str_vec);
mtrx.getColumn(8, str_vec); to_array_value(this->low_calc, str_vec);
mtrx.getColumn(9, str_vec); to_array_value(this->energy, str_vec);
}
if(mtrx.getLenColumn() >= 11)
{
mtrx.getColumn(10, str_vec); to_array_value(this->typeExample, str_vec);
}
}
template <typename NType>
NMatrix<string>& NTradeTgTab<NType>::toMatrix(NMatrix<string>& mtrx)
{
vector<string> str_vec;
mtrx.clear();
if(this->date.empty() || this->time.empty())
{
mtrx.init(this->getLenRow(), 2, "");
}
else
{
mtrx.pushColumn(this->date);
mtrx.pushColumn(this->time);
}
to_array_string(str_vec, this->open_real); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->high_real); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->low_real); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->close_real); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->volume_real); mtrx.pushColumn(str_vec);
if (!this->high_calc.empty() && !this->low_calc.empty())
{
to_array_string(str_vec, this->high_calc); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->low_calc); mtrx.pushColumn(str_vec);
to_array_string(str_vec, this->energy); mtrx.pushColumn(str_vec);
}
if(!this->typeExample.empty())
{
to_array_string(str_vec, this->typeExample); mtrx.pushColumn(str_vec);
}
return mtrx;
}
template <typename NType>
void NTradeTgTab<NType>::copyData(NTradeTgTab<NType>& obj, NSetType st)
{
this->deinit();
for(int ind = 0; ind < obj.date.getLength(); ind++)
{
if(obj.typeExample[ind] == st)
{
this->date.push(obj.date[ind]);
this->time.push(obj.time[ind]);
this->open_real.push(obj.open_real[ind]);
this->high_real.push(obj.high_real[ind]);
this->low_real.push(obj.low_real[ind]);
this->close_real.push(obj.close_real[ind]);
this->volume_real.push(obj.volume_real[ind]);
this->high_calc.push(obj.high_calc[ind]);
this->low_calc.push(obj.low_calc[ind]);
this->energy.push(obj.energy[ind]);
this->typeExample.push(st);
}
}
}
template <typename NType>
void NTradeTgTab<NType>::saveECSV(DataECSV& dt, string& parent)
{
//NMatrix<string> str_mtrx;
vector<string> str_vec;
//string str_val;
//string field;
dt.addGroup(parent, "");
dt.addString(parent, "date", this->date);
dt.addString(parent, "time", this->time);
to_array_string(str_vec, this->open_real); dt.addElement(parent, "open_real", str_vec, typeid(NType).name());
to_array_string(str_vec, this->high_real); dt.addElement(parent, "high_real", str_vec, typeid(NType).name());
to_array_string(str_vec, this->low_real); dt.addElement(parent, "low_real", str_vec, typeid(NType).name());
to_array_string(str_vec, this->close_real); dt.addElement(parent, "close_real", str_vec, typeid(NType).name());
to_array_string(str_vec, this->volume_real); dt.addElement(parent, "volume_real", str_vec, typeid(NType).name());
to_array_string(str_vec, this->high_calc); dt.addElement(parent, "high_calc", str_vec, typeid(NType).name());
to_array_string(str_vec, this->low_calc); dt.addElement(parent, "low_calc", str_vec, typeid(NType).name());
to_array_string(str_vec, this->energy); dt.addElement(parent, "energy", str_vec, typeid(NType).name());
to_array_string(str_vec, this->typeExample); dt.addElement(parent, "typeExample", str_vec, typeid(NType).name());
}
template <typename NType>
void NTradeTgTab<NType>::loadECSV(DataECSV& dt, string& parent)
{
StructECSV* iter;
//NMatrix<string> str_mtrx;
vector<string> str_vec;
//string str_val;
this->deinit();
if(dt.isOneMatrix())
{
iter = dt.modules[0];
this->convertMatrix(iter->mtrx);
}
else
{
size_t ind = dt.getShift();
iter = dt.modules[ind];
if(iter->cmpPath(parent, true)) {ind++;}
while(dt.isNextBlock(ind, parent))
{
iter = dt.modules[ind];
if(iter->getFieldValue(parent, "date", this->date)) {;}
else if(iter->getFieldValue(parent, "time", this->time)) {;}
else if(iter->getFieldValue(parent, "open_real", str_vec)) {to_array_value(this->open_real, str_vec);}
else if(iter->getFieldValue(parent, "high_real", str_vec)) {to_array_value(this->high_real, str_vec);}
else if(iter->getFieldValue(parent, "low_real", str_vec)) {to_array_value(this->low_real, str_vec);}
else if(iter->getFieldValue(parent, "close_real", str_vec)) {to_array_value(this->close_real, str_vec);}
else if(iter->getFieldValue(parent, "volume_real", str_vec)) {to_array_value(this->volume_real, str_vec);}
else if(iter->getFieldValue(parent, "high_calc", str_vec)) {to_array_value(this->high_calc, str_vec);}
else if(iter->getFieldValue(parent, "low_calc", str_vec)) {to_array_value(this->low_calc, str_vec);}
else if(iter->getFieldValue(parent, "energy", str_vec)) {to_array_value(this->energy, str_vec);}
else if(iter->getFieldValue(parent, "typeExample", str_vec)) {to_array_value(this->typeExample, str_vec);}
ind++;
}
dt.setShift(ind);
}
}
#endif // NTRADETGTAB_H