Liquidation and bankruptcy prices: under the hood

Aditya Palepu
DerivaDEX
Published in
6 min readOct 1, 2020

Liquidation and bankruptcy prices must be well understood when participating in the highly-leveraged and volatile cryptocurrency perpetual swap markets.

I’ve been an institutional quant for the majority of my career. When I first started dabbling in crypto’s most popular product — the perpetual swap — the concepts of liquidation and bankruptcy prices were foreign to me. To understand how these are calculated, I sifted through Binance’s exchange docs, chatted with Bybit’s help desk for hours, and scoured through Reddit’s BitMEX support rabbit hole. Turns out, all this research only made things more confusing. Worse yet, leading exchanges such as FTX have incorrect help guides, suggesting that liquidation price erroneously fluctuates as the mark price changes. This lack of clarity and consistency is exceptionally dangerous for you, the trader. Mistakes happen to the best of us, but no exchange can succeed in the long run without transparency and an obsession with the trading experience. At DerivaDEX, we are committed to this, always and forever.

On that note, what are bankruptcy and liquidation prices, and how are they computed?

Bankruptcy price is the price at which a trader’s losses exactly equals the collateral they’ve deposited.

Liquidation price is the price at which the exchange will begin to automatically close a trader’s position. This price will arrive slightly before the bankruptcy price is reached.

In this post, you’ll learn:

  • How to compute a bankruptcy price (with examples!)
  • How to compute a liquidation price (with examples!)
  • About the implicit (hidden!) costs of high leverage

If you want to view our examples as you go, check out our python/jupyter-notebook calculator with the pre-defined examples we’ll talk about!

This post is part of DexLAB Math Camp, our technical series for traders!

Calculating bankruptcy price

The bankruptcy price is the price at which a trader’s collateral would be fully wiped out due to losses. Let’s analyze the scenario where Alice and Bob each want to gain exposure to Bitcoin at a price of $10,000 via leveraged instruments after having deposited $10,000 and $20,000 of collateral respectively. Alice buys 4 perpetual swap contracts and Bob takes the other side of this by selling 4 contracts. Let’s say BTC/USDT is now trading at $11,000.

Alice (long)

Alice has purchased $40,000 worth of BTC/USDT despite having only deposited $10,000 in collateral and is now 4x-leveraged. If the price of Bitcoin were to rise to $15,000, she would receive $20,000 in profit, 4x more than she would have made if she purchased spot Bitcoin on Coinbase, for example. While on a spot exchange, the price of Bitcoin would have to drop all the way down to $0 to lose her $10,000 of collateral. In this case, due to her leverage, it can drop much less before she loses $10,000. This bankruptcy price can be computed as such:

# Position details
collateral = 10_000
position_side = 1 # 1 = long, -1 = short
position_size = 4
avg_entry_px = 10_000
mark_px = 11_000
# Compute unrealized PNL for position
unrealized_pnl = position_size * position_side * (mark_px - avg_entry_px) = 4 * 1 * (11_000 - 10_000) = 4_000
# Compute current account value
total_account_value = collateral + unrealized_pnl = 10_000 + 4_000 = 14_000
# Compute bankruptcy price
bankruptcy_px = mark_px - position_side * (total_account_value / position_size) = 11_000 - 1 * (14_000 / 4) = 7_500

Bob (short)

Bob has sold $40,000 worth of BTC/USDT despite having only deposited $20,000 in collateral and is now 2x-leveraged. If the price of Bitcoin were to fall to $5,000, he would receive $10,000 in profit, 2x more than he would have made if he purchased spot Bitcoin on Coinbase, for example. On a spot exchange, the price of Bitcoin would have to rise all the way to $20,000 for him to lose his $10,000 of collateral. It does not have to rise as much in this case for him to lose his collateral, because of his leverage. Using the same logic as above, Bob’s bankruptcy price can be computed as such:

# Position details
collateral = 20_000
position_side = -1 # 1 = long, -1 = short
position_size = 4
avg_entry_px = 10_000
mark_px = 11_000
# Compute unrealized PNL for position
unrealized_pnl = position_size * position_side * (mark_px - avg_entry_px) = 4 * -1 * (11_000 - 10_000) = -4_000
# Compute current account value
total_account_value = collateral + unrealized_pnl = 20_000 - 4_000 = 16_000
# Compute bankruptcy price
bankruptcy_px = mark_px - position_side * (total_account_value / position_size) = 11_000 + 1 * (16_000 / 4) = 15_000

Calculating liquidation price

The liquidation price is the price at which the exchange will trigger a liquidation (i.e. automatically close a trader’s position) due to under-collateralization. This is where things get a bit fuzzy, and most exchanges do nothing to help you out.

The first concept to understand is the maintenance margin ratio. Maintenance margin ratio (mmr) refers to how much collateral a trader must maintain before being forcibly closed, acting as some buffer for the exchange before their position becomes truly worthless (or worse yet, less than worthless). In order for a position to remain open, it must meet the following condition:

total_account_value / position_notional >= mmr

So how do we get from here to computing the liquidation price (which is the mark price at which point a liquidation will be triggered)?

position_notional = position_size * mark_px
total_account_value = collateral + unrealized_pnl
unrealized_pnl = position_size * position_side * (mark_px - avg_entry_px)
collateral + position_size * position_side * (mark_px - avg_entry_px) / (position_size * mark_px) >= mmrcollateral + position_size * position_side * (mark_px - avg_entry_px) >= mmr * position_size * mark_pxcollateral + (position_size * position_side * mark_px) - (position_size * position_side * avg_entry_px) >= mmr * position_size * mark_pxcollateral - (position_size * position_side * avg_entry_px) >= (mmr * position_size * mark_px) - (position_size * position_side * mark_px)collateral - (position_size * position_side * avg_entry_px) >= mark_px * position_size * (mmr - position_side)mark_px = liquidation_px = (collateral - position_size * position_side * avg_entry_px) / (position_size * (mmr - position_side))

Alice (long)

If you recall, Alice has purchased $40,000 worth of BTC/USDT (when BTC/USDT was at a price of $10,000) with $10,000 in collateral and is now 4x-leveraged. Let’s assume a real-world maintenance margin ratio of 3%.

# Position details
collateral = 10_000
position_side = 1 # 1 = long, -1 = short
position_size = 4
avg_entry_px = 10_000
mmr = 0.03
# Compute liquidation price
liquidation_px = (collateral - position_size * position_side * avg_entry_px) / (position_size * (mmr - position_side)) = (10_000 - 4 * 1 * 10_000) / (4 * (0.03 - 1)) = 7_731.96

As you can see, Alice’s liquidation price is $7,731.96, which arrives prior to her bankruptcy price of $7,500 (since she is long).

Bob (short)

If you recall, Bob has sold $40,000 worth of BTC/USDT (when BTC/USDT was at a price of $10,000) with $20,000 in collateral and is now 2x-leveraged. Let’s assume a real-world maintenance margin ratio of 3%.

# Position details
collateral = 20_000
position_side = -1 # 1 = long, -1 = short
position_size = 4
avg_entry_px = 10_000
mmr = 0.03
# Compute liquidation price
liquidation_px = (collateral - position_size * position_side * avg_entry_px) / (position_size * (mmr - position_side)) = (20_000 - 4 * -1 * 10_000) / (4 * (0.03 + 1)) = 14_563.11

As you can see, Bob’s liquidation price is $14,563.11, which arrives prior to his bankruptcy price of $15,000 (since he is short).

What does this all mean?

Bankruptcy and liquidation prices are two of the most significant price levels a trader needs to be aware of when trading perpetual swaps. As shown above, your collateral, position size, position side, average entry price, and maintenance margin ratio can impact where these prices are relative to the current mark price of the product.

One key takeaway of these prices is that they reveal the implicit cost you’re paying for high-leveraged positions. If you play around with the formulas above, you may notice that as you raise your leverage, the maintenance margin becomes an increasingly significant portion of the initial margin buffer you have. As covered in our primer on insurance funds, when the liquidation price is crossed, your position will be automatically closed, effectively losing you the maintenance margin spread to the exchange.

This chart shows you how the maintenance margin proportion grows when you increase your leverage.

This is a big way exchanges make money off of you, eating your margin as if it were a fee. This fee grows (and can be quite large) with higher leverage. While trading highly-leveraged perpetual swaps can be a capital-efficient, hassle-free, and even fun way to express a view on the market, it’s important to track the bankruptcy and liquidation prices of your position to avoid losing your collateral, which is way less enjoyable.

Bankruptcy and liquidation price calculator

Feel free to check out our python/jupyter-notebook calculator with the pre-defined examples we used above!

For more of these DexLAB Math Camp posts, see:

Stay in touch!

We’ll reveal more about our unique design in coming days.

--

--

Aditya Palepu
DerivaDEX

Co-Founder & CEO @ DEX Labs. Duke Eng '13 (ECE/CS). Blockchain, ML/AI enthusiast. Previously DRW algorithmic trader. D.C. sports fanatic and burrito lover.