-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (135 loc) · 7.02 KB
/
Copy pathmain.cpp
File metadata and controls
143 lines (135 loc) · 7.02 KB
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
#include "IndicatorsEasy.hpp"
#include "NormalizationEasy.hpp"
#include "CorrelationEasy.hpp"
#include "HistoricalDataEasy.hpp"
int main() {
// проверим Расстояние Левенштайна
const std::string src = "125678";
const std::string dst = "5216789";
const std::string::size_type distance = AlgorithmsEasy::calc_levenstein_distance(src, dst);
std::cout << "distance " << distance << std::endl;
std::vector<double> vec_src, vec_dst;
vec_src.push_back(0.1);
vec_src.push_back(0.2);
vec_src.push_back(0.5);
vec_dst.push_back(0.1);
vec_dst.push_back(0.3);
vec_dst.push_back(0.5);
const std::string::size_type vec_distance = AlgorithmsEasy::calc_generalized_levenstein_distance(vec_src, vec_dst);
std::cout << "vec_distance " << vec_distance << std::endl;
std::string path = "..//..//train_2//quotes_bars_data//frxEURGBP";
HistoricalDataEasy::HistoricalData hist(path);
hist.read_all_data();
int PERIOD_MA = 10;
int PERIOD_MW = 10;
int PERIOD_RSI = 5;
int PERIOD_BB = 20;
double STD_DEV_BB = 2;
IndicatorsEasy::WMA<double> wma(PERIOD_MA);
IndicatorsEasy::SMA<double> sma(PERIOD_MA);
IndicatorsEasy::EMA<double> ema(PERIOD_MA);
IndicatorsEasy::MW<double> mw(PERIOD_MW);
IndicatorsEasy::RSI<double, IndicatorsEasy::EMA<double>> rsi(PERIOD_RSI);
IndicatorsEasy::BollingerBands<double> bb(PERIOD_BB, STD_DEV_BB);
IndicatorsEasy::DetectorWaveform<double> dw(100);
/*
30, 240, 0.6
*/
const int CANDLE_SIZE = 60;
int status = 0;
while(status != hist.END_OF_DATA) {
double price = 0;
unsigned long long timestamp = 0;
hist.get_price(price, timestamp, status, CANDLE_SIZE);
//std::cout << "price: " << price << std::endl;
if(status == hist.SKIPPING_DATA) {
wma.clear();
sma.clear();
ema.clear();
mw.clear();
rsi.clear();
bb.clear();
dw.clear();
}
if(status == hist.NORMAL_DATA) {
double wma_out, sma_out, ema_out, rsi_out, bb_tl, bb_ml, bb_bl;
double dw_out;
if(rsi.update(price, rsi_out) == hist.OK) {
//std::cout << "rsi: " << rsi_out << std::endl;
}
if(dw.update(price, dw_out, 20) == hist.OK) {
//std::cout << "dw: " << dw_out << std::endl;
if(abs(rsi_out) > 80)
if(abs(dw_out) > 0.8) {
int state = 0;
if(dw_out > 0) {
hist.check_binary_option(state, hist.SELL, 180, timestamp);
} else
if(dw_out < 0) {
hist.check_binary_option(state, hist.BUY, 180, timestamp);
}
static int num_sum = 0;
static double sum = 0;
if(state == 1) {
sum += 1.0;
}
num_sum++;
std::cout << "eff " << (sum / (double)num_sum) << std::endl;
std::cout << num_sum << std::endl;
std::cout << xtime::get_str_unix_date_time(timestamp) << std::endl;
//int zz;
//std::cin >> zz;
//std::cout << zz << std::endl;
}
}
# if (0)
if(wma.update(price, wma_out) == hist.OK) {
std::cout << "wma: " << wma_out << std::endl;
}
if(sma.update(price, sma_out) == hist.OK) {
std::cout << "sma: " << sma_out << std::endl;
}
if(ema.update(price, ema_out) == hist.OK) {
std::cout << "ema: " << ema_out << std::endl;
}
if(rsi.update(price, rsi_out) == hist.OK) {
std::cout << "rsi: " << rsi_out << std::endl;
}
if(bb.update(price, bb_tl, bb_ml, bb_bl) == hist.OK) {
std::cout << "bb: " << bb_tl << " " << bb_ml << " " << bb_bl << std::endl;
}
std::vector<double> mw_out;
if(mw.update(price, mw_out) == hist.OK) {
std::cout << "mw:";
for(int i = 0; i < PERIOD_MW; ++i) {
std::cout << " " << mw_out[i];
}
std::cout << std::endl;
std::vector<double> mw_norm_out;
NormalizationEasy::calculate_min_max(mw_out, mw_norm_out, NormalizationEasy::MINMAX_1_1);
std::cout << "mw norm:";
for(size_t i = 0; i < mw_norm_out.size(); ++i) {
std::cout << " " << mw_norm_out[i];
mw_norm_out[i] += i * 0.1;
}
std::cout << std::endl;
double p = 0;
CorrelationEasy::calculate_spearman_rank_correlation_coefficient(mw_out, mw_norm_out, p);
std::cout << "spearman corr: " << p << std::endl;
double temp;
mw.get_std_data(temp);
std::cout << "mw std: " << temp << std::endl;
mw.get_average_data(temp);
std::cout << "mw aver: " << temp << std::endl;
mw.get_max_data(temp);
std::cout << "mw max: " << temp << std::endl;
mw.get_min_data(temp);
std::cout << "mw min: " << temp << std::endl;
std::cout << std::endl;
}
# endif
}
//std::cout << std::endl;
}
return 0;
}