revalue_positions
Match trades FIFO to compute realized and unrealized P&L, showing open positions and trade history. Pass executions and optional marks to get profit breakdown per symbol.
Instructions
Match buys and sells FIFO and compute realised and unrealised P&L.
Use this to turn a list of fills into a trade history — "what did I actually make on these trades", "which positions are still open", "what is my realised P&L". Fills are matched first-in-first-out per instrument: a sell consumes the oldest open lots first, and any excess opens a position in the opposite direction, so a sell of 150 against a long of 100 closes the 100 and leaves a short of 50. Longs and shorts are handled symmetrically.
Pass the executions in; this tool cannot fetch anyone's trade history. Realised P&L is converted to your reporting currency at the closing fill's FX rate, which is where the gain is crystallised.
Optionally pass marks (symbol to current price) to get unrealised P&L on whatever
remains open. Symbols without a mark are reported with a null rather than being
treated as flat.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| marks | No | ||
| executions | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| open_lots | Yes | ||
| closed_trades | Yes | ||
| realised_pnl_base | Yes | Total realised P&L in the reporting currency. | |
| unrealised_pnl_by_symbol | No | Per-symbol mark-to-market on open lots, in each lot's own currency. |