6#include "fastmm/core/latency.hpp"
30struct PnlDecomposition {
85 std::uint64_t
fills = 0;
151 std::int64_t venue_ts,
152 std::int64_t trigger_ts);
153 void on_fill(std::uint64_t
id, std::int64_t ts);
165 std::int64_t venue_ts = 0;
166 std::int64_t first_fill = -1;
167 std::uint32_t open = 0;
172 std::uint64_t
id = 0;
173 std::uint32_t chain = 0;
175 [[nodiscard]] Entry* find(std::uint64_t
id)
noexcept;
176 void insert(std::uint64_t
id, std::uint32_t chain);
177 void erase(Entry* e)
noexcept;
178 [[nodiscard]] std::uint32_t new_chain(std::int64_t venue_ts);
179 void close(std::uint32_t chain);
180 std::vector<Entry> table_;
181 std::size_t entries_ = 0;
182 std::vector<Chain> chains_;
183 std::vector<std::uint32_t> free_;
184 LogLinearHistogram virt_;
185 std::vector<std::int64_t> time_to_fill_;
186 std::uint64_t orders_ = 0;
187 std::uint64_t cancels_ = 0;
188 std::uint64_t replaces_ = 0;
189 std::uint64_t quotes_filled_ = 0;
193 const FillRows& fills,
The order half of the metrics, kept as a run goes: the counts of new orders, cancels and replaces,...
Definition metrics.hpp:145
void on_order(std::uint8_t kind, std::uint64_t id, std::uint64_t orig, std::int64_t venue_ts, std::int64_t trigger_ts)
An order message sent: kind is kOrderKindNew, Cancel or Replace, orig the order a replace replaces,...
void on_fill(std::uint64_t id, std::int64_t ts)
friend Metrics compute_metrics(const EquityRows &, const FillRows &, OrderStats &, const MetricsInputs &)
static OrderStats of(const OrderRows &orders, const FillRows &fills)
The rows' orders, then their fills.
void on_end(std::uint64_t id)
The order can no longer fill (rejected, cancelled, replaced, expired or filled).
Post-fill markouts: the metric that separates spread captured from adverse selection.
Definition backtest_config.hpp:44
Metrics compute_metrics(const EquityRows &equity, const FillRows &fills, OrderStats &orders, const MetricsInputs &in)
constexpr double kMinAnnualizedDurationS
Shortest run whose Sharpe ratio is annualised: one day.
Definition metrics.hpp:121
constexpr Duration seconds(std::int64_t v) noexcept
Definition time.hpp:41
Diagnostics of how the fills were obtained, next to the markouts.
Definition metrics.hpp:47
double queue_ahead_mean
base units
Definition metrics.hpp:68
std::uint64_t quotes_placed
Definition metrics.hpp:64
std::uint64_t time_to_fill_p50_ns
Venue arrival of a new order to its first fill. Only orders that filled are counted.
Definition metrics.hpp:59
double queue_ahead_p90
Definition metrics.hpp:70
double inside_touch_share
at a better price than the touch (it improved it)
Definition metrics.hpp:54
std::uint64_t quotes_filled
Definition metrics.hpp:65
double realized_spread_bps
Notional-weighted (mid at fill - price) for buys, (price - mid at fill) for sells,...
Definition metrics.hpp:50
std::uint64_t time_to_fill_p90_ns
Definition metrics.hpp:60
std::uint64_t time_to_fill_p99_ns
Definition metrics.hpp:61
double realized_spread_quote
Definition metrics.hpp:51
double at_touch_share
Shares of the maker fills, by where the order was against the venue book at the fill.
Definition metrics.hpp:53
bool queue_position_known
Displayed quantity still ahead of the order when it filled; the L2Queue fill model only.
Definition metrics.hpp:67
double behind_touch_share
at a worse price than the touch
Definition metrics.hpp:55
double through_touch_share
At or beyond the opposite touch: the market had moved through the resting order.
Definition metrics.hpp:57
double fill_rate_per_quote
Share of new orders that got at least one fill (fill_ratio counts fills per order instead).
Definition metrics.hpp:63
double queue_ahead_p50
Definition metrics.hpp:69
Buckets of one horizon, all over the same measured fills.
Definition markout.hpp:58
Definition metrics.hpp:73
double fill_ratio
fills / new orders
Definition metrics.hpp:94
double final_position
base units, summed over instruments
Definition metrics.hpp:79
std::uint64_t replaces
Definition metrics.hpp:92
std::uint64_t rejects
Definition metrics.hpp:93
double fees
Definition metrics.hpp:78
double net_pnl
PnL in quote currency at the last bar: net == realized + unrealized - fees.
Definition metrics.hpp:75
std::vector< MarkoutHorizon > markouts
one entry per configured horizon, in order
Definition metrics.hpp:114
double inventory_max
max |position| at any fill or bar
Definition metrics.hpp:100
std::uint64_t maker_fills
Definition metrics.hpp:88
std::uint64_t virtual_tick_to_order_p99_ns
Definition metrics.hpp:107
double spread_captured_bps
mean of (mid - px) / mid for buys, (px - mid) / mid sells
Definition metrics.hpp:95
PnlDecomposition decomposition
Where the net PnL came from, and how good the fills were. See markout.hpp.
Definition metrics.hpp:112
double sharpe_annualized
sharpe_bar * sqrt(bars per 365-day year); NaN for runs more than one bar shorter than kMinAnnualizedD...
Definition metrics.hpp:83
FillQuality fill_quality
Definition metrics.hpp:113
std::uint64_t taker_fills
Definition metrics.hpp:89
std::uint64_t bars
Definition metrics.hpp:102
double volume_quote
Definition metrics.hpp:97
double duration_s
Definition metrics.hpp:103
std::uint64_t cancels
Definition metrics.hpp:91
double volume_base
Definition metrics.hpp:96
std::uint64_t wall_tick_to_order_p99_ns
Definition metrics.hpp:110
double unrealized_pnl
Definition metrics.hpp:77
const MarkoutHorizon * markout(std::int64_t horizon_ns) const noexcept
The markout of one horizon, or nullptr when it was not measured.
double realized_pnl
Definition metrics.hpp:76
double quote_uptime
fraction of bars with both a bid and an ask resting
Definition metrics.hpp:101
std::uint64_t virtual_tick_to_order_p50_ns
Virtual tick-to-order: engine receipt of the triggering event (T0, virtual clock) to the order's arri...
Definition metrics.hpp:106
double inventory_mean
over bars
Definition metrics.hpp:98
std::uint64_t orders
new orders sent
Definition metrics.hpp:90
std::uint64_t fills
Definition metrics.hpp:87
double sharpe_bar
mean / sample stdev of per-bar equity changes
Definition metrics.hpp:80
double max_drawdown
largest fall of equity from its peak, quote currency, >= 0
Definition metrics.hpp:84
double max_drawdown_pct
max_drawdown / initial_capital; NaN when initial_capital <= 0.
Definition metrics.hpp:86
std::uint64_t wall_tick_to_order_p50_ns
Measured wall clock per engine step that consumed market data (0 when not measured).
Definition metrics.hpp:109
double inventory_abs_mean
over bars
Definition metrics.hpp:99
How the net PnL of the run splits into the parts a market maker can act on: net == spread_capture + m...
Definition metrics.hpp:32
double notional
traded notional of every fill
Definition metrics.hpp:40
double spread_capture
sum of signed_qty * (mid at fill - fill price)
Definition metrics.hpp:33
std::uint64_t fills
Definition metrics.hpp:43
double capture_notional
traded notional of the fills that had a mid at the fill
Definition metrics.hpp:41
double residual
reported net PnL - net
Definition metrics.hpp:39
double spread_capture_bps
Definition metrics.hpp:34
double fees_paid
sum of the positive fees, >= 0
Definition metrics.hpp:36
std::uint64_t capture_fills
Definition metrics.hpp:42
double rebates_received
sum of the negative fees with the sign flipped, >= 0
Definition metrics.hpp:37
double net
spread_capture + mid_drift - fees_paid + rebates_received
Definition metrics.hpp:38
double mid_drift
sum of signed_qty * (final mid - mid at fill)
Definition metrics.hpp:35