Unrealized PnL Formulas
Unrealized PnL represents the current profit or loss on an open position, computed from the live forward price. LONG position (trader profits when price goes up):notionalis in USDC precision (6 decimals)currentForwardPriceandentryStrikeare in price precision (18 decimals)PRICE_PRECISION= 1e18- The result is in USDC precision (6 decimals)
- Positive = profit, negative = loss
The forward price used for unrealized PnL is the live forward price for the position’s specific fixing timestamp, fetched via
OracleModule.getForward(pairId, fixingTimestamp). This is different from the fixing price used at maturity settlement.Position Equity
Position equity determines whether a position can be liquidated:imLocked is the margin currently locked against the position (Onchain: stored in the Position struct, mutable via add/remove margin) and unrealizedPnl is signed (Computed: derived from the current forward price and entry strike). Position equity itself is Computed — it is not stored onchain.
When equity falls below the maintenance margin threshold (mmThreshold), the position becomes liquidatable. See the Liquidation page for details.
Account Equity
Account equity provides a holistic view of a trader’s financial state across all positions:aggregateUnrealizedPnl is the sum of unrealized PnL across all of the account’s open positions. This metric is used for account-level health monitoring, though the protocol’s isolated margin model means each position is liquidated independently.
Under isolated margin (the only mode in M2), each position’s risk is contained to its own locked margin. A deeply underwater position does not affect other positions or free collateral — only the margin locked against that specific position is at risk.
Dual PnL Tracking
When a position closes (via settlement, liquidation, or early termination), the protocol records two PnL values:| Field | Description | Capped? |
|---|---|---|
realizedPnl | Accounting PnL used for margin transfers | Yes — losses capped at marginAtRisk |
marketPnl | True mathematical PnL for analytics | No |
When They Diverge
realizedPnl drives all USDC transfers. The marketPnl is recorded for accurate analytics and auditing. A BadDebt event is emitted whenever these values diverge.
Worked Examples
Example 1: LONG Position in Profit
Example 1: LONG Position in Profit
Setup:Position equity: 20 (IM) + 20 (PnL) = 40 USDCThe trader is profitable. Both
- Side: LONG
- Notional: 1,000 USDC (1,000,000,000 raw)
- Entry strike: 1.08 (1,080,000,000,000,000,000 in 18 decimals)
- Current forward price: 1.10 (1,100,000,000,000,000,000)
- IM locked: 20 USDC
realizedPnl and marketPnl would be +20 USDC if the position were closed at this price.Example 2: SHORT Position in Profit
Example 2: SHORT Position in Profit
Setup:Position equity: 20 (IM) + 20 (PnL) = 40 USDCThe trader profits because the EUR/USD rate dropped, matching their SHORT bet.
- Side: SHORT
- Notional: 1,000 USDC (1,000,000,000 raw)
- Entry strike: 1.08 (1,080,000,000,000,000,000)
- Current forward price: 1.06 (1,060,000,000,000,000,000)
- IM locked: 20 USDC
Example 3: Bad Debt Scenario
Example 3: Bad Debt Scenario
Setup:Position equity: 20 (IM) + (-25) (PnL) = -5 USDC (negative)Dual PnL values at close:
- Side: LONG
- Notional: 1,000 USDC
- Entry strike: 1.08
- Current forward price: 1.055 (significant adverse move)
- IM locked: 20 USDC
marginAtRisk= 20 USDC (the locked margin)|pnl|= 25 >marginAtRisk= 20 —> bad debt scenariorealizedPnl= -20 USDC (loss capped at margin)marketPnl= -25 USDC (true mathematical loss)- Bad debt = 25 - 20 = 5 USDC absorbed by pool
Price Sources for PnL
Different operations use different price sources:| Operation | Price Source | Description |
|---|---|---|
| Unrealized PnL (mark-to-market) | Forward price | Live forward price for the position’s fixing timestamp |
| Maturity settlement | Fixing price | Pyth spot price recorded at 4 PM UTC on maturity day |
| Early termination | Forward price | Current forward price at close time |
| Liquidation | Forward price | Current forward price at liquidation time |
| Partial reduction | Forward price | Current forward price at reduction time |
PnL Capping Mechanics
At settlement, losses are capped at the margin available to cover them. This is the isolated margin guarantee:marginAtRisk equals the position’s imLocked. For a partial reduction, it is calculated proportionally: