![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
Positions, cash and realized profit, updated by each execution of a replay. More...
#include <algotradelib/src/backtest/ledger.hpp>
Public Member Functions | |
| ReplayLedger (Decimal64 cash, Currency currency) | |
| Constructs a ledger holding only cash. | |
| std::optional< Decimal64 > | cash_in (const Currency ¤cy) const |
| Returns the cash held in a currency. | |
| std::optional< Decimal64 > | quantity_of (const InstrumentId &instrument) const |
| Returns the quantity held of an instrument. | |
| std::optional< Decimal64 > | average_price_of (const InstrumentId &instrument) const |
| Returns the average price of the position in an instrument. | |
| Decimal64 | realized_in (const Currency ¤cy) const |
| Returns the profit realized by closing positions, in a currency (fees excluded). | |
| const std::vector< HoldingPosition > & | positions () const noexcept |
| Returns every position, including ones that went flat. | |
| const std::vector< Execution > & | executions () const noexcept |
| Returns every execution applied. | |
| bool | apply (const Execution &execution, const Currency ¤cy) |
| Applies one execution to the position, cash and realized profit. | |
| bool | mark (const InstrumentId &instrument, const Decimal64 &price) |
| Marks positions in an instrument to a price, updating their market value. | |
| template<typename BrokerTag> | |
| strategy::Portfolio< BrokerTag > | snapshot (std::chrono::system_clock::time_point as_of) const |
| Returns the portfolio a strategy sees. | |
| std::optional< Decimal64 > | equity_in (const Currency ¤cy) const |
| Returns total equity in a currency: cash plus positions at their last marks. | |
Positions, cash and realized profit, updated by each execution of a replay.
Cash and profit are kept per currency and never converted.
Definition at line 61 of file ledger.hpp.
Constructs a ledger holding only cash.
| cash | The starting cash. |
| currency | Its currency. |
Definition at line 68 of file ledger.hpp.
|
inline |
Applies one execution to the position, cash and realized profit.
A trade through flat (selling 150 from a long of 100) closes the old position, realizing its profit against the old average, and opens the remainder at the new price. Commission, institution fee and tax are deducted from cash.
| execution | The execution. |
| currency | The instrument's currency. |
Definition at line 157 of file ledger.hpp.
|
inline |
Returns the average price of the position in an instrument.
| instrument | The instrument. |
Definition at line 105 of file ledger.hpp.
|
inline |
Returns the cash held in a currency.
| currency | The currency. |
Definition at line 77 of file ledger.hpp.
Referenced by apply(), and equity_in().
|
inline |
Returns total equity in a currency: cash plus positions at their last marks.
Positions in other currencies are left out, not converted.
| currency | The currency. |
Definition at line 367 of file ledger.hpp.
|
inlinenoexcept |
Returns every execution applied.
Definition at line 142 of file ledger.hpp.
|
inline |
Marks positions in an instrument to a price, updating their market value.
| instrument | The instrument. |
| price | The new mark. |
Definition at line 298 of file ledger.hpp.
|
inlinenoexcept |
Returns every position, including ones that went flat.
Of the money fields only market_value_ (quantity times last mark) is filled; purchase_value_, unrealized_profit_loss_ and unrealized_return_ stay at their defaults.
Definition at line 136 of file ledger.hpp.
|
inline |
Returns the quantity held of an instrument.
| instrument | The instrument. |
Definition at line 91 of file ledger.hpp.
|
inline |
Returns the profit realized by closing positions, in a currency (fees excluded).
| currency | The currency. |
Definition at line 119 of file ledger.hpp.
Referenced by apply().
|
inline |
Returns the portfolio a strategy sees.
The model a replay presents: every held share is sellable (basis whole holding, deduct resting sells, unverified), buying power is this ledger's cash (no settlement is modelled), and cash_ is filled. Working orders are left empty; Backtester fills them from its queue.
| BrokerTag | The order-reference tag of the portfolio. |
| as_of | The snapshot time, for as_of_ and the buying-power stamps. |
Definition at line 332 of file ledger.hpp.