|
| const Position & | get (InstrumentId id) const noexcept |
| |
| const Position & | operator[] (InstrumentId id) const noexcept |
| |
| void | on_fill (InstrumentId id, Side side, Price px, Qty qty, Notional fee, const Instrument &inst) noexcept |
| | Applies a fill.
|
| |
| void | correct_fill (InstrumentId id, Side side, Price est_px, Price px, Qty qty, Notional fee, const Instrument &inst) noexcept |
| | A fill booked from a venue's cumulative quantity, at the order's own price and with no fee, turned out to be an execution at px costing fee.
|
| |
| void | on_funding (InstrumentId id, Notional amount) noexcept |
| | A funding payment on the instrument's position, in its settlement currency (negative paid, positive received).
|
| |
| Notional | funding (InstrumentId id) const noexcept |
| | Funding booked on one instrument, in its settlement currency (part of its realized PnL).
|
| |
| void | mark (InstrumentId id, Price mid, const Instrument &inst) noexcept |
| | Mark-to-market the open position, in the instrument's settlement currency.
|
| |
| void | set (InstrumentId id, Qty qty, Price avg_px, const Instrument &inst) noexcept |
| | Reconciliation: overwrite qty/avg with the venue's view.
|
| |
| void | reset (InstrumentId id) noexcept |
| |
| void | set_accounting (const FxPlan &plan) noexcept |
| | Accounting across settlement currencies.
|
| |
| void | set_rate (std::size_t c, FxRate r) noexcept |
| | The rate of currency c (an index of the plan): the totals in it are converted again.
|
| |
| bool | converting () const noexcept |
| |
| std::size_t | currency_count () const noexcept |
| |
| FxRate | rate (std::size_t c) const noexcept |
| |
| const Totals & | native (std::size_t c) const noexcept |
| |
| Notional | gross_exposure () const noexcept |
| | Totals over every instrument, kept up to date by the updates above (the engine checks net_pnl() on every market-data event; summing kMaxInstruments positions there cost more than the rest of the event).
|
| |
| Notional | net_exposure () const noexcept |
| |
| Notional | total_realized () const noexcept |
| |
| Notional | total_unrealized () const noexcept |
| |
| Notional | total_fees () const noexcept |
| |
| Notional | total_funding () const noexcept |
| | Funding over every instrument; part of total_realized().
|
| |
| Notional | native_funding (std::size_t c) const noexcept |
| | Funding of one currency, in that currency (converting() only).
|
| |
| Notional | net_pnl () const noexcept |
| |
| Portfolio | portfolio () const noexcept |
| |
Applies a fill.
PnL is scaled by the instrument's contract multiplier and, for an inverse (coin-margined) contract, computed in the base coin: qty * multiplier * (1/avg - 1/px). The average entry price of an inverse position is the size-weighted harmonic mean, which is what makes that exact.
Opening / adding: a new average over the old position and this fill.
Reducing / flipping: realise on the closed part in the position's direction.
< flipped through zero: the remainder opens at px
A fill booked from a venue's cumulative quantity, at the order's own price and with no fee, turned out to be an execution at px costing fee.
Its quantity is already in the position, so on_fill() would count it twice; what was never booked is what it cost. Paying px instead of est_px for qty is worth qty * (px - est_px), given up on a buy and received on a sell, and that difference is exactly the error the estimate left in this position's PnL. The average entry price keeps the estimate: moving it would need the position the fill was booked into, which is history, and the error it carries is the one this correction has already taken out.
Reconciliation: overwrite qty/avg with the venue's view.
Realized PnL and fees are history and are kept; the unrealized PnL of the new position is remeasured at the last mark, so the totals the max-loss budget reads stay consistent with the positions. A record without an average price (zero: the venue gave none, or none that could be read) keeps the tracked one when the position stays on the same side, else takes the last mark: valued at an average of 0, a short of 0.0014 BTC is a loss of its whole notional, which trips max_loss.
| void fastmm::PositionTracker::set_accounting |
( |
const FxPlan & |
plan | ) |
|
|
inlinenoexcept |
Accounting across settlement currencies.
With a plan of two or more currencies the tracker also keeps the totals per currency and converts them at the rate last set for each (set_rate), and the totals below are in the reporting currency. A currency whose rate was never set counts as zero. Without one (the default) nothing is converted and every Notional is added as it is.
What is booked already (a tracker configured after fills) moves into its currencies.