FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::bt Namespace Reference

Classes

struct  AbArmSummary
 
struct  AbCell
 One instrument in one arm over one block (the whole test with assignment = "instrument"). More...
 
struct  AbEffect
 One arm against arm 0 on one metric. More...
 
struct  AbHorizon
 
struct  AbReport
 
struct  AbReportOptions
 
struct  ArrayColumns
 
class  ArraySource
 
struct  BacktestConfig
 
struct  BacktestResult
 
class  BacktestRunner
 Convenience wrapper that owns the config. More...
 
class  BacktestSession
 
struct  BacktestTreasury
 The pool treasuries of a run ([venues. More...
 
class  ChainSource
 Concatenation of sources that cover consecutive spans of time (one file per day). More...
 
class  CsvSource
 
struct  EquityRows
 
struct  FillQuality
 Diagnostics of how the fills were obtained, next to the markouts. More...
 
struct  FillRows
 
struct  InstrumentEquityRows
 One instrument's columns of EquityRows, one row per bar. More...
 
struct  JournalInfo
 
class  JournalSource
 
struct  LiveAnalysis
 
struct  LiveAnalysisInstrument
 
struct  MarkoutBucket
 
struct  MarkoutHorizon
 Buckets of one horizon, all over the same measured fills. More...
 
class  MergedSource
 k-way merge of several sources by event time (stable: lower source index first on ties). More...
 
struct  Metrics
 
struct  MetricsInputs
 
struct  OrderRows
 
class  OrderStats
 The order half of the metrics, kept as a run goes: the counts of new orders, cancels and replaces, the virtual tick-to-order latency, and each new order's first fill for the fill quality's quotes filled and time to fill (a replace chain's fills count for the new order that began it, at the earliest of them). More...
 
class  OwnedMergedSource
 MergedSource over sources it owns: open_data() of several specs ("a; b"), one per venue. More...
 
struct  PnlDecomposition
 How the net PnL of the run splits into the parts a market maker can act on: net == spread_capture + mid_drift - fees_paid + rebates_received + residual mid_drift is the move of the mid from each fill to the end of the run, valued at the signed quantity of the fill: adverse selection plus the mark-to-market of whatever is still open. More...
 
struct  ReplayOptions
 
struct  ReplayResult
 
struct  ReplayStrategy
 A strategy outside the registry (a Python hot strategy): the name for the result, the parameter schema that ParamUpdate fields are matched against, and a factory that builds the runner on the sim::ReplayBackend that deps.backend points at. More...
 
struct  Row
 
class  RowAssembler
 Builds messages from a row stream. Provider is bool(Row&) returning false at end. More...
 
struct  SlowMethodTiming
 Wall time of one slow method of a Python strategy over a backtest. More...
 
struct  StartPosition
 One [backtest.positions] row: the engine starts with this position in the instrument. More...
 
struct  SweepPoint
 
class  SyntheticSource
 
struct  SyntheticSourceConfig
 
class  TimeSliceSource
 The events of inner in [t0, t1) of event time (exch_ts, recv_ts when unset), for walk-forward folds. More...
 
struct  WalkForwardFold
 
struct  WalkForwardReport
 

Concepts

concept  DataSourceLike
 

Typedefs

using ParamGrid = std::vector< std::pair< std::string, std::vector< std::string > > >
 
using SweepPoints = std::vector< ParamMap >
 The points of a sweep, in order: a grid expanded (expand_grid) or any list.
 
using SourceFactory = std::function< std::unique_ptr< MdSource >()>
 may return nullptr
 
using RunFn = std::function< BacktestResult(const BacktestConfig &, MdSource *)>
 
using ResultHook = std::function< void(std::size_t index, BacktestResult &result)>
 Called with each point's result as it is done (index in the list of points or configurations), one call at a time, before it is kept: a caller that needs less of it (the CLI prints the metrics) can drop the rest there, so a sweep of thousands of points holds no more than that.
 
using ScoreFn = std::function< double(const BacktestResult &)>
 Ranking metric of a run, higher is better.
 

Enumerations

enum class  InitialState : std::uint8_t { StateFile = 0 , Journal = 1 , None = 2 }
 Where the strategy's starting state comes from ([backtest] initial_state). More...
 
enum class  RowType : std::uint8_t { Snapshot = 0 , Delta = 1 , Trade = 2 , Ticker = 3 }
 

Functions

template<StrategyLike S>
BacktestResult run_backtest (const BacktestConfig &cfg, MdSource *source=nullptr)
 
BacktestResult run_backtest (const BacktestConfig &cfg, std::string_view strategy, MdSource *source=nullptr)
 Registry path (registers the built-in strategies first).
 
BacktestConfig shared_start (BacktestConfig cfg)
 cfg for runs that start from one place: the points of a sweep, the folds of a walk-forward, the arms of an [ab] branch test.
 
SyntheticSourceConfig synthetic_source_config (const BacktestConfig &cfg)
 The SyntheticSource a run with source == nullptr replays under the L2 queue fill model.
 
void warn_unfed_instruments (const InstrumentTable &instruments, std::span< const std::uint64_t > by_instrument)
 Logs a warning for each instrument the data gave no events, and for the events that named an instrument id past the table.
 
std::unique_ptr< MdSource > open_data (std::string_view spec, const InstrumentTable *instruments=nullptr)
 Resolves --data through the data-source registry (data_registry.hpp): "\<name\>:\<args\>", or a bare *.fmj / *.csv path.
 
std::unique_ptr< MdSource > open_source (const BacktestConfig &cfg)
 Source for [backtest] source / path.
 
std::string result_difference (const BacktestResult &a, const BacktestResult &b)
 The first thing two results of one configuration differ in, as "field[row]: a vs b", or empty when they are the same: every fill (time, instrument, side, price, quantity, fee, order id, liquidity, the venue's book and queue at the fill, the mids at each markout horizon), every order sent, every equity bar, the engine's and the venue's counts, positions and PnL, and the outbound hash.
 
Metrics compute_metrics (const EquityRows &equity, const FillRows &fills, OrderStats &orders, const MetricsInputs &in)
 
Metrics compute_metrics (const EquityRows &equity, const FillRows &fills, const OrderRows &orders, const MetricsInputs &in)
 
LiveAnalysis analyze_live (const std::string &path, std::span< const std::int64_t > horizons_ns)
 Throws std::runtime_error when the journal cannot be read.
 
std::string format_live_analysis (const LiveAnalysis &a)
 
std::string live_analysis_json (const LiveAnalysis &a)
 
AbReport ab_report (std::span< const std::string > journals, const AbReportOptions &opt)
 Throws std::runtime_error when a journal cannot be read, has no [ab] in its configuration, or the journals ran different tests.
 
void add_noise_floor (AbReport &r, const AbReport &aa)
 Puts aa's interval half-widths next to the matching effects of r (by metric).
 
std::string format_ab_report (const AbReport &r)
 
std::string ab_report_json (const AbReport &r)
 
std::string ab_cells_csv (const AbReport &r)
 One row per cell.
 
SweepPoints expand_grid (const ParamGrid &grid)
 Expands the grid in order: [{k1: v11, k2: v21}, {k1: v11, k2: v22}, ...].
 
BacktestConfig point_config (const BacktestConfig &start, const ParamMap &point)
 The configuration a point runs: start (shared_start() of the sweep's base) with each key of point set, a key of kSweepSettings as that backtest setting (BacktestConfig::set_setting) and any other as a strategy parameter; no output directory, journal or order rows.
 
std::vector< SweepPoint > sweep (const BacktestConfig &base, const SweepPoints &points, const SourceFactory &source_factory, const RunFn &run, int threads=0, const ResultHook &done={})
 Generic driver; run is called once per point on a worker thread.
 
std::vector< SweepPoint > sweep (const BacktestConfig &base, const ParamGrid &grid, const SourceFactory &source_factory, const RunFn &run, int threads=0, const ResultHook &done={})
 
template<StrategyLike S>
std::vector< SweepPoint > sweep (const BacktestConfig &base, const ParamGrid &grid, const SourceFactory &source_factory={}, int threads=0)
 
std::vector< SweepPoint > sweep_by_name (const BacktestConfig &base, std::string strategy, const SweepPoints &points, const SourceFactory &source_factory={}, int threads=0, bool separately=false, const ResultHook &done={})
 A registered strategy's sweep.
 
std::vector< SweepPoint > sweep_by_name (const BacktestConfig &base, std::string strategy, const ParamGrid &grid, const SourceFactory &source_factory={}, int threads=0, bool separately=false, const ResultHook &done={})
 
ScoreFn score_metric (std::string_view name)
 
std::vector< Timestamp > fold_edges (const BacktestConfig &base, const SourceFactory &source_factory, int folds)
 The k + 1 edges of folds equal slices of the data's event-time range: fold i is [edges[i], edges[i + 1]).
 
std::unique_ptr< MdSource > fold_source (const BacktestConfig &base, std::unique_ptr< MdSource > inner, Timestamp t0, Timestamp t1)
 The cursor a walk-forward fold reads: inner from t0 to t1, owning it.
 
void score_walk_forward (WalkForwardReport &rep, const ScoreFn &score_fn={})
 Scores the points of every fold of rep by score_fn, or by the metric named rep.metric when score_fn is empty, and fills in best, chosen, the in-sample / out-of-sample / hindsight scores, the means and the choice changes.
 
WalkForwardReport walk_forward (const BacktestConfig &base, const SweepPoints &points, const SourceFactory &source_factory, const RunFn &run, int folds, std::string_view metric="net_pnl", int threads=0)
 Splits the data's event-time range into folds equal slices and runs the whole grid on each one (a fresh backtest per point and fold, all on one pool of threads workers).
 
WalkForwardReport walk_forward (const BacktestConfig &base, const ParamGrid &grid, const SourceFactory &source_factory, const RunFn &run, int folds, std::string_view metric="net_pnl", int threads=0)
 
WalkForwardReport walk_forward_by_name (const BacktestConfig &base, std::string strategy, const SweepPoints &points, const SourceFactory &source_factory, int folds, std::string_view metric="net_pnl", int threads=0, const ResultHook &done={})
 walk_forward() of a registered strategy.
 
WalkForwardReport walk_forward_by_name (const BacktestConfig &base, std::string strategy, const ParamGrid &grid, const SourceFactory &source_factory, int folds, std::string_view metric="net_pnl", int threads=0, const ResultHook &done={})
 
JournalInfo inspect_journal (const std::string &path)
 Throws std::runtime_error when the file cannot be opened / validated.
 
BacktestConfig journal_config (const std::string &path)
 The configuration embedded in the journal.
 
std::string describe_outbound (const EventHeader &h)
 One-line description of an Out* message (type, ids, side, price, quantity, stamp).
 
ReplayResult replay_journal (const std::string &path, const BacktestConfig &cfg, const ReplayOptions &opt={})
 cfg supplies the engine configuration and strategy parameters (it must match the recording run for a verifying replay); the instrument table is taken from the journal.
 
ReplayResult replay_journal (const std::string &path, const BacktestConfig &cfg, const ReplayOptions &opt, const ReplayStrategy &strategy)
 Replays strategy instead of a registered one (opt.strategy is ignored).
 
ReplayResult replay_journal (const std::string &path, const ReplayOptions &opt={})
 Replays with the journal's embedded configuration (journal_config(path)).
 
std::uint64_t write_md_journal (MdSource &source, const std::string &path, const InstrumentTable &instruments, std::uint64_t seed, std::string_view strategy="data", std::uint64_t max_events=0)
 Writes the events of source (all, or the first max_events when non-zero) to a fresh .fmj with JournalFileWriter (instrument table + header stamped with seed); used to produce fixtures.
 

Variables

constexpr std::array< std::string_view, 8 > kSweepSettings
 The backtest settings a sweep's point can vary besides the strategy's parameters (BacktestConfig::set_setting).
 
constexpr double kDefaultSpreadBps = 4.0
 The [sim] defaults of a configuration file: a liquid crypto pair.
 
constexpr double kDefaultMidStepBps = 0.5
 
constexpr double kDefaultDepthBps = 1.0
 
constexpr std::uint8_t kOrderKindNew = 0
 
constexpr std::uint8_t kOrderKindCancel = 1
 
constexpr std::uint8_t kOrderKindReplace = 2
 
constexpr double kMinAnnualizedDurationS = 86400.0
 Shortest run whose Sharpe ratio is annualised: one day.
 
constexpr std::int64_t kDefaultMarkoutHorizonsNs []
 Horizons measured by default, in simulated time.
 

Typedef Documentation

◆ ParamGrid

using fastmm::bt::ParamGrid = typedef std::vector<std::pair<std::string, std::vector<std::string> >>

◆ SweepPoints

using fastmm::bt::SweepPoints = typedef std::vector<ParamMap>

The points of a sweep, in order: a grid expanded (expand_grid) or any list.

◆ SourceFactory

using fastmm::bt::SourceFactory = typedef std::function<std::unique_ptr<MdSource>()>

may return nullptr

◆ RunFn

using fastmm::bt::RunFn = typedef std::function<BacktestResult(const BacktestConfig&, MdSource*)>

◆ ResultHook

using fastmm::bt::ResultHook = typedef std::function<void(std::size_t index, BacktestResult& result)>

Called with each point's result as it is done (index in the list of points or configurations), one call at a time, before it is kept: a caller that needs less of it (the CLI prints the metrics) can drop the rest there, so a sweep of thousands of points holds no more than that.

◆ ScoreFn

using fastmm::bt::ScoreFn = typedef std::function<double(const BacktestResult&)>

Ranking metric of a run, higher is better.

score_metric() names four, "net_pnl", "realized_pnl", "sharpe_bar" and "spread_captured_bps", and throws std::invalid_argument for any other name.

Enumeration Type Documentation

◆ InitialState

enum class fastmm::bt::InitialState : std::uint8_t
strong

Where the strategy's starting state comes from ([backtest] initial_state).

Enumerator
StateFile 

[strategy] state_file, when set

Journal 

the data journal's (journal_state.hpp), with the session's positions

None 

nothing: the strategy starts fresh

◆ RowType

enum class fastmm::bt::RowType : std::uint8_t
strong
Enumerator
Snapshot 
Delta 
Trade 
Ticker 

Function Documentation

◆ run_backtest() [1/2]

template<StrategyLike S>
BacktestResult fastmm::bt::run_backtest ( const BacktestConfig &  cfg,
MdSource *  source = nullptr 
)

◆ run_backtest() [2/2]

BacktestResult fastmm::bt::run_backtest ( const BacktestConfig &  cfg,
std::string_view  strategy,
MdSource *  source = nullptr 
)

Registry path (registers the built-in strategies first).

Throws std::invalid_argument for an unknown strategy or bad parameters.

◆ shared_start()

BacktestConfig fastmm::bt::shared_start ( BacktestConfig  cfg)

cfg for runs that start from one place: the points of a sweep, the folds of a walk-forward, the arms of an [ab] branch test.

The [strategy] state_file is read once into the strategy's initial state and dropped, so every run restores the same bytes and none writes its end state back, where the runs would race on the file and each would start from another's end. Throws std::invalid_argument when the file cannot be read.

◆ synthetic_source_config()

SyntheticSourceConfig fastmm::bt::synthetic_source_config ( const BacktestConfig &  cfg)

The SyntheticSource a run with source == nullptr replays under the L2 queue fill model.

◆ warn_unfed_instruments()

void fastmm::bt::warn_unfed_instruments ( const InstrumentTable &  instruments,
std::span< const std::uint64_t >  by_instrument 
)

Logs a warning for each instrument the data gave no events, and for the events that named an instrument id past the table.

by_instrument: events per id, its last entry those past the table (sim::SimDriver::by_instrument()).

◆ open_data()

std::unique_ptr< MdSource > fastmm::bt::open_data ( std::string_view  spec,
const InstrumentTable *  instruments = nullptr 
)

Resolves --data through the data-source registry (data_registry.hpp): "\<name\>:\<args\>", or a bare *.fmj / *.csv path.

"synthetic" (and "") open to nullptr, which selects the market generator. instruments lets a source map its symbols onto instrument ids; it may be null. Throws std::runtime_error for an unknown source, bad options or unreadable files.

◆ open_source()

std::unique_ptr< MdSource > fastmm::bt::open_source ( const BacktestConfig &  cfg)

Source for [backtest] source / path.

source is a whole spec ("binance:BTCUSDT:2024-03-27"); a bare name plus path ("journal" + "x.fmj") is the same thing written as two keys.

◆ result_difference()

std::string fastmm::bt::result_difference ( const BacktestResult &  a,
const BacktestResult &  b 
)

The first thing two results of one configuration differ in, as "field[row]: a vs b", or empty when they are the same: every fill (time, instrument, side, price, quantity, fee, order id, liquidity, the venue's book and queue at the fill, the mids at each markout horizon), every order sent, every equity bar, the engine's and the venue's counts, positions and PnL, and the outbound hash.

Wall-clock figures are not compared. What a multiverse's run is checked against its own backtest with (fastmm-backtest --verify, fastmm.sweep(verify=...)).

◆ compute_metrics() [1/2]

Metrics fastmm::bt::compute_metrics ( const EquityRows &  equity,
const FillRows &  fills,
OrderStats &  orders,
const MetricsInputs &  in 
)

◆ compute_metrics() [2/2]

Metrics fastmm::bt::compute_metrics ( const EquityRows &  equity,
const FillRows &  fills,
const OrderRows &  orders,
const MetricsInputs &  in 
)

◆ analyze_live()

LiveAnalysis fastmm::bt::analyze_live ( const std::string &  path,
std::span< const std::int64_t >  horizons_ns 
)

Throws std::runtime_error when the journal cannot be read.

◆ format_live_analysis()

std::string fastmm::bt::format_live_analysis ( const LiveAnalysis &  a)

◆ live_analysis_json()

std::string fastmm::bt::live_analysis_json ( const LiveAnalysis &  a)

◆ ab_report()

AbReport fastmm::bt::ab_report ( std::span< const std::string >  journals,
const AbReportOptions &  opt 
)

Throws std::runtime_error when a journal cannot be read, has no [ab] in its configuration, or the journals ran different tests.

◆ add_noise_floor()

void fastmm::bt::add_noise_floor ( AbReport &  r,
const AbReport &  aa 
)

Puts aa's interval half-widths next to the matching effects of r (by metric).

◆ format_ab_report()

std::string fastmm::bt::format_ab_report ( const AbReport &  r)

◆ ab_report_json()

std::string fastmm::bt::ab_report_json ( const AbReport &  r)

◆ ab_cells_csv()

std::string fastmm::bt::ab_cells_csv ( const AbReport &  r)

One row per cell.

◆ expand_grid()

SweepPoints fastmm::bt::expand_grid ( const ParamGrid &  grid)

Expands the grid in order: [{k1: v11, k2: v21}, {k1: v11, k2: v22}, ...].

◆ point_config()

BacktestConfig fastmm::bt::point_config ( const BacktestConfig &  start,
const ParamMap &  point 
)

The configuration a point runs: start (shared_start() of the sweep's base) with each key of point set, a key of kSweepSettings as that backtest setting (BacktestConfig::set_setting) and any other as a strategy parameter; no output directory, journal or order rows.

◆ sweep() [1/3]

std::vector< SweepPoint > fastmm::bt::sweep ( const BacktestConfig &  base,
const SweepPoints &  points,
const SourceFactory &  source_factory,
const RunFn &  run,
int  threads = 0,
const ResultHook &  done = {} 
)

Generic driver; run is called once per point on a worker thread.

threads <= 0 uses hardware_concurrency.

◆ sweep() [2/3]

std::vector< SweepPoint > fastmm::bt::sweep ( const BacktestConfig &  base,
const ParamGrid &  grid,
const SourceFactory &  source_factory,
const RunFn &  run,
int  threads = 0,
const ResultHook &  done = {} 
)

◆ sweep() [3/3]

template<StrategyLike S>
std::vector< SweepPoint > fastmm::bt::sweep ( const BacktestConfig &  base,
const ParamGrid &  grid,
const SourceFactory &  source_factory = {},
int  threads = 0 
)

◆ sweep_by_name() [1/2]

std::vector< SweepPoint > fastmm::bt::sweep_by_name ( const BacktestConfig &  base,
std::string  strategy,
const SweepPoints &  points,
const SourceFactory &  source_factory = {},
int  threads = 0,
bool  separately = false,
const ResultHook &  done = {} 
)

A registered strategy's sweep.

Under the queue fill models (l2_queue, l3_queue) the points share their passes over the data (sweep_multiverse(), multiverse.hpp) with the results each gives alone; otherwise, or with separately, every point is a backtest of its own.

◆ sweep_by_name() [2/2]

std::vector< SweepPoint > fastmm::bt::sweep_by_name ( const BacktestConfig &  base,
std::string  strategy,
const ParamGrid &  grid,
const SourceFactory &  source_factory = {},
int  threads = 0,
bool  separately = false,
const ResultHook &  done = {} 
)

◆ score_metric()

ScoreFn fastmm::bt::score_metric ( std::string_view  name)

◆ fold_edges()

std::vector< Timestamp > fastmm::bt::fold_edges ( const BacktestConfig &  base,
const SourceFactory &  source_factory,
int  folds 
)

The k + 1 edges of folds equal slices of the data's event-time range: fold i is [edges[i], edges[i + 1]).

Reads one cursor from source_factory to the end; an empty factory (or one returning nullptr) reads the synthetic market as a SyntheticSource stream, which needs fill_model l2_queue (std::invalid_argument otherwise, and for data with no events or folds < 2).

◆ fold_source()

std::unique_ptr< MdSource > fastmm::bt::fold_source ( const BacktestConfig &  base,
std::unique_ptr< MdSource >  inner,
Timestamp  t0,
Timestamp  t1 
)

The cursor a walk-forward fold reads: inner from t0 to t1, owning it.

A null inner is the synthetic market of base as a stream (fill_model l2_queue; std::invalid_argument otherwise).

◆ score_walk_forward()

void fastmm::bt::score_walk_forward ( WalkForwardReport &  rep,
const ScoreFn &  score_fn = {} 
)

Scores the points of every fold of rep by score_fn, or by the metric named rep.metric when score_fn is empty, and fills in best, chosen, the in-sample / out-of-sample / hindsight scores, the means and the choice changes.

With one fold, its start_ts / end_ts are set from its results. walk_forward() ends with it; a caller that ran the points itself (the Python package, for strategies written in Python) or ranks by a score of its own calls it directly. Throws std::invalid_argument for an unknown metric.

◆ walk_forward() [1/2]

WalkForwardReport fastmm::bt::walk_forward ( const BacktestConfig &  base,
const SweepPoints &  points,
const SourceFactory &  source_factory,
const RunFn &  run,
int  folds,
std::string_view  metric = "net_pnl",
int  threads = 0 
)

Splits the data's event-time range into folds equal slices and runs the whole grid on each one (a fresh backtest per point and fold, all on one pool of threads workers).

Each fold reads a TimeSliceSource over the worker's cursor, so it starts on the book as of its first instant with a flat engine. folds == 1 is exactly sweep(). The synthetic market (source_factory empty or returning nullptr) is sliced as a SyntheticSource stream, which needs fill_model l2_queue: the coupled matching market cannot be cut and throws std::invalid_argument.

◆ walk_forward() [2/2]

WalkForwardReport fastmm::bt::walk_forward ( const BacktestConfig &  base,
const ParamGrid &  grid,
const SourceFactory &  source_factory,
const RunFn &  run,
int  folds,
std::string_view  metric = "net_pnl",
int  threads = 0 
)

◆ walk_forward_by_name() [1/2]

WalkForwardReport fastmm::bt::walk_forward_by_name ( const BacktestConfig &  base,
std::string  strategy,
const SweepPoints &  points,
const SourceFactory &  source_factory,
int  folds,
std::string_view  metric = "net_pnl",
int  threads = 0,
const ResultHook &  done = {} 
)

walk_forward() of a registered strategy.

Under the queue fill models the points of each fold share their passes over the fold's data (sweep_multiverse(), multiverse.hpp), with the same report. done sees each result, with index fold * points + point (ResultHook).

◆ walk_forward_by_name() [2/2]

WalkForwardReport fastmm::bt::walk_forward_by_name ( const BacktestConfig &  base,
std::string  strategy,
const ParamGrid &  grid,
const SourceFactory &  source_factory,
int  folds,
std::string_view  metric = "net_pnl",
int  threads = 0,
const ResultHook &  done = {} 
)

◆ inspect_journal()

JournalInfo fastmm::bt::inspect_journal ( const std::string &  path)

Throws std::runtime_error when the file cannot be opened / validated.

◆ journal_config()

BacktestConfig fastmm::bt::journal_config ( const std::string &  path)

The configuration embedded in the journal.

Throws std::runtime_error when there is none (v1 journals, market-data journals, hand-built backtest configurations) or it does not parse.

◆ describe_outbound()

std::string fastmm::bt::describe_outbound ( const EventHeader &  h)

One-line description of an Out* message (type, ids, side, price, quantity, stamp).

◆ replay_journal() [1/3]

ReplayResult fastmm::bt::replay_journal ( const std::string &  path,
const BacktestConfig &  cfg,
const ReplayOptions &  opt = {} 
)

cfg supplies the engine configuration and strategy parameters (it must match the recording run for a verifying replay); the instrument table is taken from the journal.

Throws std::runtime_error / std::invalid_argument on unreadable journals or unknown strategies.

◆ replay_journal() [2/3]

ReplayResult fastmm::bt::replay_journal ( const std::string &  path,
const BacktestConfig &  cfg,
const ReplayOptions &  opt,
const ReplayStrategy &  strategy 
)

Replays strategy instead of a registered one (opt.strategy is ignored).

◆ replay_journal() [3/3]

ReplayResult fastmm::bt::replay_journal ( const std::string &  path,
const ReplayOptions &  opt = {} 
)

Replays with the journal's embedded configuration (journal_config(path)).

◆ write_md_journal()

std::uint64_t fastmm::bt::write_md_journal ( MdSource &  source,
const std::string &  path,
const InstrumentTable &  instruments,
std::uint64_t  seed,
std::string_view  strategy = "data",
std::uint64_t  max_events = 0 
)

Writes the events of source (all, or the first max_events when non-zero) to a fresh .fmj with JournalFileWriter (instrument table + header stamped with seed); used to produce fixtures.

Returns the number of events written.

Variable Documentation

◆ kSweepSettings

constexpr std::array<std::string_view, 8> fastmm::bt::kSweepSettings
inlineconstexpr
Initial value:
= {"latency_fixed_us",
"latency_jitter_us",
"latency_md_us",
"latency_md_jitter_us",
"p_drop",
"queue_conservatism",
"maker_fee_bps",
"taker_fee_bps"}

The backtest settings a sweep's point can vary besides the strategy's parameters (BacktestConfig::set_setting).

The Python BacktestConfig has an attribute of each name.

◆ kDefaultSpreadBps

constexpr double fastmm::bt::kDefaultSpreadBps = 4.0
inlineconstexpr

The [sim] defaults of a configuration file: a liquid crypto pair.

New limit orders leave 4 bps around the latent mid and rest 1 bps behind that on average; orders a mid move left behind rest inside it, so the book's spread is 1.7 to 3.4 bps (10th to 90th percentile), 2.7 at the median. Latent mid steps of 0.5 bps, 2 a second calm and 8 volatile, give 0.4 to 0.7 bps of volatility a square-root second.

◆ kDefaultMidStepBps

constexpr double fastmm::bt::kDefaultMidStepBps = 0.5
inlineconstexpr

◆ kDefaultDepthBps

constexpr double fastmm::bt::kDefaultDepthBps = 1.0
inlineconstexpr

◆ kOrderKindNew

constexpr std::uint8_t fastmm::bt::kOrderKindNew = 0
inlineconstexpr

◆ kOrderKindCancel

constexpr std::uint8_t fastmm::bt::kOrderKindCancel = 1
inlineconstexpr

◆ kOrderKindReplace

constexpr std::uint8_t fastmm::bt::kOrderKindReplace = 2
inlineconstexpr

◆ kMinAnnualizedDurationS

constexpr double fastmm::bt::kMinAnnualizedDurationS = 86400.0
inlineconstexpr

Shortest run whose Sharpe ratio is annualised: one day.

◆ kDefaultMarkoutHorizonsNs

constexpr std::int64_t fastmm::bt::kDefaultMarkoutHorizonsNs[]
inlineconstexpr
Initial value:
= {
1'000'000'000LL, 10'000'000'000LL, 60'000'000'000LL}

Horizons measured by default, in simulated time.