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

#include <fastmm/backtest/backtest_config.hpp>

Public Member Functions

bool publishes_params () const noexcept
 The run publishes parameter updates of its own: [ab] or [strategy.overrides] (BacktestSession::enable_ab).
 
FxPlan fx_plan (const InstrumentTable &table)
 The FX plan for table under accounting (throws ConfigError when a limit reads the totals and the table is not covered; otherwise a warning goes to warnings and nothing converts).
 
UnderlyingPlan underlying_plan (const InstrumentTable &table) const
 The [risk.underlying] plan for table (throws ConfigError when the spec does not fit it).
 
void set_market_bps (double spread_bps, double mid_step_bps, double depth_bps)
 The synthetic market in basis points of generator.start_mid, turned into ticks of generator.tick: the spread from touch to touch (base_spread_ticks, half of it a side), the size of a latent mid step (mid_step_ticks) and the mean distance of a new limit order behind the touch (depth_ticks).
 
bool set_setting (std::string_view key, std::string_view value)
 Sets one of kSweepSettings from its decimal value: latency_fixed_us and latency_jitter_us the order and ack paths of the venues without a [backtest.venues.
 
void set_param (const std::string &key, const std::string &value)
 "key=value" strategy parameter override (CLI --param).
 
void set_seed (std::uint64_t s) noexcept
 Seeds the synthetic market and the latency model.
 

Static Public Member Functions

static BacktestConfig from_config (const Config &cfg)
 Throws ConfigError on invalid values.
 
static BacktestConfig single_instrument (std::string_view symbol, Price tick, Qty lot)
 One instrument (venue 0) with the given tick/lot; generator tick/lot follow (examples).
 

Public Attributes

EngineConfig engine
 
InstrumentTable instruments
 
std::string strategy
 registry name (apps / Python); ignored by run_backtest<S>()
 
ParamMap params
 
sim::SimTransportConfig transport
 
sim::MarketGeneratorParams generator
 
std::uint64_t seed = 1
 synthetic market + latency model (engine.rng_seed is separate)
 
Timestamp start {seconds(1'700'000'000).ns}
 
Duration duration = seconds(60)
 synthetic horizon
 
Duration equity_bar = seconds(1)
 
double initial_capital = 0.0
 reporting only (drawdown %)
 
AccountingSpec accounting
 [accounting] and the venue names its sources name (Config::venues order).
 
std::vector< std::string > venue_names
 
UnderlyingSpec underlying
 [risk.underlying]: from_config() builds engine.underlying from it for instruments; replay builds it again for the journal's table.
 
std::vector< std::string > warnings
 from_config: Config::warnings plus unknown [backtest] keys, each naming the key and its line.
 
int generator_seed_levels = 20
 
std::string source
 "synthetic" | "journal" | "csv" | "" (caller supplies the source)
 
std::string path
 
std::string output_dir
 
std::string journal_out
 record the run to this .fmj (empty = no journal)
 
MsgRing * record_ring = nullptr
 Where the engine puts its records (core/record_stream.hpp), as fastmm-live hands them to the store: the caller's ring, drained by the caller, large enough for the run (a full ring drops records).
 
std::string config_toml
 Effective configuration embedded in journal_out (Config::effective_toml(); from_config() sets it, hand-built configs leave it empty).
 
bool measure_wall_clock = true
 
bool keep_orders = true
 The result keeps a row for every order sent (BacktestResult::orders).
 
std::vector< Duration > markout_horizons = {seconds(1), seconds(10), seconds(60)}
 Post-fill markout horizons in simulated time; empty turns markouts off.
 
bool balances_from_journal = false
 Start each venue's account (transport.accounts) from the first balance snapshot the journal source recorded for it; a venue it has none for keeps the configured balances.
 
std::vector< TreasuryConfig > treasuries
 The pool treasuries ([venues.
 
Duration transfer_latency {}
 [backtest] transfer_latency_ms: a simulated transfer is carried out this long after it is sent.
 
double transfer_p_fail = 0.0
 [backtest] transfer_p_fail, transfer_p_unknown, transfer_hang_ms: the simulated venue refuses a transfer, or loses its answer and carries it out transfer_hang later (sim::SimTransferFaults).
 
double transfer_p_unknown = 0.0
 
Duration transfer_hang = milliseconds(90'000)
 
InitialState initial_state = InitialState::StateFile
 The strategy's starting state; Journal also starts the engine's positions where the recorded session had them (sim::SessionStart).
 
std::vector< StartPosition > positions
 [backtest.positions]: the engine's positions at the start, by instrument. They replace the
 
Timestamp start_at {}
 [backtest] start_at: the run reads the data from its start (the books and the strategy's view of the market warm up), but trading starts later: with initial_state = "journal" at the last checkpoint of the data journal at or before this time, whose state the strategy restores as a warm standby's take-over does, else at this time.
 
bool latency_from_journal = false
 [backtest] latency_from_journal: the simulated venues take a message's latency from the data journal's own messages around the same time where that is longer than the model's draw (sim/recorded_latency.hpp); the data source must be a journal.
 
bool params_from_journal = false
 The data journal's parameter updates reach the strategy at the times the session received them (sim::RecordedParams), mapped by name and type onto its schema.
 
std::vector< std::string > params_pinned
 params_from_journal leaves these parameters at the configured values: a counterfactual run keeps the session's other updates ([backtest] params_pinned, comma-separated).
 
bool controls_from_journal = false
 The data journal's operator commands (sim::replayable_control) reach the engine at the times the session received them.
 
AbSection ab
 [ab]: an A/B test of the strategy's parameters (strategies/ab_test.hpp); no arms: none.
 
std::map< std::string, std::vector< std::string > > param_groups
 [strategy.groups] and [strategy.overrides]: parameters per instrument, set at the start (strategies/param_overrides.hpp).
 
std::map< std::string, ParamMap > param_overrides
 
int ab_arm = -1
 [ab] assignment = "branch": the arm this run is (an index into ab.arms); fastmm-backtest runs each one in turn.
 
Duration reorder_window = milliseconds(1000)
 Recorded data reaches the simulated venue in venue-time order (sim/venue_order.hpp), assuming no event was received more than this after its venue time; zero keeps the recorded order.
 

Member Function Documentation

◆ publishes_params()

bool fastmm::bt::BacktestConfig::publishes_params ( ) const
inlinenoexcept

The run publishes parameter updates of its own: [ab] or [strategy.overrides] (BacktestSession::enable_ab).

◆ from_config()

static BacktestConfig fastmm::bt::BacktestConfig::from_config ( const Config &  cfg)
static

Throws ConfigError on invalid values.

◆ single_instrument()

static BacktestConfig fastmm::bt::BacktestConfig::single_instrument ( std::string_view  symbol,
Price  tick,
Qty  lot 
)
static

One instrument (venue 0) with the given tick/lot; generator tick/lot follow (examples).

◆ fx_plan()

FxPlan fastmm::bt::BacktestConfig::fx_plan ( const InstrumentTable &  table)

The FX plan for table under accounting (throws ConfigError when a limit reads the totals and the table is not covered; otherwise a warning goes to warnings and nothing converts).

◆ underlying_plan()

UnderlyingPlan fastmm::bt::BacktestConfig::underlying_plan ( const InstrumentTable &  table) const

The [risk.underlying] plan for table (throws ConfigError when the spec does not fit it).

◆ set_market_bps()

void fastmm::bt::BacktestConfig::set_market_bps ( double  spread_bps,
double  mid_step_bps,
double  depth_bps 
)

The synthetic market in basis points of generator.start_mid, turned into ticks of generator.tick: the spread from touch to touch (base_spread_ticks, half of it a side), the size of a latent mid step (mid_step_ticks) and the mean distance of a new limit order behind the touch (depth_ticks).

Each comes to at least one tick. from_config() applies the [sim] defaults below unless the tick keys are given; single_instrument() keeps the one-tick market of MarketGeneratorParams.

◆ set_setting()

bool fastmm::bt::BacktestConfig::set_setting ( std::string_view  key,
std::string_view  value 
)

Sets one of kSweepSettings from its decimal value: latency_fixed_us and latency_jitter_us the order and ack paths of the venues without a [backtest.venues.

<name>] entry, latency_md_us and latency_md_jitter_us their market data, p_drop the share of orders lost, queue_conservatism the queue model's, maker_fee_bps and taker_fee_bps one schedule for every instrument. Returns false for any other key; throws std::invalid_argument for a value out of range.

◆ set_param()

void fastmm::bt::BacktestConfig::set_param ( const std::string &  key,
const std::string &  value 
)
inline

"key=value" strategy parameter override (CLI --param).

◆ set_seed()

void fastmm::bt::BacktestConfig::set_seed ( std::uint64_t  s)
inlinenoexcept

Seeds the synthetic market and the latency model.

Member Data Documentation

◆ engine

EngineConfig fastmm::bt::BacktestConfig::engine

◆ instruments

InstrumentTable fastmm::bt::BacktestConfig::instruments

◆ strategy

std::string fastmm::bt::BacktestConfig::strategy

registry name (apps / Python); ignored by run_backtest<S>()

◆ params

ParamMap fastmm::bt::BacktestConfig::params

◆ transport

sim::SimTransportConfig fastmm::bt::BacktestConfig::transport

◆ generator

sim::MarketGeneratorParams fastmm::bt::BacktestConfig::generator

◆ seed

std::uint64_t fastmm::bt::BacktestConfig::seed = 1

synthetic market + latency model (engine.rng_seed is separate)

◆ start

Timestamp fastmm::bt::BacktestConfig::start {seconds(1'700'000'000).ns}

◆ duration

Duration fastmm::bt::BacktestConfig::duration = seconds(60)

synthetic horizon

◆ equity_bar

Duration fastmm::bt::BacktestConfig::equity_bar = seconds(1)

◆ initial_capital

double fastmm::bt::BacktestConfig::initial_capital = 0.0

reporting only (drawdown %)

◆ accounting

AccountingSpec fastmm::bt::BacktestConfig::accounting

[accounting] and the venue names its sources name (Config::venues order).

from_config() builds engine.fx from them for instruments; replay builds it again for the journal's table.

◆ venue_names

std::vector<std::string> fastmm::bt::BacktestConfig::venue_names

◆ underlying

UnderlyingSpec fastmm::bt::BacktestConfig::underlying

[risk.underlying]: from_config() builds engine.underlying from it for instruments; replay builds it again for the journal's table.

◆ warnings

std::vector<std::string> fastmm::bt::BacktestConfig::warnings

from_config: Config::warnings plus unknown [backtest] keys, each naming the key and its line.

◆ generator_seed_levels

int fastmm::bt::BacktestConfig::generator_seed_levels = 20

◆ source

std::string fastmm::bt::BacktestConfig::source

"synthetic" | "journal" | "csv" | "" (caller supplies the source)

◆ path

std::string fastmm::bt::BacktestConfig::path

◆ output_dir

std::string fastmm::bt::BacktestConfig::output_dir

◆ journal_out

std::string fastmm::bt::BacktestConfig::journal_out

record the run to this .fmj (empty = no journal)

◆ record_ring

MsgRing* fastmm::bt::BacktestConfig::record_ring = nullptr

Where the engine puts its records (core/record_stream.hpp), as fastmm-live hands them to the store: the caller's ring, drained by the caller, large enough for the run (a full ring drops records).

Null: none.

◆ config_toml

std::string fastmm::bt::BacktestConfig::config_toml

Effective configuration embedded in journal_out (Config::effective_toml(); from_config() sets it, hand-built configs leave it empty).

Callers that override fields after from_config() must refresh or clear it.

◆ measure_wall_clock

bool fastmm::bt::BacktestConfig::measure_wall_clock = true

◆ keep_orders

bool fastmm::bt::BacktestConfig::keep_orders = true

The result keeps a row for every order sent (BacktestResult::orders).

A sweep's points do not: their metrics count the orders as they go (OrderStats), and the outbound hash covers them.

◆ markout_horizons

std::vector<Duration> fastmm::bt::BacktestConfig::markout_horizons = {seconds(1), seconds(10), seconds(60)}

Post-fill markout horizons in simulated time; empty turns markouts off.

The run stops the simulated clock at every fill time + horizon to read the venue mid there, so the shortest horizon also bounds how often the run loop is entered.

◆ balances_from_journal

bool fastmm::bt::BacktestConfig::balances_from_journal = false

Start each venue's account (transport.accounts) from the first balance snapshot the journal source recorded for it; a venue it has none for keeps the configured balances.

◆ treasuries

std::vector<TreasuryConfig> fastmm::bt::BacktestConfig::treasuries

The pool treasuries ([venues.

<primary>.treasury] with enabled): each runs on simulated time against its pool's simulated accounts (sim/sim_treasury.hpp), without a ledger file. Empty: none, and the run is what it was without them.

◆ transfer_latency

Duration fastmm::bt::BacktestConfig::transfer_latency {}

[backtest] transfer_latency_ms: a simulated transfer is carried out this long after it is sent.

◆ transfer_p_fail

double fastmm::bt::BacktestConfig::transfer_p_fail = 0.0

[backtest] transfer_p_fail, transfer_p_unknown, transfer_hang_ms: the simulated venue refuses a transfer, or loses its answer and carries it out transfer_hang later (sim::SimTransferFaults).

◆ transfer_p_unknown

double fastmm::bt::BacktestConfig::transfer_p_unknown = 0.0

◆ transfer_hang

Duration fastmm::bt::BacktestConfig::transfer_hang = milliseconds(90'000)

◆ initial_state

InitialState fastmm::bt::BacktestConfig::initial_state = InitialState::StateFile

The strategy's starting state; Journal also starts the engine's positions where the recorded session had them (sim::SessionStart).

◆ positions

std::vector<StartPosition> fastmm::bt::BacktestConfig::positions

[backtest.positions]: the engine's positions at the start, by instrument. They replace the

journal's (initial_state = "journal") for the instruments listed: a backtest that starts at a part from the middle of a session, whose records do not repeat the positions, starts where the session was.

◆ start_at

Timestamp fastmm::bt::BacktestConfig::start_at {}

[backtest] start_at: the run reads the data from its start (the books and the strategy's view of the market warm up), but trading starts later: with initial_state = "journal" at the last checkpoint of the data journal at or before this time, whose state the strategy restores as a warm standby's take-over does, else at this time.

Until then every venue an order can go to has not reconciled, so the engine refuses orders (NotReconciled); at the start each one reconciles with the start positions. Invalid: trading starts with the data.

◆ latency_from_journal

bool fastmm::bt::BacktestConfig::latency_from_journal = false

[backtest] latency_from_journal: the simulated venues take a message's latency from the data journal's own messages around the same time where that is longer than the model's draw (sim/recorded_latency.hpp); the data source must be a journal.

◆ params_from_journal

bool fastmm::bt::BacktestConfig::params_from_journal = false

The data journal's parameter updates reach the strategy at the times the session received them (sim::RecordedParams), mapped by name and type onto its schema.

◆ params_pinned

std::vector<std::string> fastmm::bt::BacktestConfig::params_pinned

params_from_journal leaves these parameters at the configured values: a counterfactual run keeps the session's other updates ([backtest] params_pinned, comma-separated).

◆ controls_from_journal

bool fastmm::bt::BacktestConfig::controls_from_journal = false

The data journal's operator commands (sim::replayable_control) reach the engine at the times the session received them.

◆ ab

AbSection fastmm::bt::BacktestConfig::ab

[ab]: an A/B test of the strategy's parameters (strategies/ab_test.hpp); no arms: none.

◆ param_groups

std::map<std::string, std::vector<std::string> > fastmm::bt::BacktestConfig::param_groups

[strategy.groups] and [strategy.overrides]: parameters per instrument, set at the start (strategies/param_overrides.hpp).

◆ param_overrides

std::map<std::string, ParamMap> fastmm::bt::BacktestConfig::param_overrides

◆ ab_arm

int fastmm::bt::BacktestConfig::ab_arm = -1

[ab] assignment = "branch": the arm this run is (an index into ab.arms); fastmm-backtest runs each one in turn.

◆ reorder_window

Duration fastmm::bt::BacktestConfig::reorder_window = milliseconds(1000)

Recorded data reaches the simulated venue in venue-time order (sim/venue_order.hpp), assuming no event was received more than this after its venue time; zero keeps the recorded order.