Joseph Chang

Why PL keeps changing while my position is zero?

Programming


From my understanding, NAV and "Cumulative PnL" should remain unchanged, if there is no outstanding positions.

However, from the backtest result (see highlighted below), for certain days when "Net Position" is zero, "Cumulative PnL" is not constant.

I couldn't understand how "Cumulative PnL" is calculated. Could anyone kindly explain it? Thanks you.



q

 
tony lam

This issue is related to offsetting trades.

Suppose we opened the following 2 trades:

  • 0.01 lot BUY order (TRADE_ID = 44195803) at 2021-01-08 19:00:36, and
  • 0.01 lot SELL order (TRADE_ID = 44197289) at 2021-01-08 20:00:38
trades

They are 2 offsetting trades with different trade ID. In terms of daily mark-to-market,

  • PnL for TRADE_ID=44195803 would be calculated as (MarketBidPrice - 1.21969),
  • PnL for TRADE_ID=44197289 would be (1.22133 - MarketAskPrice)

Thus, although the net position is zero, the residual PnL is (MarketBidPrice - MarketAskPrice) which is still subject to the market bid-ask fluctuation. The highlighted part is exactly the market bid-ask that this pair of trades will subject to fluctuate.



 
tony lam

To "freeze" or realize the PnL, we should submit a close order for TRADE_ID = 44195803, instead of opening an offsetting trade. Please refer to section 'Place Order' in technical document

techdoc

For example, when opening a new order, we can firstly create our own orderRef, say '1'.

example

When the order is successfully opened (refer to 'OrderFeed'), we can based on the orderRef to create a mapping to the system generated TradeID. Then, we know which TradeID we want to close later.

orderfeed