> For the complete documentation index, see [llms.txt](https://quantinfra.gitbook.io/quantinfra-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantinfra.gitbook.io/quantinfra-docs/positions-pnl-and-yield-tracking.md).

# Positions, PnL and yield tracking

Every trade booked to an account alters a position in this contract.

## Types of position accounting

Accounts used for strategies (Virtual Accounts or Strategy Subaccounts) may choose the type of position accounting:

* Netted (default) — there may be only one position in a given contract on the account
* Hedged — there may be different positions in one contract

When using the hedged mode, every order must specify the Position Effect — whether its execution opens a new position or closes an existing one. The field named StrategyPositionId links orders, trades, and positions.

Broker accounts always use the Netted accounting.

Executable subaccounts (ESAs) have the same accounting as the strategy they are subscribed to.

## Position

| Property                                                                                                                                             | Description                                                                                                                                    |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| OpenTradeId                                                                                                                                          | ID of the last trade that affected the position. See explanation about position history below.                                                 |
| AccountId                                                                                                                                            |                                                                                                                                                |
| StrategyPositionId                                                                                                                                   | For accounts that use Hedged accounting, an arbitrary string identifying the position.                                                         |
| ContractId                                                                                                                                           |                                                                                                                                                |
| Volume                                                                                                                                               | Unsigned volume in contract units                                                                                                              |
| SignedVolume                                                                                                                                         |                                                                                                                                                |
| Side                                                                                                                                                 |                                                                                                                                                |
| OpenPrice                                                                                                                                            | TotalOpenPayments / Volume                                                                                                                     |
| TotalOpenPayments                                                                                                                                    | Sum of the payments of all trades that increased the position                                                                                  |
| OpenDt                                                                                                                                               | Initial open timestamp                                                                                                                         |
| HistoryOpenDt                                                                                                                                        | Timestamp of the last change (due to the trade or end of day)                                                                                  |
| TotalSettlPayments                                                                                                                                   | Value of the position at the last end of day in the settlement/quote currency                                                                  |
| TotalSettlPaymentsInAccountCcy                                                                                                                       |                                                                                                                                                |
| SettlPrice                                                                                                                                           | TotalSettlPayments / Volume                                                                                                                    |
| CloseTradeId                                                                                                                                         | Only for positions history — reference to the trade that changed the position                                                                  |
| ClosePrice                                                                                                                                           | Only for positions history. See explanation about position history below                                                                       |
| CloseDt                                                                                                                                              | Only for positions history                                                                                                                     |
| IsClosed                                                                                                                                             |                                                                                                                                                |
| RealizedPnL                                                                                                                                          | Gross PnL (not accounting for commissions) attributed to this position history record                                                          |
| RealizedPnLInAccountCcy                                                                                                                              |                                                                                                                                                |
| FloatingPnL                                                                                                                                          | Daily floating PnL attributed to this position history record                                                                                  |
| TotalFloatingPnL                                                                                                                                     |                                                                                                                                                |
| Commission                                                                                                                                           | Total commission attributed to this part of the position.                                                                                      |
| For opened positions it equals the sum of commissions of opening trades, for closed positions — commissions of opening trades and the closing trade. |                                                                                                                                                |
| SignalGroupId                                                                                                                                        |                                                                                                                                                |
| IsSynthetic                                                                                                                                          | Whether the contract is synthetic                                                                                                              |
| ParentPositionId                                                                                                                                     | For positions that are real positions in legs of a synthetic contract, contains the reference to the parent position in the synthetic contract |
| ChangeType                                                                                                                                           | Only for position history records — the type of the change:                                                                                    |
| • Open                                                                                                                                               |                                                                                                                                                |
| • Close                                                                                                                                              |                                                                                                                                                |
| • MTM (mark to market at the end of day)                                                                                                             |                                                                                                                                                |

## Position history

Whenever a position changes, a history record is saved to indicate the position's state at that time. For example:

* The first trade opens a position +10 AAPL @ 295
* The second trade +5 AAPL is booked:
  * The open positions will contain one position +15 AAPL. Its OpenTradeId will be set to the ID of the second trade, and HistoryOpenDt — to its timestamp
  * Position history will contain a record +10 AAPL, with CloseDt and CloseTradeId set to those of the second trade; and OpenDt and OpenTradeId — to those of the first one. The close price will be equal to the open price (since the position has increased and there was no change in realized PnL)
* If the position is partially closed, the volume of the position history record will reflect the closed amount. The record will additionally contain the realized PnL attributed to the closed part. The commissions and TotalFloatingPnL are distributed between the closed and the remaining part proportionally to their volumes.
* At the end of day all positions are marked to market. Position history records are created for all existing positions, with CloseDt equal to the timestamp of the end of day, ClosePrice — to the end of day price, and FloatingPnL reflecting the today’s value. For the active positions, SettlPx will be updated to the end of day price, HistoryOpenDt — to the timestamp, and TotalSettlPayments — to the value as of the end of day.

Position history allows us to see the actual positions at any moment in time (by selecting history records with HistoryOpenDt ≤ timestamp and CloseDt ≥ timestamp) and helps build P\&L reports.

## PnL and yield calculation

At the end of each day (the exact time is determined by platform-wide settings), all active positions and balances are marked to market. For contracts quoted or settled in currencies different from the account base currency, the value is converted to the account currency. The account's total equity is recorded and compared with the equity at the end of the previous day to calculate the daily PnL.

Yield also accounts for the changes in the investment; see details [here](/quantinfra-docs/balances-and-investment.md#investment-and-share-count).

Floating PnL is recorded for all open positions in the position history.

Each end of day creates the following records:

### Daily return (SharePriceHistory)

<table><thead><tr><th width="212.015625">Property</th><th>Description</th></tr></thead><tbody><tr><td>DailyReturn</td><td>Daily return on the account</td></tr><tr><td>HWM</td><td>High water mark</td></tr><tr><td>ShareCount</td><td>Current share count</td></tr><tr><td>SharePrice</td><td>Current share price.<br>Total return = SharePrice - 1 (x 100%)</td></tr></tbody></table>

### End-of-day balances (BalanceValue)

There may be several balance records, one for each currency. Open positions are grouped by the settlement currency of the position's contract.

<table><thead><tr><th width="212.015625">Property</th><th>Description</th></tr></thead><tbody><tr><td>Cash balance</td><td>Cash balance in the respective currency. It includes:<br>- balance operations<br>- settlement (quote) currency payments (CalculatedCcyLastQty) for the trades in contracts of type Stock and FX<br>- base currency payments for the trades in contracts of type FX<br>- commissions for trades in contracts of all types</td></tr><tr><td>Holdings</td><td>The open values of all positions in contracts of type Stock</td></tr><tr><td>UnrealizedPnL</td><td>Floating PnL of all positions in contracts of type Stock</td></tr><tr><td>FuturesVM</td><td>Floating PnL of all positions in contracts of type Futures and CFD</td></tr><tr><td>Total amount</td><td>Sum of the above</td></tr></tbody></table>

### End-of-day position values

<table><thead><tr><th width="212.015625">Property</th><th>Description</th></tr></thead><tbody><tr><td>Signed value</td><td>Value of the position in the contract's settlement currency</td></tr><tr><td>Fx rate</td><td>FX conversion rate from settlement currency to account currency</td></tr><tr><td>Signed value in account currency</td><td></td></tr><tr><td>SharePrice</td><td>Current share price.<br>Total return = SharePrice - 1 (x 100%)</td></tr><tr><td>Equity value in account currency</td><td>For contracts of type Stock, equals the signed value. For Futures and CFDs equals the unrealized PnL (variation margin).</td></tr></tbody></table>

## Spot FX trades (including cryptocurrencies)

Spot FX trades immediately update the cash balances of both the base and quote currencies. If you need to track the virtual positions at the contract level, enable the respective feature for the account.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantinfra.gitbook.io/quantinfra-docs/positions-pnl-and-yield-tracking.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
