algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::backtest::QueueingExecutor< BrokerTag > Class Template Reference

The replay's executor: accepts orders and holds them until they fill or are withdrawn. More...

#include <algotradelib/src/backtest/engine.hpp>

Inheritance diagram for algotradelib::backtest::QueueingExecutor< BrokerTag >:

Classes

class  Queue
 Every outstanding order, oldest first: a view over the queue, valid until the queue changes. More...

Public Member Functions

 QueueingExecutor ()=default
 An executor with nothing queued.
 QueueingExecutor (const QueueingExecutor &other)=default
 Copies an executor and its queue.
 QueueingExecutor (QueueingExecutor &&other) noexcept(std::is_nothrow_move_constructible< ByInstrument >::value)
 Moves an executor; the source is left with nothing queued.
QueueingExecutor & operator= (QueueingExecutor &&other) noexcept
 Replaces this executor with a move of another, which is left with nothing queued.
QueueingExecutor & operator= (const QueueingExecutor &other)
 Replaces this executor with a copy of another, entirely or not at all.
runner::SendOutcome place (const strategy::PlannedOrder &order)
 Accepts and queues an order, issuing it a reference.
runner::SendOutcome cancel (const WorkingOrder< BrokerTag > &working)
 Withdraws the order a working row names, matched by reference.
std::optional< OrderRef< BrokerTag > > last_ref () const
 Returns the reference issued to the most recently accepted order.
Queue queued () const noexcept
 Returns every outstanding order, oldest first.
template<typename Each>
void for_each_queued_in (const InstrumentId &instrument, Each &&each) const
 Calls each with every outstanding order in one instrument, oldest first.
const QueuedOrder< BrokerTag > * find (const OrderRef< BrokerTag > &ref) const
 Finds an outstanding order.
void assign_session (const OrderRef< BrokerTag > &ref, Date session)
 Records the session date of a queued order; see QueuedOrder::session_.
bool withdraw (const OrderRef< BrokerTag > &ref)
 Removes an order from the queue.
bool release (const OrderRef< BrokerTag > &ref)
 Marks a queued stop-limit order as released.
void open_bar () noexcept
 Starts the next bar; orders accepted from now on cannot fill against it.
std::uint64_t bar () const noexcept
 Returns the bar being replayed.
std::uint64_t changes () const noexcept
 Returns how many times the queue gained or lost an order (place, cancel, withdraw).
template<typename PriceOf>
void stamp_decision_prices (PriceOf &&price_of)
 Stamps the orders accepted since the last call with their instrument's price now, and when it was observed.
void deciding_at (std::chrono::system_clock::time_point at, bool exact=true)
 Sets the decision instant stamped on orders accepted from now on.

Static Public Member Functions

static bool can_model (const strategy::PlannedOrder &order) noexcept
 Tests whether a replay can price an order from bars.
static constexpr bool models_time_in_force (TimeInForce condition) noexcept
 Tests whether the replay models a limit or market order's time in force.

Static Public Attributes

static constexpr bool reaches_a_broker = false
 false: a replay reaches no broker.

Detailed Description

template<typename BrokerTag>
class algotradelib::backtest::QueueingExecutor< BrokerTag >

The replay's executor: accepts orders and holds them until they fill or are withdrawn.

queued() is always the complete set of outstanding orders; the engine shows them to the strategy as working orders.

Template Parameters
BrokerTagThe order-reference tag.

Definition at line 103 of file engine.hpp.

Constructor & Destructor Documentation

◆ QueueingExecutor() [1/2]

template<typename BrokerTag>
algotradelib::backtest::QueueingExecutor< BrokerTag >::QueueingExecutor ( const QueueingExecutor< BrokerTag > & other)
default

Copies an executor and its queue.

Parameters
otherThe executor to copy.

◆ QueueingExecutor() [2/2]

template<typename BrokerTag>
algotradelib::backtest::QueueingExecutor< BrokerTag >::QueueingExecutor ( QueueingExecutor< BrokerTag > && other)
inlinenoexcept

Moves an executor; the source is left with nothing queued.

noexcept exactly when the standard library moves an std::unordered_map without throwing (libc++ and libstdc++ do; Microsoft's allocates).

Parameters
otherThe executor to move from.
Exceptions
std::bad_allocIf the map cannot be moved; the source is then unchanged.

Definition at line 127 of file engine.hpp.

Member Function Documentation

◆ assign_session()

template<typename BrokerTag>
void algotradelib::backtest::QueueingExecutor< BrokerTag >::assign_session ( const OrderRef< BrokerTag > & ref,
Date session )
inline

Records the session date of a queued order; see QueuedOrder::session_.

Parameters
refThe order.
sessionThe session's market-local date.

Definition at line 462 of file engine.hpp.

◆ bar()

template<typename BrokerTag>
std::uint64_t algotradelib::backtest::QueueingExecutor< BrokerTag >::bar ( ) const
inlinenoexcept

Returns the bar being replayed.

Returns
The bar number, counting from one.

Definition at line 519 of file engine.hpp.

◆ can_model()

template<typename BrokerTag>
bool algotradelib::backtest::QueueingExecutor< BrokerTag >::can_model ( const strategy::PlannedOrder & order)
inlinestaticnoexcept

Tests whether a replay can price an order from bars.

Only regular-session limit and market orders without a trigger, and DAY stop-limit orders with both a trigger and a limit price. Best-limit, primary-limit, mid-price, conditional-limit and closing-price orders need a book or a session close that bars do not carry.

Parameters
orderThe order.
Returns
true if the replay can model it.

Definition at line 226 of file engine.hpp.

◆ cancel()

template<typename BrokerTag>
runner::SendOutcome algotradelib::backtest::QueueingExecutor< BrokerTag >::cancel ( const WorkingOrder< BrokerTag > & working)
inline

Withdraws the order a working row names, matched by reference.

Parameters
workingThe working row.
Returns
ACCEPTED if it was queued; REJECTED if nothing matches (it filled or was already withdrawn).

Definition at line 276 of file engine.hpp.

◆ changes()

template<typename BrokerTag>
std::uint64_t algotradelib::backtest::QueueingExecutor< BrokerTag >::changes ( ) const
inlinenoexcept

Returns how many times the queue gained or lost an order (place, cancel, withdraw).

Releasing a stop and dating an order's session change neither its working row nor the count.

Returns
The count since construction.

Definition at line 530 of file engine.hpp.

◆ deciding_at()

template<typename BrokerTag>
void algotradelib::backtest::QueueingExecutor< BrokerTag >::deciding_at ( std::chrono::system_clock::time_point at,
bool exact = true )
inline

Sets the decision instant stamped on orders accepted from now on.

Parameters
atThe instant.
exactWhether at is exact or only an upper bound; see QueuedOrder::decision_is_exact_.

Definition at line 554 of file engine.hpp.

◆ find()

template<typename BrokerTag>
const QueuedOrder< BrokerTag > * algotradelib::backtest::QueueingExecutor< BrokerTag >::find ( const OrderRef< BrokerTag > & ref) const
inline

Finds an outstanding order.

Parameters
refThe reference.
Returns
A pointer into the queue (valid until the queue changes), or nullptr.

Definition at line 452 of file engine.hpp.

◆ for_each_queued_in()

template<typename BrokerTag>
template<typename Each>
void algotradelib::backtest::QueueingExecutor< BrokerTag >::for_each_queued_in ( const InstrumentId & instrument,
Each && each ) const
inline

Calls each with every outstanding order in one instrument, oldest first.

Visits only that instrument's orders, however many others are queued. each must not change the queue.

Parameters
instrumentThe instrument.
eachCalled as each(const QueuedOrder&).

Definition at line 437 of file engine.hpp.

◆ last_ref()

template<typename BrokerTag>
std::optional< OrderRef< BrokerTag > > algotradelib::backtest::QueueingExecutor< BrokerTag >::last_ref ( ) const
inline

Returns the reference issued to the most recently accepted order.

Returns
The reference, or std::nullopt before any.

Definition at line 284 of file engine.hpp.

◆ models_time_in_force()

template<typename BrokerTag>
constexpr bool algotradelib::backtest::QueueingExecutor< BrokerTag >::models_time_in_force ( TimeInForce condition)
inlinestaticconstexprnoexcept

Tests whether the replay models a limit or market order's time in force.

A day order rests on later bars until the session ends; every other condition is filled or not on the next bar and not kept after it (NextBarFillModel::rests_unfilled), which is how an UNKNOWN one is replayed too.

Parameters
conditionThe condition.
Returns
true for every condition today.

Definition at line 259 of file engine.hpp.

◆ open_bar()

template<typename BrokerTag>
void algotradelib::backtest::QueueingExecutor< BrokerTag >::open_bar ( )
inlinenoexcept

Starts the next bar; orders accepted from now on cannot fill against it.

Definition at line 511 of file engine.hpp.

◆ operator=() [1/2]

template<typename BrokerTag>
QueueingExecutor & algotradelib::backtest::QueueingExecutor< BrokerTag >::operator= ( const QueueingExecutor< BrokerTag > & other)
inline

Replaces this executor with a copy of another, entirely or not at all.

Parameters
otherThe executor to copy.
Returns
This executor.
Exceptions
std::bad_allocIf the copy cannot be made; this executor is then unchanged.

Definition at line 168 of file engine.hpp.

◆ operator=() [2/2]

template<typename BrokerTag>
QueueingExecutor & algotradelib::backtest::QueueingExecutor< BrokerTag >::operator= ( QueueingExecutor< BrokerTag > && other)
inlinenoexcept

Replaces this executor with a move of another, which is left with nothing queued.

Parameters
otherThe executor to move from.
Returns
This executor.

Definition at line 145 of file engine.hpp.

◆ place()

template<typename BrokerTag>
runner::SendOutcome algotradelib::backtest::QueueingExecutor< BrokerTag >::place ( const strategy::PlannedOrder & order)
inline

Accepts and queues an order, issuing it a reference.

A replay invents no transport failure.

Parameters
orderThe order.
Returns
ACCEPTED, or REFUSED_LOCALLY for an order the replay cannot price from bars (see can_model); a refused order is reported as a BINDING_REFUSED rejection (ReplayResult::rejected_, the pass's Report::rejected_), as a live binding's refusal is; the strategy is not told.

Definition at line 189 of file engine.hpp.

◆ queued()

template<typename BrokerTag>
Queue algotradelib::backtest::QueueingExecutor< BrokerTag >::queued ( ) const
inlinenoexcept

Returns every outstanding order, oldest first.

Returns
A view of the orders; valid until the queue changes.

Definition at line 424 of file engine.hpp.

◆ release()

template<typename BrokerTag>
bool algotradelib::backtest::QueueingExecutor< BrokerTag >::release ( const OrderRef< BrokerTag > & ref)
inline

Marks a queued stop-limit order as released.

Parameters
refThe order.
Returns
true if it was queued.

Definition at line 499 of file engine.hpp.

◆ stamp_decision_prices()

template<typename BrokerTag>
template<typename PriceOf>
void algotradelib::backtest::QueueingExecutor< BrokerTag >::stamp_decision_prices ( PriceOf && price_of)
inline

Stamps the orders accepted since the last call with their instrument's price now, and when it was observed.

Template Parameters
PriceOfA callable from an InstrumentId to a pair of an optional price and an optional instant.
Parameters
price_ofThe price lookup.

Definition at line 540 of file engine.hpp.

◆ withdraw()

template<typename BrokerTag>
bool algotradelib::backtest::QueueingExecutor< BrokerTag >::withdraw ( const OrderRef< BrokerTag > & ref)
inline

Removes an order from the queue.

Parameters
refThe order.
Returns
true if it was queued.

Definition at line 473 of file engine.hpp.

Member Data Documentation

◆ reaches_a_broker

template<typename BrokerTag>
bool algotradelib::backtest::QueueingExecutor< BrokerTag >::reaches_a_broker = false
staticconstexpr

false: a replay reaches no broker.

Definition at line 177 of file engine.hpp.


The documentation for this class was generated from the following file: