Skip to content

Commit 48ade5b

Browse files
committed
добавлен класс для тестирования бинарных опционов
1 parent 4ba8ce4 commit 48ade5b

10 files changed

Lines changed: 760 additions & 38 deletions

File tree

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@
2525
[submodule "lib/xwave"]
2626
path = lib/xwave
2727
url = https://github.com/NewYaroslav/xwave.git
28+
[submodule "lib/imgui"]
29+
path = lib/imgui
30+
url = https://github.com/ocornut/imgui.git
31+
[submodule "lib/imgui-sfml"]
32+
path = lib/imgui-sfml
33+
url = https://github.com/eliasdaler/imgui-sfml.git

example/test_indicators/main.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
#include "HistoricalDataEasy.hpp"
55

66
int main() {
7-
std::string path = "..//..//train_2//quotes_bars_data//frxAUDCAD";
7+
std::string path = "..//..//train_2//quotes_bars_data//frxEURGBP";
88
HistoricalDataEasy::HistoricalData hist(path);
99
hist.read_all_data();
1010

1111
int PERIOD_MA = 10;
1212
int PERIOD_MW = 10;
13-
int PERIOD_RSI = 10;
13+
int PERIOD_RSI = 5;
1414
int PERIOD_BB = 20;
1515
double STD_DEV_BB = 2;
1616
IndicatorsEasy::WMA<double> wma(PERIOD_MA);
@@ -19,24 +19,59 @@ int main() {
1919
IndicatorsEasy::MW<double> mw(PERIOD_MW);
2020
IndicatorsEasy::RSI<double, IndicatorsEasy::EMA<double>> rsi(PERIOD_RSI);
2121
IndicatorsEasy::BollingerBands<double> bb(PERIOD_BB, STD_DEV_BB);
22+
IndicatorsEasy::DetectorWaveform<double> dw(100);
23+
/*
24+
30, 240, 0.6
25+
*/
2226
const int CANDLE_SIZE = 60;
2327

2428
int status = 0;
2529
while(status != hist.END_OF_DATA) {
2630
double price = 0;
2731
unsigned long long timestamp = 0;
2832
hist.get_price(price, timestamp, status, CANDLE_SIZE);
29-
std::cout << "price: " << price << std::endl;
33+
//std::cout << "price: " << price << std::endl;
3034
if(status == hist.SKIPPING_DATA) {
3135
wma.clear();
3236
sma.clear();
3337
ema.clear();
3438
mw.clear();
3539
rsi.clear();
3640
bb.clear();
41+
dw.clear();
3742
}
3843
if(status == hist.NORMAL_DATA) {
3944
double wma_out, sma_out, ema_out, rsi_out, bb_tl, bb_ml, bb_bl;
45+
double dw_out;
46+
if(rsi.update(price, rsi_out) == hist.OK) {
47+
//std::cout << "rsi: " << rsi_out << std::endl;
48+
}
49+
if(dw.update(price, dw_out, 20) == hist.OK) {
50+
//std::cout << "dw: " << dw_out << std::endl;
51+
if(abs(rsi_out) > 80)
52+
if(abs(dw_out) > 0.8) {
53+
int state = 0;
54+
if(dw_out > 0) {
55+
hist.check_binary_option(state, hist.SELL, 180, timestamp);
56+
} else
57+
if(dw_out < 0) {
58+
hist.check_binary_option(state, hist.BUY, 180, timestamp);
59+
}
60+
static int num_sum = 0;
61+
static double sum = 0;
62+
if(state == 1) {
63+
sum += 1.0;
64+
}
65+
num_sum++;
66+
std::cout << "eff " << (sum / (double)num_sum) << std::endl;
67+
std::cout << num_sum << std::endl;
68+
std::cout << xtime::get_str_unix_date_time(timestamp) << std::endl;
69+
//int zz;
70+
//std::cin >> zz;
71+
//std::cout << zz << std::endl;
72+
}
73+
}
74+
# if (0)
4075
if(wma.update(price, wma_out) == hist.OK) {
4176
std::cout << "wma: " << wma_out << std::endl;
4277
}
@@ -83,8 +118,9 @@ int main() {
83118
std::cout << "mw min: " << temp << std::endl;
84119
std::cout << std::endl;
85120
}
121+
# endif
86122
}
87-
std::cout << std::endl;
123+
//std::cout << std::endl;
88124
}
89125
return 0;
90126
}

example/test_sounds/main.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#include "WavEasy.hpp"
66

77
int main() {
8-
std::string path = "..//..//..//binary_historical_data//quotes_bars_data//R_25";
8+
std::string name = "frxEURCHF";
9+
std::string path = "..//..//..//binary_historical_data//quotes_bars_data//" + name;
910
HistoricalDataEasy::HistoricalData hist(path, "quotes_bars.zstd");
1011
hist.read_all_data();
1112
std::vector<double> norm_prices;
@@ -17,15 +18,21 @@ int main() {
1718
std::cout << "prices size: " << prices.size() << std::endl;
1819
std::vector<unsigned long long> times = hist.get_array_times();
1920
NormalizationEasy::calculate_difference(prices, norm_prices);
20-
NormalizationEasy::calculate_min_max(norm_prices, norm_prices, NormalizationEasy::MINMAX_1_1);
21+
NormalizationEasy::normalize_amplitudes(norm_prices, norm_prices, 1.0);
2122
if(norm_prices.size() == 0) {
2223
std::cout << "error!" << std::endl;
2324
return 0;
2425
}
2526
std::cout << "save sounds" << std::endl;
26-
std::cout << "date beg: " << xtime::get_str_unix_date_time(times[0]) << std::endl;
27-
std::cout << "date end: " << xtime::get_str_unix_date_time(times.back()) << std::endl;
28-
WavEasy::SoundRecording wav("test");
27+
xtime::DateTime startTime(times[0]);
28+
xtime::DateTime stopTime(times.back());
29+
30+
31+
std::cout << "date beg: " << startTime.get_str_date_time() << std::endl;
32+
std::cout << "date end: " << stopTime.get_str_date_time() << std::endl;
33+
std::string wav_file_name = name + "_" + std::to_string(startTime.day) + "_" + std::to_string(startTime.month) + "_" + std::to_string(startTime.year) +
34+
"_TO_" + std::to_string(stopTime.day) + "_" + std::to_string(stopTime.month) + "_" + std::to_string(stopTime.year);
35+
WavEasy::SoundRecording wav(wav_file_name,16000);
2936
for(size_t i = 0; i < norm_prices.size(); ++i) {
3037
wav.update(norm_prices[i]);
3138
}

include/BinaryApiEasy.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ namespace BinaryApiEasy
146146
std::vector<double> &prices,
147147
std::vector<unsigned long long> &times)
148148
{
149-
// сохраняем
150149
std::ofstream file(file_name, std::ios_base::binary);
151150
unsigned long data_size = times.size();
152151
file.write(reinterpret_cast<char *>(&data_size),sizeof (data_size));
@@ -166,7 +165,6 @@ namespace BinaryApiEasy
166165
std::vector<double> &prices,
167166
std::vector<unsigned long long> &times)
168167
{
169-
// сохраняем
170168
std::ifstream file(file_name, std::ios_base::binary);
171169
if(!file)
172170
return FILE_CANNOT_OPENED;

0 commit comments

Comments
 (0)