QuantCalcs/tools

Tools › Position size calculator

Position Size Calculator

Size a leveraged trade to a fixed risk, fees included — then check that your stop actually fires before the exchange liquidates you.

What you lose if stopped out.
Below entry for a long, above for a short.
Optional — exchange specifics
Often 0.4–1% at low tiers.
Open + close taker fees.
Position size
Risk amount
Margin required
Liquidation price
Stop distance
Max safe leverage
The workingsize, then the safety limit

Ad slot · replace with AdSense unit after approval

Sizing to a fixed risk

The premise of risk-based sizing is that you decide the loss first and let the position follow. If you accept losing 1% of the account and your stop sits 5% away, the position is whatever size makes those two numbers agree. A tighter stop therefore buys a larger position at the same risk — not a safer one.

loss per unit  =  |entry − stop|  +  fee × entry
quantity  =  (balance × risk%) ÷ loss per unit
notional  =  quantity × entry

Fees belong in the loss per unit. Leave them out and the trade quietly risks more than the number you chose.

The part other calculators skip: can you even reach your stop?

A stop-loss only protects you if the exchange lets you get there. Push the leverage high enough and the liquidation price moves inside your stop — the position is closed out before the stop ever triggers, and the “1% risk” you carefully calculated was never real. The loss is the whole margin instead.

There is an exact leverage at which liquidation lands precisely on the stop. Above it you are liquidated first; below it the stop does its job.

long  Lmax = 1 ÷ (1 + fee − (stop ÷ entry) × (1 − mmr))
short Lmax = 1 ÷ ((stop ÷ entry) × (1 + mmr) − 1 + fee)

Two consequences worth internalising. A wider stop lowers the ceiling, because the price has further to travel and liquidation is waiting on the way. And no matter how tight the stop, the ceiling can never exceed 1 ÷ maintenance rate — at 0.5% maintenance that is 200×, at 5% it is 20×, because maintenance margin alone eventually consumes what you posted.

What this excludes

This models an isolated-margin position on a linear perpetual. Under cross margin your whole balance backs the trade, so liquidation sits further away and depends on your other positions. Exchanges also use tiered maintenance rates that rise with position size, funding is ignored because it accrues over time rather than at a point, and slippage means a stop may fill worse than its trigger price. Each of those pushes the real outcome slightly against you, so treat the ceiling as an upper bound rather than a target.

Questions

How do I calculate position size from risk?

Divide the amount you are willing to lose by the loss per unit, which is the distance from entry to stop plus the round-trip fee on that unit. The result is the quantity to buy or sell, and multiplying it by the entry price gives the notional.

Can I be liquidated before my stop is hit?

Yes, and it is a common and expensive mistake. If your leverage is high enough, the liquidation price sits between your entry and your stop, so the exchange closes the position first and your intended risk limit never applies.

What is the maximum leverage I can safely use?

The leverage at which the liquidation price lands exactly on your stop. Beyond it, liquidation comes first. It depends on how far your stop sits from entry, the maintenance margin rate, and fees, and it can never exceed one divided by the maintenance rate.

Risk note. Leveraged trading can lose your entire margin, and liquidation often happens faster than expected during volatile moves. These figures are estimates for education and risk-planning, not trading or financial advice. Your exchange’s own margin engine is the authority for your account.

How this was verified

The leverage ceiling is not asserted, it is checked. A script simulates a margin account and walks the price from entry toward the stop, testing at every step whether equity has fallen to the maintenance requirement, and confirms that the closed form predicts which event fires first — stop or liquidation — on both sides of the market. It also pins that a stop-out costs exactly the intended risk once fees are counted, that halving the stop distance doubles the position, that widening the stop lowers the ceiling, and that the ceiling approaches one divided by the maintenance rate as the stop tightens.

You can run it yourself: verification/position_size.py.

Open method: the formulas are shown above, the checks are public, and the full source is on GitHub — verify it at github.com/yjquant/calc-tools. Corrections welcome via hello@quantcalcs.com.