track_lot_profitability_detailed#

API documentation for tradeexecutor.visual.position.track_lot_profitability_detailed Python function.

track_lot_profitability_detailed(df)[source]#

Track lot-level realised and unrealised PnL using FIFO method, and return position-level summary metrics at each step.

Parameters:
df (pd.DataFrame): Must contain columns:
  • ‘quantity’: +ve for buy, -ve for sell

  • ‘executed_price’: trade price

  • ‘mark_price’: current market price for unrealised PnL

Returns:
pd.DataFrame: with added columns:
  • ‘total_pnl’: realised + unrealised PnL (USD)

  • ‘total_pnl_pct’: profitability in percent of capital

  • ‘unrealised_pnl’: mark-to-market PnL of open lots

  • ‘realised_pnl’: cumulative PnL from closed lots

Parameters:

df (DataFrame) –

Return type:

DataFrame