Crypto backtesting
Loading...
Searching...
No Matches
ohlc.h
Go to the documentation of this file.
1#pragma once
2
3#include "core.h"
4#include <cassert>
5
6// OHLC
7namespace fx {
8/// Get time of a data point
9constexpr auto to_time(std::ranges::range auto &&xs) {
10 return std::lround(to_first(xs));
11};
12
13/// Get open price for a data point
14constexpr auto to_open(std::ranges::range auto &&xs) {
15 assert(to_size(xs) > 1uz);
16 return xs[1];
17}
18
19/// Get high price for a data point
20constexpr auto to_high(std::ranges::range auto &&xs) {
21 assert(to_size(xs) > 2uz);
22 return xs[2];
23}
24
25/// Get low price for a data point
26constexpr auto to_low(std::ranges::range auto &&xs) {
27 assert(to_size(xs) > 3uz);
28 return xs[3];
29}
30
31/// Get close price for a data point
32constexpr auto to_close(std::ranges::range auto &&xs) {
33 assert(to_size(xs) > 4uz);
34 return xs[4];
35}
36
37/// Get total volume for a data point
38constexpr auto to_volume = [](std::ranges::range auto &&xs) {
39 assert(to_size(xs) > 5uz);
40 return xs[5];
41};
42} // 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_low(std::ranges::range auto &&xs)
Get low price for a data point.
Definition ohlc.h:26
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