algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::runner::RunLedger Class Reference

One run's cash and its own shares, for strategy::RiskLimits::run_budget_. More...

#include <algotradelib/src/runner/run_ledger.hpp>

Public Member Functions

 RunLedger (Money opening)
 Opens a new run.
const std::string & id () const noexcept
 Returns the run's id.
const Money & cash () const noexcept
 Returns the run's cash.
const Currency & currency () const noexcept
 Returns the run's currency.
Decimal64 holding (const InstrumentId &instrument) const
 Returns the run's own shares of an instrument.
bool book (const InstrumentId &instrument, OrderSide side, const Decimal64 &filled, const Money &amount, const Decimal64 &fee)
 Books one fill.

Friends

template<typename, typename, typename, typename>
class Runner

Detailed Description

One run's cash and its own shares, for strategy::RiskLimits::run_budget_.

A new run opens with the budget as its cash and no shares. Each fill moves both: a buy spends its amount and its fee and adds its quantity, a sell returns its amount less its fee and takes its quantity away. The cash may go below zero only by a fee booked above what was reserved; the shares never do.

runner::Runner keeps one when a budget is set; read it through Runner::run_cash and Runner::run_holding.

Definition at line 128 of file run_ledger.hpp.

Constructor & Destructor Documentation

◆ RunLedger()

algotradelib::runner::RunLedger::RunLedger ( Money opening)
inlineexplicit

Opens a new run.

Parameters
openingThe run's starting cash, which names its currency.

Definition at line 134 of file run_ledger.hpp.

Member Function Documentation

◆ book()

bool algotradelib::runner::RunLedger::book ( const InstrumentId & instrument,
OrderSide side,
const Decimal64 & filled,
const Money & amount,
const Decimal64 & fee )
inline

Books one fill.

Parameters
instrumentThe instrument.
sideThe fill's side.
filledThe quantity filled.
amountWhat the fill traded for, quantity times price.
feeIts commission and taxes together.
Returns
true if booked; false, with nothing changed, if amount is in another currency than the run's, a figure is negative, a sell is more than the run's shares, or the arithmetic does not fit.

Definition at line 181 of file run_ledger.hpp.

◆ cash()

const Money & algotradelib::runner::RunLedger::cash ( ) const
inlinenoexcept

Returns the run's cash.

Returns
The cash, in the run's currency.

Definition at line 148 of file run_ledger.hpp.

◆ currency()

const Currency & algotradelib::runner::RunLedger::currency ( ) const
inlinenoexcept

Returns the run's currency.

Returns
The currency every amount the run books must be in.

Definition at line 156 of file run_ledger.hpp.

◆ holding()

Decimal64 algotradelib::runner::RunLedger::holding ( const InstrumentId & instrument) const
inline

Returns the run's own shares of an instrument.

Parameters
instrumentThe instrument.
Returns
The shares; zero for an instrument the run never traded.

Definition at line 165 of file run_ledger.hpp.

◆ id()

const std::string & algotradelib::runner::RunLedger::id ( ) const
inlinenoexcept

Returns the run's id.

Returns
The id of its opening line; empty for a run kept only in memory.

Definition at line 140 of file run_ledger.hpp.

◆ Runner

template<typename, typename, typename, typename>
friend class Runner
friend

Definition at line 201 of file run_ledger.hpp.


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