FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
array_source.hpp
Go to the documentation of this file.
1#pragma once
2// ArraySource: zero-copy structure-of-arrays input, the numpy path of the Python bindings
3// (8.5). The caller keeps the columns alive for the lifetime of the source. Column dtypes:
4//
5// ts int64 event time, ns, non-decreasing
6// type uint8 RowType: 0 snapshot level, 1 delta level, 2 trade, 3 book ticker
7// inst uint32 dense instrument id
8// side int8 0 bid / buy aggressor, 1 ask / sell aggressor
9// price int64 (raw 1e-8 fixed point) or float64 exactly one of the two
10// qty int64 (raw 1e-8 fixed point) or float64 exactly one of the two
11// seq uint64 optional venue update id (empty span == 0 for every row)
12//
13// The columns are validated once at construction (sizes, enum ranges, ordering, finite
14// doubles); next() allocates nothing.
16
17#include <cstddef>
18#include <cstdint>
19#include <span>
20#include <string>
21
22namespace fastmm::bt {
23
24struct ArrayColumns {
25 std::span<const std::int64_t> ts;
26 std::span<const std::uint8_t> type;
27 std::span<const std::uint32_t> inst;
28 std::span<const std::int8_t> side;
29 std::span<const std::int64_t> price_i64;
30 std::span<const double> price_f64;
31 std::span<const std::int64_t> qty_i64;
32 std::span<const double> qty_f64;
33 std::span<const std::uint64_t> seq;
35 [[nodiscard]] std::size_t size() const noexcept { return ts.size(); }
36 // Empty string when the columns are usable, otherwise a description of the first problem.
37 [[nodiscard]] std::string validate() const;
38};
40class ArraySource final : public MdSource {
41 public:
42 // Throws std::invalid_argument with validate()'s message when the columns are unusable.
43 explicit ArraySource(const ArrayColumns& cols, VenueId venue = VenueId{0});
44 const EventHeader* next() override;
45 void reset() override;
46 [[nodiscard]] Timestamp start_ts() const override {
47 return cols_.size() == 0 ? Timestamp{} : Timestamp{cols_.ts[0]};
48 }
49 [[nodiscard]] std::size_t rows() const noexcept { return cols_.size(); }
50
51 private:
52 bool provide(Row& r) noexcept;
53 ArrayColumns cols_;
54 std::size_t i_ = 0;
55 RowAssembler asm_;
56};
57
58} // namespace fastmm::bt
Definition array_source.hpp:42
Timestamp start_ts() const override
Definition array_source.hpp:48
std::size_t rows() const noexcept
Definition array_source.hpp:51
void reset() override
const EventHeader * next() override
Builds messages from a row stream. Provider is bool(Row&) returning false at end.
Definition data_source.hpp:56
DataSource (8.4): a timestamp-ordered stream of normalized market-data events consumed by the simulat...
Definition backtest_config.hpp:39
Definition messages.hpp:37
Definition time.hpp:45
Definition array_source.hpp:26
std::span< const std::uint32_t > inst
Definition array_source.hpp:29
std::span< const double > price_f64
Definition array_source.hpp:32
std::span< const std::uint64_t > seq
Definition array_source.hpp:35
std::span< const std::int64_t > ts
Definition array_source.hpp:27
std::span< const std::int64_t > price_i64
Definition array_source.hpp:31
std::span< const double > qty_f64
Definition array_source.hpp:34
std::size_t size() const noexcept
Definition array_source.hpp:37
std::span< const std::uint8_t > type
Definition array_source.hpp:28
std::string validate() const
Empty string when the columns are usable, otherwise a description of the first problem.
std::span< const std::int8_t > side
Definition array_source.hpp:30
std::span< const std::int64_t > qty_i64
Definition array_source.hpp:33
Definition data_source.hpp:45