Crypto backtesting
Loading...
Searching...
No Matches
fx.cxx
Go to the documentation of this file.
1#include "ohlc.h"
2#include <numeric>
3#include <vector>
4
5// CORE
6namespace fx {
7static_assert(to_size(std::views::iota(0, 10)) == 10uz);
8static_assert(to_size(std::vector{1.0, 2.0}) == 2uz);
9static_assert(to_size(std::vector{1, 2, 3}) == 3uz);
10static_assert(to_size<double>(std::vector{1, 2, 3}) == 3.0);
11static_assert(to_size<float>(std::vector<int>{}) == 0uz);
12
13static_assert(to_first(std::vector{1, 2, 3}) == 1);
14static_assert(to_first(std::vector{1.0, 2.0, 3.0}) == 1.0);
15static_assert(to_first(std::vector{'a'}) == 'a');
16
17static_assert(to_last(std::vector{1, 2, 3}) == 3);
18static_assert(to_last(std::vector{1.0, 2.0, 3.0}) == 3.0);
19static_assert(to_last(std::vector{'a'}) == 'a');
20
21static_assert(to_sum(std::vector{1, 2, 3}) == 6.0);
22static_assert(to_sum(std::vector{1.0f, 2.0f}) == 3.0f);
23static_assert(to_sum(std::vector<int>{}) == 0.0);
24
25static_assert(identity(1) == 1);
26static_assert(std::ranges::size(identity(std::vector{2, 2})) == 2uz);
27
28static_assert(to_profit(100.0, 100.0) == 0.0);
29static_assert(to_profit(100.0f, 150.0f) == 50.0f);
30static_assert(to_profit(200.0, 100.0) == -50.0);
31static_assert(to_profit(200.0l, 100.0l) == -50.0l);
32} // namespace fx
33
34// DEPS
35namespace fx {
36// OHLC
37static_assert(to_time(std::vector{1.4, 2.0, 3.0}) == 1);
38static_assert(to_time(std::vector{1.6, 2.0, 3.0}) == 2);
39static_assert(to_open(std::vector{0.0, 1.0, 2.0, 3.0, 4.0}) == 1.0);
40static_assert(to_high(std::vector{0.0, 1.0, 2.0, 3.0, 4.0}) == 2.0);
41static_assert(to_low(std::vector{0.0, 1.0, 2.0, 3.0, 4.0}) == 3.0);
42static_assert(to_close(std::vector{0.0, 1.0, 2.0, 3.0, 4.0}) == 4.0);
43static_assert(to_volume(std::vector{0.0, 1.0, 2.0, 3.0, 4.0, 5.0}) == 5.0);
44} // namespace fx
Core routines that don't depend on any other fx routines.
Definition constants.h:3
constexpr auto to_first(std::ranges::range auto &&xs)
Return the first entry in a series.
Definition core.h:19
constexpr auto to_time(std::ranges::range auto &&xs)
Get time of a data point.
Definition ohlc.h:9
constexpr auto to_last
Return the last entry in a series.
Definition core.h:25
constexpr auto to_low(std::ranges::range auto &&xs)
Get low price for a data point.
Definition ohlc.h:26
constexpr auto to_profit(auto &&entry, auto &&exit)
Calculate profit from a trade.
Definition core.h:59
constexpr auto to_sum(std::ranges::range auto &&xs)
Calculate sum of series.
Definition core.h:31
constexpr auto identity
Just passing through.
Definition core.h:51
constexpr auto to_close(std::ranges::range auto &&xs)
Get close price for a data point.
Definition ohlc.h:32
constexpr auto to_open(std::ranges::range auto &&xs)
Get open price for a data point.
Definition ohlc.h:14
constexpr auto to_volume
Get total volume for a data point.
Definition ohlc.h:38
constexpr auto to_high(std::ranges::range auto &&xs)
Get high price for a data point.
Definition ohlc.h:20
constexpr T to_size(std::ranges::range auto &&xs)
Calculate size of a series, return type depends on input param.
Definition core.h:14