Sub topic 14
Insurance funds and auto-deleveraging
This chapter assumes you know how isolated margin works, what maintenance margin is, and how a mark price triggers liquidation. You also need to read short Python functions. The chapter covers what happens when liquidation fails to close a position at a safe price.
The problem: losses that exceed margin
A trader's margin is the most they have put at risk on a position. A perpetual swap exchange still has to pay winners in full, even when a loser's margin is gone. The exchange cannot ask the loser for more money, because the loser has no obligation beyond the margin posted. Two mechanisms cover the gap: an insurance fund and, if that is not enough, auto-deleveraging (ADL).
Two prices matter here.
- The liquidation price is where the exchange takes over the position. It sits above the point of total loss for a long, because maintenance margin is still left in the account.
- The bankruptcy price is where the position's equity reaches exactly zero. For an isolated-margin long, it is
entry * (1 - 1/leverage). For a short, it isentry * (1 + 1/leverage).
The liquidation engine tries to close the position at a price better than the bankruptcy price. Whatever is left over, or missing, is settled against the insurance fund.
How the insurance fund works
The insurance fund is a pool of the exchange's collateral, usually held in the contract's settlement currency. It has two flows.
- Inflow: if a liquidated position closes at a price better than its bankruptcy price, the remaining equity goes into the fund. Some venues also add a share of fees.
- Outflow: if the position closes at a price worse than its bankruptcy price, the fund pays the difference so the winning counterparty is made whole.
The code below computes the result of a liquidation from the fill price, ignoring fees.
def bankruptcy_price(entry, leverage, side):
if side == "long":
return entry * (1 - 1 / leverage)
return entry * (1 + 1 / leverage)
def liquidation_equity(qty, entry, leverage, side, fill_price):
"""Equity left after closing at fill_price.
Positive goes to the insurance fund; negative is paid by it."""
sign = 1 if side == "long" else -1
margin = qty * entry / leverage
pnl = sign * qty * (fill_price - entry)
return margin + pnl
print(bankruptcy_price(60000, 10, "long"))
print(liquidation_equity(1, 60000, 10, "long", 54200))
print(liquidation_equity(1, 60000, 10, "long", 54000))
print(liquidation_equity(1, 60000, 10, "long", 53500))This prints 54000.0, 200.0, 0.0 and -500.0. The long has 6,000 of margin. A fill at 54,200 leaves 200 for the fund. A fill at 53,500 costs the fund 500.
Why fills can be worse than bankruptcy
The liquidation engine acts when the mark price crosses the liquidation price. The sale itself happens on the order book at real prices. Several things can make the fill worse than the bankruptcy price:
- A fast price move can gap through the whole band between the liquidation and bankruptcy prices.
- A thin order book can force the sale to walk deep into the book. Slippage is largest on large positions.
- The mark price is smoothed from the index price, so it can lag the tradable price during sharp moves.
Venues reduce this risk with tiered maintenance margin. Larger positions get a higher maintenance rate, which moves their liquidation price further from bankruptcy. Some venues also liquidate in partial steps, reducing the position first and closing the rest only if the price keeps moving.
The loss waterfall
The exchange applies the following order when a liquidation leaves a shortfall.
Auto-deleveraging is the last step. The exchange picks profitable traders on the opposite side and force-closes all or part of their positions, usually at the bankrupt trader's bankruptcy price. This removes the open interest the failed trader left behind without any one party owing a debt.
Who gets deleveraged
Exchanges rank opposing traders by how much they stand to gain and how much leverage they use. A common score is unrealized profit percentage multiplied by effective leverage. The highest scores are closed first. The logic is that high-profit, high-leverage traders are the ones most likely to be on the winning side of the failed trade.
def adl_order(positions, mark, side):
"""Rank opposing positions; highest score is deleveraged first."""
sign = 1 if side == "long" else -1
scored = []
for p in positions:
pnl_pct = sign * (mark - p["entry"]) / p["entry"]
scored.append((pnl_pct * p["leverage"], p))
scored.sort(key=lambda x: x[0], reverse=True)
return [p for _, p in scored]
def deleverage(ranked, qty_needed):
closed = []
for p in ranked:
if qty_needed <= 0:
break
take = min(p["qty"], qty_needed)
closed.append((p["name"], take))
qty_needed -= take
return closed
shorts = [
{"name": "A", "entry": 60000, "qty": 2, "leverage": 20},
{"name": "B", "entry": 57000, "qty": 3, "leverage": 5},
{"name": "C", "entry": 55000, "qty": 1, "leverage": 50},
]
ranked = adl_order(shorts, mark=54000, side="short")
print([p["name"] for p in ranked])
print(deleverage(ranked, 2.5))The output is ['A', 'C', 'B'] and [('A', 2), ('C', 0.5)]. Trader B has the largest position but the lowest score, so B is untouched.
Real exchanges show each trader an ADL indicator, often as a row of lights, that tells them how close they are to the front of the queue. Check how your venue ranks traders, because the formula varies.
Alternatives to ADL
Some venues avoid ADL and instead spread the shortfall across all profitable traders. This is called socialized loss, and it reduces everyone's payout by a small percentage. Others rely on a large insurance fund and liquidity-provider vaults to absorb losses. On-chain venues often use a pooled vault as the counterparty. That moves the loss to vault depositors, so ADL is rarely needed there.
| Mechanism | Who bears the loss | Main trade-off |
|---|---|---|
| Insurance fund | The exchange's reserve | Needs a large fund relative to open interest |
| Auto-deleveraging | Top-ranked profitable traders | Hedges can be broken without warning |
| Socialized loss | All winners, pro rata | Payouts become uncertain |
| Liquidity vault | Vault depositors | Depositors take hidden risk |
Common errors and edge cases
- Assuming the liquidation price is the loss limit. Your loss on an isolated position is capped at the margin, but the exchange's loss is not capped at yours.
- Ignoring the fund's size. A fund of a few million dollars against billions of open interest offers little protection in a crash. Compare the fund to open interest, not to its absolute number.
- Treating ADL as only a risk for losers. A winning trader can be force-closed at the bankruptcy price of another account. The trader keeps the profit up to that price but loses the rest of the position.
- Forgetting hedged positions. In a cash-and-carry trade, the perpetual short is hedged by spot. If ADL closes the short, the spot holding becomes an unhedged long exposure, and it may be too late to rebalance during a violent move.
- Mixing up margin modes. In cross margin, other balances can absorb the loss before the fund is touched, so the loss waterfall starts later.
Summary
Liquidation closes a position before its equity reaches zero. When it cannot, the insurance fund covers the gap. When the fund runs out, auto-deleveraging closes ranked opposing positions at the failed trader's bankruptcy price. Each layer protects solvency at a different party's expense.
Exercise
A long with 1 BTC at entry 60,000 and 20x leverage is liquidated. Its bankruptcy price is 57,000. The engine fills the sale at 56,800. Ignoring fees, does the insurance fund gain or lose, and by how much?
Show answer
The margin is 60,000 / 20 = 3,000. The PnL is 1 * (56,800 - 60,000) = -3,200. Equity is 3,000 - 3,200 = -200, so the insurance fund loses 200 USDT.
Exercise
A hedged trader holds spot BTC and a perpetual short. Explain why being auto-deleveraged on the short during a price drop is a problem, even though the short was profitable.
Show answer
ADL closes the short at the failed trader's bankruptcy price, so the hedge disappears. The trader is left holding spot BTC with full downside exposure while the price is falling, and has to either re-open the short at worse terms or accept the loss on the spot position.