Correcting Position Cost, Average Price, and P&L in an Options Gateway
Summary
This troubleshooting post examines why position records from an options gateway show zero unrealized profit and loss. The author traces the issue to the gateway’s position-query handler: it initializes average price at zero, while the received position-profit field is also always zero. The post then presents a modified handler that derives average price from open cost, position size, and contract multiplier, and computes P&L using open cost and option value.
The modification also uses the response’s yesterday-position field instead of deriving yesterday’s holdings by subtracting today’s position from total position. The author reports that the revised values match those shown in the trading client. This is a platform-specific workaround based on the author’s observed data and code; the post does not establish that the P&L formula applies to every instrument, gateway, or accounting convention. Users would need to verify field meanings and sign handling against their own broker interface.
Key ideas
- The gateway’s reported position-profit field may be zero even when a position has P&L.
- Average position price can be reconstructed from open cost, position quantity, and contract size.
- The author derives option P&L from open cost and option value, with different calculations based on the option value’s sign.
- The post recommends using the response’s yesterday-position field rather than inferring it from other position fields.
- The fix is specific to the described gateway and should be checked against the broker’s field definitions.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.