Skip to main content

Overview

Drift Protocol calculates Profit and Loss (PnL) for perpetual positions based on the difference between entry and exit prices, including funding payments and fees.

Position PnL Formula

The basic PnL formula:
Where:
  • baseAssetAmount - Position size (positive for long, negative for short)
  • exitPrice - Current market price or oracle price
  • entryPrice - Average entry price
  • quoteAssetAmount - Accumulated quote changes from trades

Calculating Position PnL

Example

Base Asset Value

Calculate the value of the base asset amount at current prices:
Base asset value represents the market value of closing the entire position at current AMM prices.

Oracle-Based Asset Value

Simpler calculation using oracle price directly:

Funding PnL

Funding payments are settled periodically between longs and shorts:

Formula

Example

Fees and Funding Combined

Get total fees and funding for a position:

Entry Price

Calculate the average entry price of a position:

Formula

Break-Even Price

Calculate the break-even price (including fees and funding):

Example

Cost Basis

Calculate the current cost basis of a position:

Claimable PnL

Not all unrealized PnL can be immediately settled:
Claimable PnL may be less than unrealized PnL due to the PnL pool mechanism that prevents bank runs.

Practical Examples

Complete Position Summary

Calculate Return on Investment (ROI)