Sub topic 9
Margin and leverage
This chapter assumes you know what a futures contract is, how a long and a short position differ, and how linear contracts are priced. It also assumes you can read short Python functions. Liquidation gets its own chapter. Here we cover the accounting that decides when it happens.
What margin is
Margin is collateral that you lock up to hold a derivatives position. It is not a down payment on a purchase. You never buy the underlying coin, so nothing is bought with the margin. It is a deposit that covers losses on the position. The exchange holds it, and you can lose it.
Three quantities appear on every venue, under slightly different names:
- Initial margin is the collateral needed to open a position.
- Maintenance margin is the minimum collateral needed to keep it open.
- Margin balance is your collateral plus unrealized profit or loss (PnL) on the position.
If margin balance falls to the maintenance level, the exchange starts closing the position. The gap between initial and maintenance margin is your loss buffer.
Leverage is a ratio
Leverage is position notional divided by the margin backing it. Notional is quantity times price.
initial margin = notional / leverageA 1 BTC long at 60,000 USDT has a notional of 60,000. At 10x leverage the initial margin is 6,000 USDT. At 50x it is 1,200 USDT.
Leverage settings change how much margin the exchange locks. They do not change the position's profit and loss per dollar of price movement. A 1 BTC position gains or loses 1 USDT per 1 USDT move at any leverage setting. What changes is how large that move is compared with your margin.
A 10% fall in price costs 6,000 USDT on a 1 BTC position at 60,000. That is the entire margin at 10x, and five times the margin at 50x. At 50x the position is liquidated well before the price falls 10%.
Two kinds of leverage need separating:
- Selected leverage is the setting you choose. It determines initial margin.
- Effective leverage is current notional divided by current margin balance. It drifts as price moves. A losing position's effective leverage rises, because margin balance shrinks while notional stays roughly the same.
Margin modes
Exchanges let you choose which collateral backs a position.
Isolated margin assigns a fixed amount of margin to each position. If that position is liquidated, you lose only the assigned margin. Other balances in your account are untouched. Many exchanges let you add margin manually to a position, which moves its liquidation price further away.
Cross margin backs all positions with the whole account balance. A losing position can draw on every free coin you hold, and profits on one position can offset losses on another. Liquidation happens later, but when it does it can take the entire account.
| Property | Isolated | Cross |
|---|---|---|
| Collateral per position | Fixed amount you assign | Whole account balance |
| Liquidation price | Closer to entry | Further from entry |
| Worst-case loss | The assigned margin | The entire account |
| Management effort | Higher, you top up by hand | Lower, the account absorbs losses |
| Typical use | Speculative or high-leverage trades | Hedged books, several related positions |
Some venues add a portfolio margin mode. It nets offsetting positions and computes margin from the risk of the whole book. This lowers requirements for hedged structures such as the basis trade covered later in this tutorial.
How the pieces fit
The unrealized PnL in this flow is computed from the mark price, not the last traded price. This keeps one thin trade from triggering liquidations. The mark price is covered in a later chapter.
Worked example in code
The script below opens a 1 BTC long at 60,000 with 10x leverage and a 0.5% maintenance margin rate. It checks the position after a fall to 57,000. It also compares liquidation prices under isolated and cross modes, assuming a 10,000 USDT account. Fees and funding are ignored.
def initial_margin(qty, price, leverage):
return qty * price / leverage
def margin_balance(margin, qty, entry, mark, side="long"):
sign = 1 if side == "long" else -1
return margin + sign * qty * (mark - entry)
def maintenance_margin(qty, mark, mmr):
return qty * mark * mmr
def effective_leverage(qty, mark, balance):
return qty * mark / balance
def liquidation_price_long(qty, entry, collateral, mmr):
# Solve collateral + qty * (P - entry) = mmr * qty * P for P.
return (qty * entry - collateral) / (qty * (1 - mmr))
qty, entry, leverage, mmr = 1.0, 60000, 10, 0.005
wallet = 10000
im = initial_margin(qty, entry, leverage)
mark = 57000
bal = margin_balance(im, qty, entry, mark)
mm = maintenance_margin(qty, mark, mmr)
print("initial margin:", im)
print("margin balance at 57000:", bal)
print("maintenance margin:", mm)
print("margin ratio:", round(mm / bal, 4))
print("effective leverage:", round(effective_leverage(qty, mark, bal), 1))
print("isolated liq price:", round(liquidation_price_long(qty, entry, im, mmr), 2))
print("cross liq price:", round(liquidation_price_long(qty, entry, wallet, mmr), 2))Running it prints an initial margin of 6000.0 and a margin balance of 3000.0 at 57,000. The maintenance margin is 285.0, so the margin ratio is 0.095. Effective leverage has risen from 10x to 19.0x. The isolated liquidation price is 54271.36. The cross price is 50251.26, because the extra 4,000 USDT of free balance absorbs more loss.
The liquidation formula comes from setting margin balance equal to maintenance margin and solving for price. Real venues use tiered maintenance rates and include fees, so their numbers differ slightly.
Common errors
Treating leverage as risk-free capital efficiency. Higher leverage frees up collateral, but the liquidation price moves toward entry. At 10x with a 0.5% maintenance rate, the long above is liquidated at about 9.5% below entry. At 50x, the same position is liquidated only about 1.5% below entry.
Ignoring the maintenance rate. The liquidation distance is not exactly 1 divided by leverage. The maintenance requirement shortens it further. Large positions often face higher maintenance rates, because venues use tiers by notional size.
Forgetting costs that eat margin. Trading fees and funding payments on perpetual swaps both reduce margin balance. A position held for weeks at high leverage can drift toward liquidation with no price move at all.
Using cross margin without noticing the exposure. A small position on a volatile altcoin can be liquidated against your full balance. Check which mode a position uses before you open it, and check again after changing leverage. Some venues reset or restrict mode changes while positions are open.
Changing leverage on an open position. On many exchanges, raising leverage on an open isolated position reduces locked margin and moves the liquidation price closer. Lowering it does the opposite. Confirm the new liquidation price after every change.
Inverse contracts and collateral currency
On inverse contracts, margin is posted in the base coin, for example BTC. Your collateral then changes in dollar value as the price moves. A long loses on the contract and on the collateral at the same time. This makes the loss accelerate compared with a linear contract margined in USDT. Multi-collateral accounts add another layer: the exchange applies a haircut to volatile collateral, so 1 dollar of ETH counts for less than 1 dollar of margin.
Exercise
You open a 2 BTC long at 50,000 USDT on a linear contract with 20x leverage, isolated margin, and a 0.5% maintenance margin rate. What is the initial margin, and at what price is the position liquidated, ignoring fees and funding?
Show answer
Notional is 2 50,000 = 100,000 USDT, so the initial margin is 100,000 / 20 = 5,000 USDT. Liquidation occurs where margin + qty (P - entry) = mmr qty P. That gives P = (qty entry - margin) / (qty (1 - mmr)) = (100,000 - 5,000) / (2 * 0.995) = 95,000 / 1.99, or about 47,738.69 USDT. That is roughly 4.5% below entry.