FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
extractor.hpp
Go to the documentation of this file.
1#pragma once
2// extract_features(): drives an MdSource into the engine's own L2Book and emits a FeatureTable.
3//
4// The book is the one the simulated venue keeps under FillModel::L2Queue (sim/sim_transport.cpp,
5// `queue_on_delta`): BookDelta and BookSnapshot are applied, trades are not. So the mid of a row
6// and its forward mids are the same numbers `SimTransport::venue_mid()` reports at those times,
7// and a fill of a backtest over the same data can be joined to this table by timestamp.
8//
9// One pass, no look-ahead. Forward mids are resolved by a rule that reads the book only at times
10// the data has already reached:
11//
12// on an event at time t, before applying it, resolve every pending row whose ts + h < t;
13// at the end of the data, resolve every pending row whose ts + h <= the last event time.
14//
15// So a row's value at horizon h is the book after every event at or before ts + h and no other -
16// the same state `run_until(ts + h)` leaves the venue in. A row whose ts + h is past the last
17// event stays unset and is counted in HorizonCoverage::excluded_past_end.
18#include "fastmm/core/time.hpp"
20#include "fastmm/sim/md_source.hpp"
21
22#include <cstddef>
23#include <cstdint>
24#include <vector>
25
26namespace fastmm::research {
27
28using sim::MdSource;
29
30// kDefaultHorizonsNs as Durations.
31[[nodiscard]] std::vector<Duration> default_horizons();
32
34 // Forward horizons. Empty selects default_horizons(); non-positive entries are dropped and the
35 // rest are sorted ascending and de-duplicated.
36 std::vector<Duration> horizons;
37 // Levels summed by fastmm::imbalance(). 1 is the touch, which is all a top-of-book feed shows.
38 std::size_t imbalance_levels = 1;
39 // Minimum spacing between rows of one instrument. Zero samples every book update; 10 ms keeps
40 // at most one row per instrument per 10 ms of event time.
42 // What emits a row. A book update emits one after it has been applied; a trade emits one with
43 // the book as it stood when the trade printed. Trades off by default; with book updates off and
44 // trades on, the table has exactly one row per trade, at the timestamp of every fill a backtest
45 // over the same data can produce, which is what the cross-check against fills.csv needs.
46 // Turning both off leaves an empty table.
47 bool sample_book_updates = true;
48 bool sample_trades = false;
49 // Books kept. Events for a higher instrument id are counted and ignored.
50 std::uint32_t instruments = 1;
51};
53// Reads `source` from its current position to the end. Throws std::invalid_argument when
54// `instruments` is 0 or `imbalance_levels` is 0.
55[[nodiscard]] FeatureTable extract_features(MdSource& source, const FeatureConfig& cfg = {});
56
57} // namespace fastmm::research
FeatureTable: book features and forward mid moves, one row per qualifying market-data event,...
Definition feature_table.hpp:22
FeatureTable extract_features(MdSource &source, const FeatureConfig &cfg={})
Reads source from its current position to the end.
std::vector< Duration > default_horizons()
kDefaultHorizonsNs as Durations.
Definition time.hpp:22
Definition extractor.hpp:35
Duration subsample
Minimum spacing between rows of one instrument.
Definition extractor.hpp:43
std::vector< Duration > horizons
Forward horizons.
Definition extractor.hpp:38
bool sample_trades
Definition extractor.hpp:50
std::size_t imbalance_levels
Levels summed by fastmm::imbalance(). 1 is the touch, which is all a top-of-book feed shows.
Definition extractor.hpp:40
std::uint32_t instruments
Books kept. Events for a higher instrument id are counted and ignored.
Definition extractor.hpp:52
bool sample_book_updates
What emits a row.
Definition extractor.hpp:49
Definition feature_table.hpp:63
Time primitives.