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

#include <fastmm/backtest/backtest_runner.hpp>

Public Member Functions

 BacktestSession (const BacktestConfig &cfg, MdSource *source, const ParamSchema *schema=nullptr, std::string_view strategy_meta={})
 schema: the strategy's parameters, recorded in cfg.journal_out (may be null).
 
 ~BacktestSession ()
 
 BacktestSession (const BacktestSession &)=delete
 
BacktestSession & operator= (const BacktestSession &)=delete
 
RunnerDeps & deps () noexcept
 
sim::SimBackend & backend () noexcept
 
void set_param_schedule (sim::ParamSchedule *schedule) noexcept
 Parameter updates delivered at simulated times during run() (not owned; may be null).
 
void enable_ab (StrategyEntry::PublisherFactory publisher)
 [ab] and [strategy.overrides]: builds the run's publisher with publisher (StrategyEntry::publisher), so the overrides reach the engine before the first event and the arms' updates at their times during run().
 
void enable_ab (const std::function< std::unique_ptr< ParamPublisher >(ParamSink)> &make_publisher)
 enable_ab() with the publisher make_publisher builds on the sink it is given: a strategy whose parameters are not a FASTMM_PARAMS struct (a Python strategy's HotParamTable).
 
void set_slow_hooks (const sim::SlowHooks &hooks) noexcept
 Code run at simulated times during run() (sim::SimDriver::set_slow_hooks).
 
BacktestResult run (const sim::EngineHooks &hooks, IEngineRunner *runner, std::string_view strategy_name)
 Runs to the end of the data / horizon.
 
void begin (const sim::EngineHooks &hooks, IEngineRunner *runner, const Timestamp *world)
 run() in steps, for a multiverse (multiverse.hpp), whose runs share the recorded events and the market data forwarded from them: begin(hooks, runner, &next) leaves the source to the caller, which keeps next at the venue time of the next recorded event (Timestamp::max() when there is none) and for each event its runs share calls advance_before(the event's key) (false: this run is over), then hands it the event: world_event() (or its halves) for a recorded event after the shared SimWorld took its half, shared_market_data() for market data at its arrival.
 
bool advance_before (sim::SimKey k)
 
void world_event (const EventHeader &md) noexcept
 
void world_venue_event (const EventHeader &md) noexcept
 
void world_feed_event (const EventHeader &md) noexcept
 
void shared_market_data (const EventHeader &md) noexcept
 
sim::SimKey next_key ()
 The key of this run's own next event or stop (equity bar, markout); never() once it is over.
 
sim::SimKey step_key ()
 After shared_market_data(): the earliest event the engine's step added (SimDriver::step_key).
 
void reach (Timestamp t) noexcept
 The clock at the last event the run shared (which it may not have had to take).
 
void credit_market_data (std::uint64_t n) noexcept
 Market data the multiverse did not hand the run, which its engine did not need (SimDriver::credit_market_data).
 
bool stopped () const noexcept
 The engine asked to stop: the run takes no further event.
 
BacktestResult end (std::string_view strategy_name)
 
void take_record (const EventHeader &record)
 A run over a journal that is being followed (backtest/follow_source.hpp): a record of the session it did not have at its start, before the run has reached the record's time.
 
const FillRows & fill_rows () const noexcept
 What the run has so far: the fills up to the event it last took and the equity bars it has passed.
 
const EquityRows & equity_rows () const noexcept
 
std::size_t forget_rows (std::size_t fills, std::size_t bars)
 Returns how many fills it forgot.
 
std::uint64_t orders_sent () const noexcept
 The order messages the run has sent.
 

Constructor & Destructor Documentation

◆ BacktestSession() [1/2]

fastmm::bt::BacktestSession::BacktestSession ( const BacktestConfig &  cfg,
MdSource *  source,
const ParamSchema *  schema = nullptr,
std::string_view  strategy_meta = {} 
)

schema: the strategy's parameters, recorded in cfg.journal_out (may be null).

strategy_meta: key=value lines recorded in cfg.journal_out (Python strategies).

◆ ~BacktestSession()

fastmm::bt::BacktestSession::~BacktestSession ( )

◆ BacktestSession() [2/2]

fastmm::bt::BacktestSession::BacktestSession ( const BacktestSession &  )
delete

Member Function Documentation

◆ operator=()

BacktestSession & fastmm::bt::BacktestSession::operator= ( const BacktestSession &  )
delete

◆ deps()

RunnerDeps & fastmm::bt::BacktestSession::deps ( )
inlinenoexcept

◆ backend()

sim::SimBackend & fastmm::bt::BacktestSession::backend ( )
inlinenoexcept

◆ set_param_schedule()

void fastmm::bt::BacktestSession::set_param_schedule ( sim::ParamSchedule *  schedule)
inlinenoexcept

Parameter updates delivered at simulated times during run() (not owned; may be null).

◆ enable_ab() [1/2]

void fastmm::bt::BacktestSession::enable_ab ( StrategyEntry::PublisherFactory  publisher)

[ab] and [strategy.overrides]: builds the run's publisher with publisher (StrategyEntry::publisher), so the overrides reach the engine before the first event and the arms' updates at their times during run().

A configuration with either needs it (BacktestConfig::publishes_params). Throws std::invalid_argument when the arms or the overrides do not fit the strategy (ab_test.hpp, param_overrides.hpp).

◆ enable_ab() [2/2]

void fastmm::bt::BacktestSession::enable_ab ( const std::function< std::unique_ptr< ParamPublisher >(ParamSink)> &  make_publisher)

enable_ab() with the publisher make_publisher builds on the sink it is given: a strategy whose parameters are not a FASTMM_PARAMS struct (a Python strategy's HotParamTable).

◆ set_slow_hooks()

void fastmm::bt::BacktestSession::set_slow_hooks ( const sim::SlowHooks &  hooks)
inlinenoexcept

Code run at simulated times during run() (sim::SimDriver::set_slow_hooks).

◆ run()

BacktestResult fastmm::bt::BacktestSession::run ( const sim::EngineHooks &  hooks,
IEngineRunner *  runner,
std::string_view  strategy_name 
)

Runs to the end of the data / horizon.

runner (may be null) supplies engine stats and, with [strategy] state_file, the strategy's state to write at the end.

◆ begin()

void fastmm::bt::BacktestSession::begin ( const sim::EngineHooks &  hooks,
IEngineRunner *  runner,
const Timestamp *  world 
)

run() in steps, for a multiverse (multiverse.hpp), whose runs share the recorded events and the market data forwarded from them: begin(hooks, runner, &next) leaves the source to the caller, which keeps next at the venue time of the next recorded event (Timestamp::max() when there is none) and for each event its runs share calls advance_before(the event's key) (false: this run is over), then hands it the event: world_event() (or its halves) for a recorded event after the shared SimWorld took its half, shared_market_data() for market data at its arrival.

end() runs what is left and returns what run() would have. begin(.., nullptr) + end() is run().

◆ advance_before()

bool fastmm::bt::BacktestSession::advance_before ( sim::SimKey  k)

◆ world_event()

void fastmm::bt::BacktestSession::world_event ( const EventHeader &  md)
noexcept

◆ world_venue_event()

void fastmm::bt::BacktestSession::world_venue_event ( const EventHeader &  md)
noexcept

◆ world_feed_event()

void fastmm::bt::BacktestSession::world_feed_event ( const EventHeader &  md)
noexcept

◆ shared_market_data()

void fastmm::bt::BacktestSession::shared_market_data ( const EventHeader &  md)
noexcept

◆ next_key()

sim::SimKey fastmm::bt::BacktestSession::next_key ( )

The key of this run's own next event or stop (equity bar, markout); never() once it is over.

◆ step_key()

sim::SimKey fastmm::bt::BacktestSession::step_key ( )

After shared_market_data(): the earliest event the engine's step added (SimDriver::step_key).

◆ reach()

void fastmm::bt::BacktestSession::reach ( Timestamp  t)
noexcept

The clock at the last event the run shared (which it may not have had to take).

◆ credit_market_data()

void fastmm::bt::BacktestSession::credit_market_data ( std::uint64_t  n)
noexcept

Market data the multiverse did not hand the run, which its engine did not need (SimDriver::credit_market_data).

◆ stopped()

bool fastmm::bt::BacktestSession::stopped ( ) const
noexcept

The engine asked to stop: the run takes no further event.

◆ end()

BacktestResult fastmm::bt::BacktestSession::end ( std::string_view  strategy_name)

◆ take_record()

void fastmm::bt::BacktestSession::take_record ( const EventHeader &  record)

A run over a journal that is being followed (backtest/follow_source.hpp): a record of the session it did not have at its start, before the run has reached the record's time.

◆ fill_rows()

const FillRows & fastmm::bt::BacktestSession::fill_rows ( ) const
noexcept

What the run has so far: the fills up to the event it last took and the equity bars it has passed.

A caller that keeps what it needs of them can forget_rows() the first fills and bars: a run over weeks of data then holds about one bar's worth. end()'s result covers what was not forgotten. Fills whose markouts are still to come stay.

◆ equity_rows()

const EquityRows & fastmm::bt::BacktestSession::equity_rows ( ) const
noexcept

◆ forget_rows()

std::size_t fastmm::bt::BacktestSession::forget_rows ( std::size_t  fills,
std::size_t  bars 
)

Returns how many fills it forgot.

◆ orders_sent()

std::uint64_t fastmm::bt::BacktestSession::orders_sent ( ) const
noexcept

The order messages the run has sent.