-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathUtils.h
More file actions
96 lines (78 loc) · 2.24 KB
/
Utils.h
File metadata and controls
96 lines (78 loc) · 2.24 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
#pragma once
#include <cpprest/json.h>
#include <iostream>
#include <stdlib.h>
using namespace std::chrono;
web::json::value readJsonFile(std::string const &jsonFileName)
{
web::json::value output;
try
{
std::ifstream f(jsonFileName);
std::stringstream strStream;
strStream << f.rdbuf();
f.close();
output = web::json::value::parse(strStream);
}
catch (web::json::json_exception excep)
{
throw web::json::json_exception("Error Parsing JSON file " + jsonFileName);
}
return output;
}
void getTime(long &time)
{
struct timeval tp;
gettimeofday(&tp, NULL);
time = (long)tp.tv_sec * 1000L + tp.tv_usec / 1000;
}
inline auto binary_to_hex_digit(unsigned a) -> char
{
return a + (a < 10 ? '0' : 'a' - 10);
}
auto binary_to_hex(unsigned char const *binary, unsigned binary_len) -> std::string
{
std::string r(binary_len * 2, '\0');
for (unsigned i = 0; i < binary_len; ++i)
{
r[i * 2] = binary_to_hex_digit(binary[i] >> 4);
r[i * 2 + 1] = binary_to_hex_digit(binary[i] & 15);
}
return r;
}
void benchmarkPerformance(void fnc())
{
auto t1 = high_resolution_clock::now();
fnc();
auto t2 = high_resolution_clock::now();
duration<double, std::milli> ms_double = t2 - t1;
std::cout << ms_double.count() << "ms\n";
}
void printHistoricalData(const TechnicalAnalysis &technicalAnalysis)
{
for (double openPrice : technicalAnalysis.data.open)
{
std::cout << std::setprecision(10) << openPrice << "\n";
}
for (double closePrice : technicalAnalysis.data.close)
{
std::cout << std::setprecision(10) << closePrice << "\n";
}
for (double ema : technicalAnalysis.data.fiftyEMA)
{
std::cout << std::setprecision(10) << ema << ", ";
}
std::cout << std::endl
<< "------------------------" << std::endl;
for (double ema : technicalAnalysis.tempData.close)
{
std::cout << std::setprecision(10) << ema << ", ";
}
std::cout << std::endl
<< "------------------------" << std::endl;
for (double ema : technicalAnalysis.data.fiftyEMA)
{
std::cout << std::setprecision(10) << ema << ", ";
}
std::cout << std::endl;
}