Take a vector of files to backtest with testing params, and return a summary of trades across all files
10 {
11
12
13 std::vector<trade_t> results;
14 auto &&results_mutex = std::mutex{};
15
16
17 std::ranges::for_each(files, [&](auto &&csv) {
18 using namespace std::views;
19
20
23
24
25
28
29
30 for (auto &&x : entries) {
31
32
33 auto &&entry_it = std::ranges::find_if(
35
36
37 auto &&offset = std::ranges::distance(std::cbegin(series), entry_it);
38
39
40 auto trade_window_size =
41 std::min(std::size(series) - offset,
static_cast<size_t>(
fx::win));
42
43
44
45 auto &&trade = std::vector<std::vector<double>>{
46 std::cbegin(series) + offset,
47 std::cbegin(series) + offset + trade_window_size};
48
49
53
54
57 auto &&duration = exit_time - entry_time;
58
59
60 auto &&to_token = csv | take(std::ranges::size(csv) - 4uz) | drop(12uz);
61
62
63 std::scoped_lock lock(results_mutex);
64 results.push_back({to_token, entry_time,
fx::to_spot(entry),
66 }
67 });
68
69
70 std::ranges::sort(
71 results, [](auto a, auto b) { return std::get<1>(a) > std::get<1>(b); });
72
73 return results;
74}
std::vector< std::vector< double > > to_series3(const std::string &csv)
Open a CSV file and return a vector of floating points for each row.
std::string file_read(const std::string_view file_name)
Open a file a return a string of the contents.
constexpr auto to_first(std::ranges::range auto &&xs)
Return the first entry in a series.
constexpr auto to_time(std::ranges::range auto &&xs)
Get time of a data point.
constexpr auto to_last
Return the last entry in a series.
auto to_exit
Find an exit in a series.
constexpr auto win
The number of prices in a trading window.
constexpr auto to_profit(auto &&entry, auto &&exit)
Calculate profit from a trade.
auto is_entry2
Calculate if the final price is an entry.
constexpr auto to_spot
Calculate spot value, note we don't average all of the OHLC prices.