Sub topic 5
Calculating a liquidation price
This chapter assumes you know what margin and leverage are, how long and short positions work, and how maintenance margin differs from initial margin. You should also be able to read short Python functions. By the end you will be able to derive a liquidation price from first principles, check it with code, and see which real-world details move it.
What a liquidation price is
A liquidation price is the price at which your position's equity falls to the exchange's maintenance requirement. Equity is your margin plus unrealized profit and loss. Once equity reaches the maintenance requirement, the exchange's liquidation engine takes over the position. You do not get to choose to hold on.
The calculation is a single equation. You set equity equal to the maintenance requirement and solve for price.
Defining the terms
Take a position of Q units of an asset, opened at entry price E.
- Leverage L is the position value divided by your margin. The initial margin rate is
i = 1 / L. - Maintenance rate m is the fraction of the current position value you must keep as equity. Typical values for large crypto contracts are well below 1%, but they rise with position size on most exchanges.
- Equity is the initial margin plus unrealized profit and loss.
This chapter uses an isolated linear contract. Isolated means only the margin assigned to this position backs it. Linear means the contract is quoted and settled in a stable currency such as USDT, so profit is Q times the price change.
Deriving the long formula
For a long position at price P:
- Initial margin:
Q * E * i - Unrealized profit and loss:
Q * (P - E) - Equity:
Q * E * i + Q * (P - E) - Maintenance requirement:
m * Q * P
Liquidation happens when the equity equals the requirement:
Q*E*i + Q*(P - E) = m*Q*P
E*i + P - E = m*P
P*(1 - m) = E*(1 - i)
P = E * (1 - i) / (1 - m)Q cancels out. In this model the liquidation price depends on leverage and the maintenance rate, not on how large the position is. Real exchanges break this by raising m for larger positions.
Deriving the short formula
A short profits when the price falls, so unrealized profit and loss is Q * (E - P):
Q*E*i + Q*(E - P) = m*Q*P
E*(1 + i) = P*(1 + m)
P = E * (1 + i) / (1 + m)The long and short formulas mirror each other. Both rely on the same setup, so the same algebra works with the sign of the price move flipped.
The maintenance requirement is measured against the current price P, not the entry price. That is why 1 - m and 1 + m appear in the denominators. Using the entry price instead gives a close but slightly different answer.
The formula in code
This function implements both formulas. It also takes an optional extra_margin_ratio, which is margin added beyond the initial margin, expressed as a fraction of the entry notional.
def liquidation_price(entry, leverage, maintenance_rate, side, extra_margin_ratio=0.0):
"""Approximate liquidation price for an isolated linear position.
Ignores fees, funding and exchange-specific maintenance tiers.
extra_margin_ratio is added margin as a fraction of entry notional.
"""
if leverage < 1:
raise ValueError("leverage must be at least 1")
initial = 1.0 / leverage
if side == "long":
price = entry * (1 - initial - extra_margin_ratio) / (1 - maintenance_rate)
return max(price, 0.0)
if side == "short":
return entry * (1 + initial + extra_margin_ratio) / (1 + maintenance_rate)
raise ValueError("side must be long or short")
print(round(liquidation_price(100.0, 10, 0.005, "long"), 2)) # 90.45
print(round(liquidation_price(100.0, 10, 0.005, "short"), 2)) # 109.45
print(round(liquidation_price(100.0, 10, 0.005, "long", 0.05), 2)) # 85.43
print(round(liquidation_price(100.0, 10, 0.005, "short", 0.05), 2)) # 114.43A 10x long entered at 100 is liquidated at about 90.45, which is a 9.55% fall. The initial margin is 10% of the position, and the maintenance requirement takes back about half a percent of it. Only the roughly 9.5% that remains is available to absorb losses.
Adding margin equal to 5% of notional moves the long liquidation price from 90.45 to 85.43. This is the idea behind a collateral buffer, which a later chapter on risk management covers.
How far away is liquidation?
The distance to liquidation shrinks quickly as leverage rises. This loop uses the same function with m = 0.5% and an entry of 100.
for lev in (2, 5, 10, 20, 50, 100):
long_liq = liquidation_price(100.0, lev, 0.005, "long")
short_liq = liquidation_price(100.0, lev, 0.005, "short")
print(f"{lev:>3}x long {long_liq:6.2f} ({100 - long_liq:5.2f}% below) "
f"short {short_liq:6.2f} ({short_liq - 100:5.2f}% above)")The output matches this table:
| Leverage | Long liquidation price | Fall that liquidates a long | Short liquidation price | Rise that liquidates a short |
|---|---|---|---|---|
| 2x | 50.25 | 49.75% | 149.25 | 49.25% |
| 5x | 80.40 | 19.60% | 119.40 | 19.40% |
| 10x | 90.45 | 9.55% | 109.45 | 9.45% |
| 20x | 95.48 | 4.52% | 104.48 | 4.48% |
| 50x | 98.49 | 1.51% | 101.49 | 1.49% |
| 100x | 99.50 | 0.50% | 100.50 | 0.50% |
Two patterns are worth noticing.
- The distance to liquidation is roughly
1 / Lminus the maintenance rate. At 100x, a move of only 0.5% ends the position, and ordinary intraday noise in crypto is larger than that. - Longs and shorts are slightly asymmetric. At the same leverage, the long's liquidation price sits a little farther from entry in percentage terms than the short's. The reason is that the maintenance requirement scales with the current price, which is lower for a long near liquidation and higher for a short.
What the simple formula leaves out
The formula gives a good estimate. Real exchanges differ from it in several ways, and each difference usually makes liquidation happen sooner.
- Fees. Opening fees reduce your margin, and exchanges often reserve a closing or liquidation fee inside the maintenance requirement. Both move the liquidation price closer to entry.
- Funding payments. On perpetual futures, funding is paid or received periodically. If you pay funding, your equity shrinks over time and the liquidation price drifts toward the market even if the price stays flat.
- Maintenance tiers. Exchanges raise the maintenance rate as position size grows. A large position has a higher
mand a closer liquidation price than the same leverage on a small one. - Mark price. The trigger compares the formula's P against the exchange's mark price, not the last traded price. The next chapters on mark price cover why. For now, remember that a wick on the last-trade chart may not liquidate you, and a move in the index can.
- Margin mode. In cross margin, other balances in the account support the position. Its liquidation price then depends on the whole account, and a single-position formula no longer applies.
- Inverse contracts. If margin is held in the coin itself, as on inverse contracts, profit and loss is not linear in price. The formulas use reciprocals of price, so the algebra changes.
Checking a result by hand
Use this routine whenever you want to verify a number, such as one an exchange shows you.
- Compute the initial margin rate
i = 1 / L. - Pick the formula for your side, long or short.
- Insert the maintenance rate from the exchange's tier table for your position size.
- Subtract any extra margin from the numerator for a long, or add it for a short.
- Move the answer a little toward the market to account for fees and funding you expect to pay.
If the exchange's figure is much farther from entry than yours, check whether it is using cross margin or a lower maintenance tier. If it is much closer, check for fees, funding, or a higher tier.
Summary of the model
- The liquidation price comes from setting equity equal to
mtimes position value. - For an isolated linear long,
P = E * (1 - 1/L) / (1 - m). For a short,P = E * (1 + 1/L) / (1 + m). - The distance to liquidation is about
1/L - m, so doubling leverage roughly halves the room for error. - Fees, funding, tiers, mark price and margin mode all shift the real number. Mostly they shift it toward the market.
Exercise
A trader opens a 20x isolated long on a linear contract at an entry price of 2000, with a maintenance rate of 1%. Ignore fees and funding. What is the liquidation price, and what percentage fall from entry does it represent? Then say whether adding margin worth 5% of the entry notional moves the liquidation price closer to or farther from entry.
Show answer
The initial margin rate is 1/20 = 0.05. The liquidation price is 2000 (1 - 0.05) / (1 - 0.01) = 1900 / 0.99, which is about 1919.19. That is a fall of (2000 - 1919.19) / 2000, about 4.04%. Adding margin equal to 5% of notional changes the numerator to 2000 (1 - 0.05 - 0.05) = 1800, so the liquidation price becomes 1800 / 0.99, about 1818.18. That is farther from entry, a fall of about 9.09%.
Exercise
A trader uses a 10x isolated short with entry 100 and maintenance rate 0.5%. A friend says that "a 10% rise liquidates a 10x short". Using the formula, is the friend exactly right, and why or why not?
Show answer
The short liquidation price is 100 * (1 + 0.1) / (1 + 0.005) = 110 / 1.005, about 109.45. The rise needed is about 9.45%, not 10%. The friend's rule of thumb ignores the maintenance requirement, which is a share of the position that the exchange keeps in reserve. The rule is close, but it overstates the room the trader has.