track_lot_profitability#

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

track_lot_profitability(df)[source]#

Tracks per-lot realised and unrealised profit and calculates weighted average return (%). Assumes FIFO matching for sells.

Parameters:
df (pd.DataFrame): Must contain columns:
  • ‘quantity’: positive for buy, negative for sell

  • ‘executed_price’: trade execution price

  • ‘mark_price’: current market price for unrealised PnL

Returns:

pd.DataFrame: Original dataframe + total_pnl and weighted_return_pct columns

Parameters:

df (DataFrame) –

Return type:

DataFrame