Function toProfitLossDto

Calculates profit/loss for a closed signal with slippage and fees.

For signals with partial closes:

  • Weights are calculated by ACTUAL DOLLAR VALUE of each partial relative to total invested. This correctly handles DCA entries that occur before or after partial closes.

Partial effective price is computed from costBasisAtClose snapshot: effectivePrice = costBasisAtClose / Σ(entry.cost/entry.price for entries[0..entryCountAtClose])

Fee structure:

  • Open fee: CC_PERCENT_FEE (charged once)
  • Close fee: CC_PERCENT_FEE × weight × (closeWithSlip / openWithSlip) per partial/remaining
  • Parameters

    • signal: Signal$2

      Closed signal with position details and optional partial history

    • priceClose: number

      Actual close price at final exit

    Returns IStrategyPnL

    PNL data with percentage, prices, and USD amounts