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 >:

Public Member Functions

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.
const std::vector< QueuedOrder< BrokerTag > > & queued () const noexcept
 Returns every outstanding order.
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.
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 87 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 221 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 269 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 129 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 180 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 276 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 207 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 194 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 163 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 263 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 103 of file engine.hpp.

◆ queued()

template<typename BrokerTag>
const std::vector< QueuedOrder< BrokerTag > > & algotradelib::backtest::QueueingExecutor< BrokerTag >::queued ( ) const
inlinenoexcept

Returns every outstanding order.

Returns
The orders, oldest first.

Definition at line 200 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 250 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 235 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 91 of file engine.hpp.


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