Skip to content
All library documents

Separating Trading and Holding PnL in Portfolio Results

Code Quant course library

Summary

This document outlines a per-contract result tracker and a portfolio-level PnL container. The contract tracker stores an opening position, observed trades, position changes, and cumulative long and short traded volumes and costs. It filters duplicate trade notifications by trade identifier and queues newly received trades for processing. When both contract specifications and a current tick are available, it values cumulative long and short activity at the latest price and computes trading PnL from the difference between current value and accumulated trade cost.

Holding PnL is calculated separately from the change between the latest price and the prior close, multiplied by the opening position and contract size; total PnL combines that with trading PnL. The portfolio container holds aggregate PnL fields and can reset them. This is accounting logic, not a trading method, and the excerpt does not explain how positions are closed or costs are reconciled across sessions. Results depend on valid market data, contract sizing, and consistent trade updates; no worked example or validation evidence is provided.

Key ideas

  • Trade identifiers are used to ignore duplicate trade updates.
  • New trades contribute to cumulative long or short volume and cost.
  • Trading PnL marks cumulative traded quantities to the latest price using contract size.
  • Holding PnL uses the opening position and the price change from the prior close.
  • Total contract PnL combines trading and holding components.

Tags

From a private course collection; the original is not published.