algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::strategy::ProbeContextT< CapsType > Class Template Reference

A context for testing a strategy without a runner: it records what the strategy asks for. More...

#include <algotradelib/src/strategy/concept.hpp>

Inheritance diagram for algotradelib::strategy::ProbeContextT< CapsType >:
Collaboration diagram for algotradelib::strategy::ProbeContextT< CapsType >:

Classes

class  Log
 A log that keeps each line in memory for a test to read. More...

Public Types

using Broker = ProbeBroker
 The broker tag; see ProbeBroker.
using caps = CapsType
 The broker capabilities the strategy sees.

Public Member Functions

 ProbeContextT ()=default
 Constructs an empty probe.
 ProbeContextT (const ProbeContextT &)=delete
 Deleted: like a runner's context, a probe cannot be copied.
ProbeContextT & operator= (const ProbeContextT &)=delete
 Deleted: a probe cannot be copied.
 ProbeContextT (ProbeContextT &&)=default
 Move constructor: takes the other probe's state.
ProbeContextT & operator= (ProbeContextT &&)=default
 Move assignment: takes the other probe's state.
std::chrono::system_clock::time_point now () const noexcept
 Returns the current instant.
MarketPhase phase () const noexcept
 Returns the market phase.
const TradingCalendar & calendar () const noexcept
 Returns the trading calendar.
const Portfolio< ProbeBroker > & portfolio () const noexcept
 Returns the portfolio.
std::optional< Instrument > instrument (const InstrumentId &id) const
 Looks up an instrument's reference data in instruments_.
void submit (OrderIntent intent)
 Records an order intent.
void submit (TargetPosition target)
 Records a target position.
void cancel (const OrderRef< ProbeBroker > &ref)
 Records a cancellation.
Log & log () noexcept
 Returns the log.
const std::vector< OrderIntent > & submitted () const noexcept
 Returns the order intents submitted.
const std::vector< TargetPosition > & targets () const noexcept
 Returns the target positions submitted.
const std::vector< CancelIntent< ProbeBroker > > & canceled () const noexcept
 Returns the cancellations requested.

Public Attributes

std::chrono::system_clock::time_point now_ {}
 The instant now() returns.
MarketPhase phase_ {MarketPhase::OPEN}
 The phase phase() returns.
TradingCalendar calendar_
 The calendar calendar() returns.
Portfolio< ProbeBroker > portfolio_
 The portfolio portfolio() returns.
std::vector< Instrument > instruments_
 The reference data instrument() searches.

Detailed Description

template<typename CapsType>
class algotradelib::strategy::ProbeContextT< CapsType >

A context for testing a strategy without a runner: it records what the strategy asks for.

Set the public fields (now_, phase_, calendar_, portfolio_, instruments_), call a handler, then read submitted(), targets(), canceled() and log().lines(). ATL_ASSERT_STRATEGY(S, MinimalContext) compiles a strategy's handlers against it.

It has no series accessors (bars, frame, panel), so it needs no linear algebra backend; a strategy that reads series is checked by the runner it is bound to.

Template Parameters
CapsTypeThe broker capabilities the strategy sees as Ctx::caps; see NoCaps and AllCaps.

Definition at line 509 of file concept.hpp.

Member Typedef Documentation

◆ Broker

template<typename CapsType>
using algotradelib::strategy::ProbeContextT< CapsType >::Broker = ProbeBroker

The broker tag; see ProbeBroker.

Definition at line 512 of file concept.hpp.

◆ caps

template<typename CapsType>
using algotradelib::strategy::ProbeContextT< CapsType >::caps = CapsType

The broker capabilities the strategy sees.

Definition at line 514 of file concept.hpp.

Member Function Documentation

◆ calendar()

template<typename CapsType>
const TradingCalendar & algotradelib::strategy::ProbeContextT< CapsType >::calendar ( ) const
inlinenoexcept

Returns the trading calendar.

Returns
calendar_.

Definition at line 567 of file concept.hpp.

◆ cancel()

template<typename CapsType>
void algotradelib::strategy::ProbeContextT< CapsType >::cancel ( const OrderRef< ProbeBroker > & ref)
inline

Records a cancellation.

Parameters
refThe order to cancel, appended to canceled().

Definition at line 606 of file concept.hpp.

◆ canceled()

template<typename CapsType>
const std::vector< CancelIntent< ProbeBroker > > & algotradelib::strategy::ProbeContextT< CapsType >::canceled ( ) const
inlinenoexcept

Returns the cancellations requested.

Returns
The cancellations, in order.

Definition at line 630 of file concept.hpp.

◆ instrument()

template<typename CapsType>
std::optional< Instrument > algotradelib::strategy::ProbeContextT< CapsType >::instrument ( const InstrumentId & id) const
inline

Looks up an instrument's reference data in instruments_.

Parameters
idThe instrument.
Returns
Its reference data, or std::nullopt if the test provided none.

Definition at line 581 of file concept.hpp.

◆ log()

template<typename CapsType>
Log & algotradelib::strategy::ProbeContextT< CapsType >::log ( )
inlinenoexcept

Returns the log.

Returns
The recording log.

Definition at line 614 of file concept.hpp.

◆ now()

template<typename CapsType>
std::chrono::system_clock::time_point algotradelib::strategy::ProbeContextT< CapsType >::now ( ) const
inlinenoexcept

Returns the current instant.

Returns
now_.

Definition at line 555 of file concept.hpp.

◆ operator=() [1/2]

template<typename CapsType>
ProbeContextT & algotradelib::strategy::ProbeContextT< CapsType >::operator= ( const ProbeContextT< CapsType > & )
delete

Deleted: a probe cannot be copied.

Returns
Not callable.

◆ operator=() [2/2]

template<typename CapsType>
ProbeContextT & algotradelib::strategy::ProbeContextT< CapsType >::operator= ( ProbeContextT< CapsType > && )
default

Move assignment: takes the other probe's state.

Returns
*this.

◆ phase()

template<typename CapsType>
MarketPhase algotradelib::strategy::ProbeContextT< CapsType >::phase ( ) const
inlinenoexcept

Returns the market phase.

Returns
phase_.

Definition at line 561 of file concept.hpp.

◆ portfolio()

template<typename CapsType>
const Portfolio< ProbeBroker > & algotradelib::strategy::ProbeContextT< CapsType >::portfolio ( ) const
inlinenoexcept

Returns the portfolio.

Returns
portfolio_.

Definition at line 573 of file concept.hpp.

◆ submit() [1/2]

template<typename CapsType>
void algotradelib::strategy::ProbeContextT< CapsType >::submit ( OrderIntent intent)
inline

Records an order intent.

Parameters
intentThe intent, appended to submitted().

Definition at line 594 of file concept.hpp.

◆ submit() [2/2]

template<typename CapsType>
void algotradelib::strategy::ProbeContextT< CapsType >::submit ( TargetPosition target)
inline

Records a target position.

Parameters
targetThe target, appended to targets().

Definition at line 600 of file concept.hpp.

◆ submitted()

template<typename CapsType>
const std::vector< OrderIntent > & algotradelib::strategy::ProbeContextT< CapsType >::submitted ( ) const
inlinenoexcept

Returns the order intents submitted.

Returns
The intents, in order.

Definition at line 620 of file concept.hpp.

◆ targets()

template<typename CapsType>
const std::vector< TargetPosition > & algotradelib::strategy::ProbeContextT< CapsType >::targets ( ) const
inlinenoexcept

Returns the target positions submitted.

Returns
The targets, in order.

Definition at line 625 of file concept.hpp.

Member Data Documentation

◆ calendar_

template<typename CapsType>
TradingCalendar algotradelib::strategy::ProbeContextT< CapsType >::calendar_

The calendar calendar() returns.

Definition at line 637 of file concept.hpp.

◆ instruments_

template<typename CapsType>
std::vector<Instrument> algotradelib::strategy::ProbeContextT< CapsType >::instruments_

The reference data instrument() searches.

Definition at line 641 of file concept.hpp.

◆ now_

template<typename CapsType>
std::chrono::system_clock::time_point algotradelib::strategy::ProbeContextT< CapsType >::now_ {}

The instant now() returns.

Definition at line 633 of file concept.hpp.

◆ phase_

template<typename CapsType>
MarketPhase algotradelib::strategy::ProbeContextT< CapsType >::phase_ {MarketPhase::OPEN}

The phase phase() returns.

Definition at line 635 of file concept.hpp.

◆ portfolio_

template<typename CapsType>
Portfolio<ProbeBroker> algotradelib::strategy::ProbeContextT< CapsType >::portfolio_

The portfolio portfolio() returns.

Definition at line 639 of file concept.hpp.


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