forked from taitashaw/HLS_FPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHFT_volatility_engine_tb.cpp
More file actions
42 lines (34 loc) · 1.08 KB
/
Copy pathHFT_volatility_engine_tb.cpp
File metadata and controls
42 lines (34 loc) · 1.08 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
/*** By John Bagshaw ***/
#include "HFT_volatility_engine.hpp"
#include <iostream>
#include <cmath>
#include <cstdlib>
#define USE_UNICODE 0
int main() {
hls::stream<tick_t> in_stream;
hls::stream<signal_t> out_stream;
const int N = 128;
const int WINDOW_SIZE = 3;
for (int i = 0; i < N; ++i) {
tick_t tick;
tick.timestamp = i;
tick.price = std::sin(i * 0.1f) * 100 + (std::rand() % 10 - 5);
in_stream.write(tick);
}
rolling_variance_stream(in_stream, out_stream, WINDOW_SIZE);
for (int i = 0; i < N - WINDOW_SIZE + 1; ++i) {
signal_t sig = out_stream.read();
#if USE_UNICODE
std::cout << "T=" << sig.timestamp
<< ", μ=" << sig.mean.to_float()
<< ", σ²=" << sig.variance.to_float()
<< std::endl;
#else
std::cout << "T=" << sig.timestamp
<< ", mean=" << sig.mean.to_float()
<< ", var=" << sig.variance.to_float()
<< std::endl;
#endif
}
return 0;
}