unrealizedPnL method

double unrealizedPnL(
  1. double currentPrice
)

Calculates net unrealized profit or loss in absolute currency units.

Implementation

double unrealizedPnL(double currentPrice) {
  if (isLong) {
    return (currentPrice - entryPrice) * quantity;
  } else {
    return (entryPrice - currentPrice) * quantity;
  }
}