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:
- CoinTiger
- Bitfinex
- Binance
- Huobi
- OKEx
- Bittrex
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.
As introduced in the last section, Funding occurs every 8 hours. Funding Rate is calculated at that time, and the Funding Rate in the formula is the most recent prior Funding Rate.
Basis=FundingRate×(Time Until Funding /8)
Mark Price=Index Price∗(1+Basis)
As an example:
- Funding Rate = 0.03%
- Time until funding = 4
- Index Price = 10,000
Basis=Funding Rate×(Time Until Funding/8)=0.03%×4/8=0.015%
Mark Price=Index Price×(1+Basis)=10,000×(1+0.015%)=10001.5
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) .