The calculation of Mark Price is intricately linked to the Funding Rate and vice versa. It is highly recommended to read both sections to get a full picture of how the system works.
As Unrealized PnL is the primary driver of liquidations, and as the Perpetual Contract allows for highly leveraged (up to 125x) positions, it is important to ensure that the Unrealized PnL calculation is accurate to avoid unnecessary liquidations. The underlying contract for the Perpetual Contract is the ‘true’ value of the Contract, and an average of the prices on the major markets constitutes the “Index Price” which is the primary component of Mark Price.
The Index Price is a bucket of prices from the major Spot Market Exchanges, weighted by their relative volume. The Exchanges used are:
There are additional protections to avoid poor market performance during outages of Spot Exchanges or during connectivity problems. These protections are listed below:
- Single price source deviation: When the latest price of a certain exchange deviates more than 5% from the median price of all price sources, the exchange weight will be set to zero for weighting purposes.
- Multi price source deviation: If more than 1 exchange shows greater than 5% deviation, the median price of all price sources will be used as the index value instead of the weighted average.
- Exchange Connectivity Problem: If we can’t access the data feed for exchange and this exchange has trades updated in the last 10 seconds, we can take price data from the last result and use it for index calculation.
If one exchange has no updates for 10 seconds, the weight of this exchange will be zero when calculating the weighted average.
Now that we’ve computed the Index Price, which can be considered as the “Spot Price”, we can move forward in calculating the Mark Price which is used for all Unrealized PnL calculations. Note that Realized PnL is still based on the actual executed market prices.
Mark price formula for perpetual futures contracts is as follows:
Mark price = Median* (Price 1, Price 2, Contract Price)
Price 1 = Index Price * (1 + Last Funding Rate * (Time Until Funding / 8))
Price 2 = Index Price + Moving Average (30-minute Basis)*
*Moving Average (30-minute Basis) = Moving Average ((Bid1+Ask1)/2- Index Price), which measures every minute in 30-minute interval
*Median: If Price 1 < Price 2 < Contract Price, then take Price 2 as Mark price.
Mark Price is a better estimate of the ‘true’ value of the contract, compared to Perpetual Futures prices which can be more volatile in the short term. We use this price to prevent unnecessary liquidations for traders and to discourage any market manipulations by poor actors.
Unrealized PnL is thus calculated as (all values in USDT):
- Net Negative Position: UnrealizedPnL= (Entry Price−MarkPrice)×S
- Net Positive Position: UnrealizedPnL=(MarkPrice−InitialBuyPrice)×Position
- Total Collateral for Margin and Liquidation purposes: Collateral=InitialCollateral+RealizedPnL+UnrealizedPnL
The maximum amount of collateral can be withdrawn from the account so long as collateral > (initial margin + borrowed amount) .