algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
report.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "./engine.hpp"
4
5#include <algotradelib/analytics>
6#include <algotradelib/core>
7
8#include <chrono>
9#include <cmath>
10#include <cstddef>
11#include <cstdint>
12#include <initializer_list>
13#include <optional>
14#include <stdexcept>
15#include <string>
16#include <utility>
17#include <vector>
18
19namespace algotradelib {
20namespace backtest {
21
29
40 std::vector<AppliedRate> applied_rates_;
54 std::optional<VenueKey> asserted_venue_;
56 std::string commission_tariff_;
68
78
80 std::size_t gaps_{0};
81
83 std::size_t unfilled_{0};
84
94 std::size_t quotes_{0};
95
111
116 static constexpr bool volume_ignored = true;
117
125 static constexpr bool bar_tape_unverified = true;
126
133 static constexpr bool sellable_is_whole_holding = true;
134
142 static constexpr bool buying_power_is_ledger_cash = true;
143
152 std::size_t unvalued_bars_{0};
154 std::optional<std::chrono::system_clock::time_point> first_unvalued_;
160 std::size_t stop_releases_{0};
168 std::size_t stop_fills_intrabar_{0};
173 std::size_t limit_fills_bounded_{0};
183 std::size_t market_fills_by_rule_{0};
191 std::size_t overdrawn_bars_{0};
193 std::optional<std::chrono::system_clock::time_point> first_overdrawn_;
195 std::optional<Money> lowest_cash_;
206 std::optional<std::chrono::system_clock::time_point> lowest_cash_at_;
208 std::optional<SellTax> sell_tax_;
210 std::size_t expired_day_orders_{0};
211};
212
218struct Report {
220 std::size_t bars_{0};
222 std::size_t executions_{0};
223
234
263
271 std::optional<Decimal64> commission_paid_;
273 std::vector<Money> commission_by_currency_;
280 std::optional<Decimal64> institution_fees_paid_;
287 std::vector<Money> institution_by_currency_;
294 std::optional<Decimal64> slippage_paid_;
296 std::vector<Money> slippage_by_currency_;
297
299 std::size_t rejected_{0};
301 std::size_t refused_{0};
302
311 std::optional<BrokerError> halted_;
313 std::size_t aborted_{0};
314
324 std::optional<Decimal64> tax_paid_;
326 std::vector<Money> tax_by_currency_;
327};
328
329namespace report_detail {
330
331// `summarize`, also handing back the curve's levels and returns as the columns the metrics take (both empty
332// for an empty curve), so `measure_input` keeps them without a second pass.
333inline Report summarize(
334 const ReplayResult& result, const NextBarFillModel& fills, std::optional<math::Scalar> periods_per_year,
335 math::Scalar risk_free, math::Vector& levels, math::Vector& returns
336) {
337 Report report;
338 report.bars_ = result.bars_;
339 report.executions_ = result.executions_.size();
340 report.rejected_ = result.rejected_.size();
341 report.refused_ = result.refused_.size();
342
343 report.caveats_.limit_fill_ = fills.limit_price();
344 report.halted_ = result.halted_;
345 report.aborted_ = result.aborted_;
346 if (fills.commission().is_scheduled()) {
348 }
349 report.caveats_.commission_tariff_ = std::string(fills.commission().tariff());
351 report.caveats_.slippage_ticks_ = fills.slippage().ticks_;
352 report.caveats_.gaps_ = result.gaps_;
353 report.caveats_.unfilled_ = result.unfilled_;
354 report.caveats_.stop_releases_ = result.stop_releases_;
359 report.caveats_.quotes_ = result.quotes_;
361 report.caveats_.unvalued_bars_ = result.unvalued_bars_;
365 report.caveats_.lowest_cash_ = result.lowest_cash_;
368
369 // Costs summed exactly, because they are money -- and **per currency**, because a replay whose
370 // instruments span markets would otherwise have won added to dollars to make one scalar.
371 // Checked, and a refusal is recorded rather than swallowed: leaving the previous total in place
372 // and carrying on produced a plausible figure that was short by an unknown amount, which is the
373 // one outcome every exact-decimal path here exists to prevent. Two individually representable
374 // commissions whose sum does not fit is enough to reach it, and a probe did.
375 bool costs_fit = true;
376 const auto accumulate = [&costs_fit](std::vector<Money>& totals, const Money& amount) {
377 for (auto& held : totals) {
378 if (held.currency_ == amount.currency_) {
379 const auto sum = decimal_add(held.amount_, amount.amount_);
380 if (!sum) {
381 costs_fit = false;
382 return;
383 }
384 held.amount_ = *sum;
385 return;
386 }
387 }
388 totals.push_back(amount);
389 };
390
391 std::vector<InstrumentId> seen;
392 for (const auto& execution : result.executions_) {
393 accumulate(report.commission_by_currency_, Money{execution.commission_, execution.currency_});
394 if (execution.institution_fee_) {
395 accumulate(report.institution_by_currency_, Money{*execution.institution_fee_, execution.currency_});
396 } else {
397 // The rate stated one figure, so this execution's commission is inclusive and the split total
398 // below cannot be completed. Counted rather than approximated.
400 }
401 // The rate that charged it, collapsed so an unchanged rate is one row with a count rather than
402 // one row per fill. Accumulated here, from the executions the ledger accepted, rather than from
403 // the schedule: a row the replay never used is not a rate this run applied.
404 bool counted = false;
405 for (auto& applied : report.caveats_.applied_rates_) {
406 if (applied == execution.applied_) {
407 ++applied.executions_;
408 counted = true;
409 break;
410 }
411 }
412 if (!counted) {
413 auto entry = execution.applied_;
414 entry.executions_ = 1;
415 report.caveats_.applied_rates_.push_back(std::move(entry));
416 }
417 // The tax, totalled per currency, over the executions in the market it was stated for: another
418 // market's fills pay none by construction, and counting them would add a zero row in their
419 // currency and cost a single-currency total its scalar.
420 if (fills.sell_tax() && execution.fill_.instrument_.country_ == fills.sell_tax()->country_) {
421 accumulate(report.tax_by_currency_, Money{execution.tax_, execution.currency_});
422 }
423 // Slippage is a per-share price difference, so its cost is that times the quantity -- and it
424 // is totalled per currency like every other cost, because a replay can hold fills in more
425 // than one and adding them would produce a figure denominated in nothing.
426 if (const auto cost = decimal_multiply(execution.slippage_, execution.fill_.quantity_)) {
427 accumulate(report.slippage_by_currency_, Money{*cost, execution.currency_});
428 } else {
429 costs_fit = false;
430 }
431 bool known = false;
432 for (const auto& id : seen) {
433 if (id == execution.fill_.instrument_) {
434 known = true;
435 break;
436 }
437 }
438 if (!known) {
439 seen.push_back(execution.fill_.instrument_);
440 }
441 }
442 report.caveats_.cost_totals_incomplete_ = !costs_fit;
443 // A scalar is stated only where one can be true: one currency, something executed, and every
444 // addition representable. On a mixed-currency replay the per-currency vectors are the whole
445 // answer, and on an arithmetic refusal nothing is stated at all rather than a figure short by an
446 // amount nobody can name.
447 if (costs_fit && report.commission_by_currency_.size() == 1) {
448 report.commission_paid_ = report.commission_by_currency_.front().amount_;
449 }
450 // Present only when every charged rate split the two components, so the total is complete rather
451 // than a sum over the subset that happened to state one.
452 if (
453 costs_fit && report.caveats_.inclusive_commission_executions_ == 0 && report.institution_by_currency_.size() == 1
454 ) {
455 report.institution_fees_paid_ = report.institution_by_currency_.front().amount_;
456 }
457 if (costs_fit && report.slippage_by_currency_.size() == 1) {
458 report.slippage_paid_ = report.slippage_by_currency_.front().amount_;
459 }
460 report.caveats_.sell_tax_ = fills.sell_tax();
461 if (fills.sell_tax() && costs_fit && report.tax_by_currency_.size() == 1) {
462 report.tax_paid_ = report.tax_by_currency_.front().amount_;
463 }
464 report.caveats_.multiple_instruments_ = seen.size() > 1;
465 for (const auto& execution : result.executions_) {
466 if (!(execution.currency_ == result.currency_)) {
468 }
469 }
470
471 if (result.equity_.empty()) {
472 // Nothing to measure. Every figure stays unobserved rather than becoming zero, which would read as
473 // a flat result rather than as an absent one.
474 report.total_return_ = math::missing();
475 report.sharpe_ = math::missing();
477 report.sortino_ = math::missing();
478 report.max_drawdown_ = math::missing();
480 return report;
481 }
482
483 report.opening_equity_ = result.equity_.front().equity_;
484 report.closing_equity_ = result.equity_.back().equity_;
485
486 // The returns and the equity curve, as the columns the metrics take.
487 returns.resize(static_cast<math::Index>(result.equity_.size()));
488 levels.resize(static_cast<math::Index>(result.equity_.size()));
489 for (std::size_t at = 0; at < result.equity_.size(); ++at) {
490 returns[static_cast<math::Index>(at)] = result.equity_[at].period_return_;
491 levels[static_cast<math::Index>(at)] = analytics::to_scalar(result.equity_[at].equity_);
492 }
493
494 // From a negative opening the ratio's sign reverses (a replay may start with negative cash), so a
495 // non-positive opening has no return and no turnover, as a zero one has none.
496 const auto opening = analytics::to_scalar(report.opening_equity_);
497 report.total_return_ = !(opening > math::Scalar{0}) ?
500
501 report.sharpe_ = analytics::sharpe(returns, risk_free);
502 report.sortino_ = analytics::sortino(returns, risk_free);
503 // Equity at or below zero before the end leaves the periods after it without a return
504 // (`EquityPoint::period_return_`), so no ratio describes the run.
505 for (std::size_t at = 0; at + 1 < result.equity_.size(); ++at) {
506 if (result.equity_[at].equity_.coefficient() <= 0) {
507 report.sharpe_ = math::undefined();
508 report.sortino_ = math::undefined();
509 break;
510 }
511 }
513
514 report.annualized_sharpe_ =
516
517 // Every trade outside the curve: it holds only the opening cash, and its figures describe no trading.
518 const auto outside = report.caveats_.other_currency_executions_;
519 if (outside > 0 && outside == result.executions_.size()) {
520 report.total_return_ = math::missing();
521 report.sharpe_ = math::missing();
523 report.sortino_ = math::missing();
524 report.max_drawdown_ = math::missing();
525 }
526
527 // Turnover from the executions rather than from a weight matrix, because a replay knows what it
528 // actually traded. One-way: the fraction of equity that changed hands.
529 // Same money on both sides, or no figure at all.
530 report.total_turnover_ = !(opening > math::Scalar{0}) ? math::undefined() : math::Scalar{0};
531 if (outside > 0) {
533 }
534 if (math::observed(report.total_turnover_)) {
535 for (const auto& execution : result.executions_) {
536 const auto traded = decimal_multiply(execution.fill_.quantity_, execution.fill_.price_);
537 if (traded) {
538 report.total_turnover_ += analytics::to_scalar(*traded) / opening;
539 }
540 }
541 }
542
543 return report;
544}
545
546} // namespace report_detail
547
561 const ReplayResult& result, const NextBarFillModel& fills,
562 std::optional<math::Scalar> periods_per_year = std::nullopt, math::Scalar risk_free = math::Scalar{0}
563) {
564 math::Vector levels;
565 math::Vector returns;
566 return report_detail::summarize(result, fills, periods_per_year, risk_free, levels, returns);
567}
568
595
611 const ReplayResult& result, const NextBarFillModel& fills, std::optional<math::Scalar> periods_per_year = std::nullopt
612) {
613 math::Vector levels;
614 math::Vector returns;
615 auto report = report_detail::summarize(result, fills, periods_per_year, math::Scalar{0}, levels, returns);
616 return MeasureInput{
617 result, std::move(report), std::move(levels), std::move(returns),
619 };
620}
621
627 const ReplayResult&&, const NextBarFillModel&, std::optional<math::Scalar> = std::nullopt
628) = delete;
629
650inline ReplayResult chain_results(const std::vector<const ReplayResult*>& results) {
651 if (results.empty()) {
652 throw std::invalid_argument("chain_results needs a result");
653 }
654 ReplayResult out;
655 for (std::size_t f = 0; f < results.size(); ++f) {
656 const ReplayResult* fold = results[f];
657 const auto refused = "chain_results: fold " + std::to_string(f) + " ";
658 if (fold == nullptr || fold->halted_ || fold->equity_.empty()) {
659 throw std::invalid_argument(refused + "is null, halted, or has no curve point");
660 }
661 if (f == 0) {
662 out.currency_ = fold->currency_;
663 out.equity_ = fold->equity_;
664 } else {
665 const auto close = out.equity_.back();
666 const auto& first = fold->equity_.front();
667 const auto from = analytics::to_scalar(first.equity_);
668 const auto to = analytics::to_scalar(close.equity_);
669 const bool capital = first.equity_.coefficient() > 0 && close.equity_.coefficient() > 0;
670 if (!(fold->currency_ == out.currency_) || !(close.at_ < first.at_) || !capital) {
671 throw std::invalid_argument(refused + "differs in currency, overlaps the previous one, or follows no capital");
672 }
673 for (std::size_t at = 0; at < fold->equity_.size(); ++at) {
674 auto point = fold->equity_[at];
675 const auto value = analytics::to_scalar(point.equity_) * (to / from);
676 // As many places as fifteen significant digits need (`to_decimal` multiplies by ten as often), up to 255.
677 std::uint8_t places = 0;
678 for (auto magnitude = std::abs(value); magnitude != 0 && magnitude < 1e15 && places < 255; ++places) {
679 magnitude *= 10;
680 }
681 const auto scaled = at == 0 ? std::optional<Decimal64>(close.equity_) : analytics::to_decimal(value, places);
682 // Nonzero is read from the decimal, not `value`: the scale is positive, and the product can underflow to 0.
683 if (!scaled || (point.equity_.coefficient() != 0 && scaled->coefficient() == 0)) {
684 throw std::invalid_argument(refused + "has an equity that does not fit a decimal once scaled");
685 }
686 point.equity_ = *scaled;
687 point.period_return_ = at == 0 ? math::missing() : point.period_return_;
688 out.equity_.push_back(point);
689 }
690 }
691 out.executions_.insert(out.executions_.end(), fold->executions_.begin(), fold->executions_.end());
692 out.rejected_.insert(out.rejected_.end(), fold->rejected_.begin(), fold->rejected_.end());
693 out.refused_.insert(out.refused_.end(), fold->refused_.begin(), fold->refused_.end());
694 for (
695 auto [total, count] : std::initializer_list<std::pair<std::size_t*, std::size_t>>{
696 {&out.gaps_, fold->gaps_}, {&out.bars_, fold->bars_}, {&out.unfilled_, fold->unfilled_},
697 {&out.aborted_, fold->aborted_}, {&out.quotes_, fold->quotes_}, {&out.records_, fold->records_},
703 }
704 ) {
705 *total += count;
706 }
710 if (
711 fold->lowest_cash_ && (!out.lowest_cash_ || decimal_less(fold->lowest_cash_->amount_, out.lowest_cash_->amount_))
712 ) {
713 out.lowest_cash_ = fold->lowest_cash_;
715 }
716 }
717 return out;
718}
719
720} // namespace backtest
721} // namespace algotradelib
An exact signed decimal: an int64 coefficient times 10^-scale.
Definition types.hpp:443
const VenueKey & asserted_venue() const noexcept
Returns the asserted venue.
Definition cost.hpp:246
std::string_view tariff() const noexcept
Returns the schedule's tariff name.
Definition cost.hpp:254
bool is_scheduled() const noexcept
Tests whether the policy resolves a schedule.
Definition cost.hpp:238
The fill model: market orders at the next bar's open, limit orders when the next bar's range reaches ...
Definition fill.hpp:142
const CommissionPolicy & commission() const noexcept
Returns the commission policy.
Definition fill.hpp:174
const std::optional< SellTax > & sell_tax() const noexcept
Returns the tax on sales.
Definition fill.hpp:219
LimitFillPrice limit_price() const noexcept
Returns which price a filled limit order is credited.
Definition fill.hpp:190
const SlippageModel & slippage() const noexcept
Returns the slippage model.
Definition fill.hpp:182
The backtest engine: Backtester replays bars (and quotes) through the same Runner a live session uses...
Scalar sortino(math::SeriesView period_returns, Scalar target=Scalar{0})
Computes the per-period Sortino ratio, (mean(returns) - target) / downside_deviation.
Definition metrics.hpp:151
Scalar annualize_ratio(Scalar ratio, Scalar periods_per_year)
Annualizes a per-period ratio by multiplying it by sqrt(periods_per_year).
Definition metrics.hpp:198
MaxDrawdown max_drawdown(math::SeriesView levels)
Finds the worst peak-to-trough decline of a level series.
Definition metrics.hpp:82
Scalar to_scalar(const Decimal64 &value)
Converts an exact decimal to the nearest Scalar.
Scalar sharpe(math::SeriesView period_returns, Scalar risk_free=Scalar{0})
Computes the per-period Sharpe ratio, (mean(returns) - risk_free) / stdev(returns).
Definition metrics.hpp:126
std::optional< Decimal64 > to_decimal(Scalar value, std::uint8_t scale)
Converts a Scalar to an exact decimal with a given number of decimal places.
Replays a strategy over stored bars: fill and cost models, the replay ledger, and the report.
Definition bootstrap.hpp:16
Report summarize(const ReplayResult &result, const NextBarFillModel &fills, std::optional< math::Scalar > periods_per_year=std::nullopt, math::Scalar risk_free=math::Scalar{0})
Summarizes a replay into a Report.
Definition report.hpp:560
LimitFillPrice
Which price a backtest credits a limit order that fills.
Definition cost.hpp:565
@ AT_LIMIT
The default: fill at the limit, or at the bar's worst traded price when the whole bar was better than...
Definition cost.hpp:574
std::optional< math::Scalar > periods_per_year(BarInterval interval, const strategy::SessionWindow &session, math::Scalar trading_days)
Returns how many bars of an interval a year contains, for analytics::annualize_ratio.
Definition clock.hpp:47
MeasureInput measure_input(const ReplayResult &result, const NextBarFillModel &fills, std::optional< math::Scalar > periods_per_year=std::nullopt)
Builds the input a measure reads from a finished replay, calling summarize once.
Definition report.hpp:610
ReplayResult chain_results(const std::vector< const ReplayResult * > &results)
Chains test replays into one result, so summarize and measure_input give the chain's figures.
Definition report.hpp:650
double Scalar
The floating-point type the analytics and math layers compute in (double).
Definition scalar.hpp:18
bool observed(Scalar value)
Tests whether a value is an observation.
Definition scalar.hpp:38
Eigen::Index Index
The signed index type of rows and columns.
Definition eigen.hpp:47
Scalar undefined()
Returns the value that stands for "the data was there, but the statistic does not exist".
Definition scalar.hpp:55
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
A dense column vector of Scalar.
Definition eigen.hpp:30
Scalar missing()
Returns the value that stands for "no observation" (a quiet NaN).
Definition scalar.hpp:28
The library: broker-neutral types (core), and the modules below.
std::optional< Decimal64 > decimal_add(const Decimal64 &lhs, const Decimal64 &rhs)
Adds two decimals exactly.
Definition types.hpp:760
bool decimal_less(const Decimal64 &lhs, const Decimal64 &rhs)
Compares two decimals numerically, whatever their scales.
Definition types.hpp:926
std::optional< Decimal64 > decimal_multiply(const Decimal64 &lhs, const Decimal64 &rhs)
Multiplies two decimals exactly; the scales add.
Definition types.hpp:826
An exact amount of money in one currency.
Definition types.hpp:1168
Scalar magnitude_
The decline as a non-negative fraction of the peak (0.2 is 20% below it).
Definition metrics.hpp:63
What a measure of a finished replay reads: the replay, its report, and its equity curve's levels and ...
Definition report.hpp:580
math::Vector levels_
Each curve point's equity, in order.
Definition report.hpp:586
const ReplayResult & result_
The replay: its curve (each point's time in equity_[i].at_), its executions and its counts.
Definition report.hpp:582
math::Vector returns_
Each curve point's period return, in order; missing() where the curve leaves it undefined (see Equity...
Definition report.hpp:591
math::Scalar periods_per_year_
The periods per year given to measure_input, or missing() when none was given.
Definition report.hpp:593
Report report_
summarize of the replay, with every built-in figure, halted_ and the caveats.
Definition report.hpp:584
Everything a replay produced; summarize turns it into a Report.
Definition engine.hpp:676
std::size_t unvalued_bars_
Bars whose equity total did not fit an exact decimal, so they have no curve point.
Definition engine.hpp:731
std::size_t stop_releases_
Stop-limit orders a bar released; see ReportCaveats::stop_releases_.
Definition engine.hpp:735
std::size_t bars_
The bars replayed; bars fed as history (ReplayConfig::trade_from_) are in history_bars_.
Definition engine.hpp:694
std::size_t limit_fills_bounded_
Limit-type fills moved to stay in range; see ReportCaveats::limit_fills_bounded_.
Definition engine.hpp:739
std::size_t unchecked_fill_causality_
How many fill decisions could not be checked for causality; see ReportCaveats::unchecked_fill_causali...
Definition engine.hpp:723
std::optional< std::chrono::system_clock::time_point > first_unvalued_
The period end of the first unvalued bar, if any.
Definition engine.hpp:733
std::vector< strategy::GuardRejection > refused_
Instructions a risk guard refused.
Definition engine.hpp:690
std::vector< strategy::Rejection > rejected_
Instructions not placed: reconciliation could not build them, or the replay cannot model them (BINDIN...
Definition engine.hpp:688
std::size_t records_
The records fed to on_data.
Definition engine.hpp:713
std::vector< Execution > executions_
Every execution, in order.
Definition engine.hpp:683
std::size_t gaps_
Bars that did not follow their predecessor; gaps are not interpolated.
Definition engine.hpp:692
std::size_t expired_day_orders_
DAY orders withdrawn unfilled when their session ended, as a broker does at the close.
Definition engine.hpp:762
std::size_t unfilled_
Orders still queued when finish ran.
Definition engine.hpp:696
std::optional< BrokerError > halted_
Why the replay stopped early, if it did.
Definition engine.hpp:707
std::size_t stop_fills_intrabar_
Fills of stops released inside a bar; see ReportCaveats::stop_fills_intrabar_.
Definition engine.hpp:737
std::string market_price_rule_
The fill model's market-price rule, or empty; see ReportCaveats::market_price_rule_.
Definition engine.hpp:741
std::size_t market_fills_by_rule_
Fills priced by the fill model's market-price rule; see ReportCaveats::market_fills_by_rule_.
Definition engine.hpp:743
std::size_t quotes_
The quotes fed; see ReportCaveats::quotes_ for what quote-driven orders mean in a replay.
Definition engine.hpp:711
Currency currency_
The currency of the equity curve (the replay's accounting currency).
Definition engine.hpp:698
std::size_t history_bars_
The bars fed as history, before ReplayConfig::trade_from_.
Definition engine.hpp:764
std::optional< std::chrono::system_clock::time_point > first_overdrawn_
The first bar end at which cash was below zero, if any.
Definition engine.hpp:756
std::size_t aborted_
Orders still working when the replay halted, cleared from the queue (unlike unfilled_).
Definition engine.hpp:709
std::optional< Money > lowest_cash_
The lowest cash any execution left in currency_, if below zero (checked at every fill).
Definition engine.hpp:758
std::optional< std::chrono::system_clock::time_point > lowest_cash_at_
When lowest_cash_ was reached (that execution's Fill::at_).
Definition engine.hpp:760
std::vector< EquityPoint > equity_
The equity curve, in order: one point per period end, or per bar, or none (ReplayConfig::equity_curve...
Definition engine.hpp:681
std::size_t overdrawn_bars_
Bars that closed with cash below zero in currency_ (counted per bar fed, so two instruments count bot...
Definition engine.hpp:754
What a replay's figures assumed and did not account for.
Definition report.hpp:31
std::size_t quotes_
How many quotes the replay was fed (zero for a bars-only replay).
Definition report.hpp:94
static constexpr bool volume_ignored
Always true: fills are never capped by traded volume, and queue position, market impact and borrow av...
Definition report.hpp:116
std::size_t gaps_
Bars that did not follow their predecessor (see ReplayClock::contiguous); gaps are not interpolated.
Definition report.hpp:80
std::size_t stop_releases_
How many stop-limit orders a bar released, each using the assumed direction (a sell stop releases whe...
Definition report.hpp:160
std::size_t inclusive_commission_executions_
How many executions were charged a single combined rate (no institution fee split).
Definition report.hpp:47
std::optional< std::chrono::system_clock::time_point > first_unvalued_
The period end of the first unvalued bar, if any.
Definition report.hpp:154
std::size_t limit_fills_bounded_
Limit-type fills whose price was moved to stay within the bar's range and the limit (see LimitFillPri...
Definition report.hpp:173
bool multiple_instruments_
Whether more than one instrument traded: a caution about survivorship bias.
Definition report.hpp:77
int slippage_ticks_
The ticks of slippage configured; fewer apply where the grid has no further step.
Definition report.hpp:67
std::size_t unfilled_
Orders still queued, unfilled, when the replay ended.
Definition report.hpp:83
std::string market_price_rule_
The fill model's market-price rule (NextBarFillModel::with_market_price), or empty when market orders...
Definition report.hpp:181
std::size_t market_fills_by_rule_
How many fills the market-price rule priced.
Definition report.hpp:183
static constexpr bool bar_tape_unverified
Always true: the replay cannot know which venue's tape its bars came from.
Definition report.hpp:125
std::optional< Money > lowest_cash_
The lowest cash an execution left, if it went below zero.
Definition report.hpp:195
std::size_t stop_fills_intrabar_
Fills of stops released inside a bar, which assume the price moved continuously through the trigger.
Definition report.hpp:168
std::optional< std::chrono::system_clock::time_point > first_overdrawn_
The first bar end at which cash was below zero.
Definition report.hpp:193
std::optional< std::chrono::system_clock::time_point > lowest_cash_at_
When the lowest cash was reached.
Definition report.hpp:206
std::size_t overdrawn_bars_
Bars that closed with cash below zero in the replay's currency: the replay borrowed,...
Definition report.hpp:191
std::string commission_tariff_
The tariff the commission schedule named; empty for a flat model.
Definition report.hpp:56
std::size_t unchecked_fill_causality_
How many times a fill was allowed without the engine being able to prove its price came after the dec...
Definition report.hpp:110
bool cost_totals_incomplete_
Whether some cost could not be summed exactly, so the cost totals are incomplete.
Definition report.hpp:63
std::size_t unvalued_bars_
Bars whose equity total could not be computed exactly (ReplayResult::unvalued_bars_).
Definition report.hpp:152
std::optional< SellTax > sell_tax_
The sale tax given to the fill model; absent if none was modelled.
Definition report.hpp:208
std::vector< AppliedRate > applied_rates_
Every commission rate that charged an execution, with how many it charged.
Definition report.hpp:40
Decimal64 slippage_basis_points_
The basis points of slippage applied.
Definition report.hpp:65
std::size_t expired_day_orders_
DAY orders withdrawn unfilled when their session ended, as they would expire live.
Definition report.hpp:210
LimitFillPrice limit_fill_
Which price a filled limit order was credited.
Definition report.hpp:33
std::size_t other_currency_executions_
Executions in a currency other than the equity curve's (ReplayConfig::currency_).
Definition report.hpp:204
std::optional< VenueKey > asserted_venue_
The venue costs were computed at, as the caller asserted it (a replay cannot observe where a fill exe...
Definition report.hpp:54
static constexpr bool buying_power_is_ledger_cash
Always true: a replay's buying power is the ledger's own cash, not a broker's figure.
Definition report.hpp:142
static constexpr bool sellable_is_whole_holding
Always true: a replay reports every held share as sellable.
Definition report.hpp:133
The summary of a replay; read halted_ and caveats_ before the figures.
Definition report.hpp:218
std::optional< BrokerError > halted_
Why the replay stopped early, if it did; read this before any figure.
Definition report.hpp:311
math::Scalar total_turnover_
One-way turnover summed over the replay, as a fraction of equity.
Definition report.hpp:262
std::optional< Decimal64 > slippage_paid_
Slippage given up, in money.
Definition report.hpp:294
Decimal64 opening_equity_
Equity at the first recorded point.
Definition report.hpp:225
math::Scalar total_return_
The total return over the replay, as a fraction; math::undefined() when the opening equity is zero or...
Definition report.hpp:233
Decimal64 closing_equity_
Equity at the last recorded point.
Definition report.hpp:227
math::Scalar max_drawdown_
The worst peak-to-trough decline of equity, as a non-negative fraction.
Definition report.hpp:255
std::size_t refused_
Instructions a risk guard refused.
Definition report.hpp:301
std::vector< Money > commission_by_currency_
Commission paid per currency.
Definition report.hpp:273
std::size_t rejected_
Instructions not placed: reconciliation could not build them, or the replay cannot model them (BINDIN...
Definition report.hpp:299
std::optional< Decimal64 > tax_paid_
Sale tax paid.
Definition report.hpp:324
std::size_t aborted_
Orders cleared from the queue by a halt (unlike ReportCaveats::unfilled_).
Definition report.hpp:313
math::Scalar annualized_sharpe_
The annualized Sharpe ratio; missing() unless a period count was given to summarize.
Definition report.hpp:247
math::Scalar sortino_
The per-period Sortino ratio; see analytics::sortino.
Definition report.hpp:253
std::size_t bars_
The bars replayed.
Definition report.hpp:220
std::vector< Money > institution_by_currency_
Institution fees per currency.
Definition report.hpp:287
std::vector< Money > slippage_by_currency_
Slippage given up per currency.
Definition report.hpp:296
std::optional< Decimal64 > institution_fees_paid_
Institution fees (유관기관제비용) paid.
Definition report.hpp:280
std::optional< Decimal64 > commission_paid_
Commission paid.
Definition report.hpp:271
std::vector< Money > tax_by_currency_
Sale tax paid per currency, over executions in the taxed market.
Definition report.hpp:326
math::Scalar sharpe_
The per-period Sharpe ratio; see analytics::sharpe.
Definition report.hpp:241
ReportCaveats caveats_
What this run assumed and did not model.
Definition report.hpp:316
std::size_t executions_
The executions.
Definition report.hpp:222
Decimal64 basis_points_
The price given up per execution, in ten-thousandths of the price.
Definition cost.hpp:442
int ticks_
Grid steps given up per execution, each a step to the next grid price against the order.
Definition cost.hpp:444