Crypto perpetual backtests: funding, margin and liquidation costs
Build a timestamped perpetual funding ledger, keep leverage and notional separate, and audit which costs a spot backtest actually accounts for.
A spot trade’s entry and exit fees answer one question: how far must the price move to cover the fills? A crypto perpetual backtest must also answer what happens while the position stays open. Funding can debit or credit cash at settlement events, margin limits the exposure you can maintain, and liquidation can end a trade before its planned exit.
Start with the spot-fee break-even calculation, then add the contract’s holding-period ledger and risk rules. The funding example below is entirely synthetic. The actual Stratifyre captures show a separate BTC/USDT spot fee audit; they do not demonstrate perpetual funding, margin or liquidation simulation.
Identify the contract before choosing a fee
“BTCUSDT” is insufficient identification. Record the exchange, product category, exact contract, quantity unit, settlement currency and collateral. A spot pair and a perpetual can share a ticker while having different cash flows.
Bybit’s USDT contracts settle P&L in USDT; its inverse contracts use the underlying cryptocurrency for margin and settlement. The same arithmetic cannot be transferred between them without changing units. Bybit contract FAQ.
For a data-backed test, retain the contract metadata with the experiment. Bybit’s instrument endpoint exposes contractType, settleCoin, quantity filters and fundingInterval, expressed in minutes. Its historical funding endpoint returns fundingRateTimestamp in milliseconds, with a product category of linear or inverse. A current interval alone does not establish the schedule throughout an older test window. Instrument metadata, funding history.
Trading fees and funding are separate ledger entries. Keep maker/taker assumptions, fill prices, spread and slippage explicit; the funding rate does not replace them.
Funding belongs to settlement timestamps
Bybit exchanges funding between longs and shorts that hold positions at the funding event: positive rates mean longs pay, negative rates mean longs receive. Intervals vary by pair and can change; eight hours is an example, not a universal constant. Its documentation also warns that openings or closures within five seconds of settlement do not guarantee inclusion. Funding calculation and timing.
For a linear USDT position, the event charge uses quantity multiplied by the mark price at that event, then by the rate. Apply the position’s actual size and direction at each timestamp. A position held for seventeen hours does not automatically owe seventeen hours of prorated funding.
Consider this deliberately invented long-position ledger:
- Open 0.02 BTC at 50,000 USDT/BTC on September 30, 2026, at 23:30 UTC.
- Close the whole position at 50,125 on October 1 at 16:30 UTC.
- Hold all 0.02 BTC through three chosen eight-hour settlement events.
- Use the hypothetical mark prices and rates below, plus a hypothetical 0.05% trading fee on each fill.
- Assume no spread, slippage, borrowing, currency conversion or tax, and no liquidation.
| Synthetic funding event, UTC | Mark, USDT/BTC | Rate | Position value, USDT | Cash change, USDT |
|---|---|---|---|---|
| Oct 1, 00:00 | 50,000 | +0.01% | 1,000 | −0.1000 |
| Oct 1, 08:00 | 50,200 | +0.02% | 1,004 | −0.2008 |
| Oct 1, 16:00 | 50,100 | −0.01% | 1,002 | +0.1002 |
| Total | — | — | — | −0.2006 |
Chosen teaching inputs, not exchange funding history or Stratifyre output. Negative cash changes are payments; positive changes are receipts. Enter 0.01% as decimal 0.0001 in a calculation.
The rates alone add to 0.02%, but multiplying that sum by the entry notional gives 0.2000 USDT, not the ledger’s 0.2006. The changing mark prices explain the difference. Partial closes would also change the event quantities.
Reconcile funding with the trade result
The synthetic price move produces 0.02 × (50,125 − 50,000) = 2.50 USDT. Entry commission is 0.5000, exit commission is 0.50125, and net funding paid is 0.2006.
Let Q be fixed base quantity, P entry price, X exit price, a and b decimal trading-fee rates, and F total funding paid in USDT. Treat funding received as negative F.
Net P&L = Q × (X − P) − Q × P × a − Q × X × b − FBreak-even X = [Q × P × (1 + a) + F] ÷ [Q × (1 − b)]With this fixed funding ledger, break-even is approximately 50,060.06 USDT/BTC, a 0.12012% increase. Without funding it would be approximately 50,050.03. This is conditional on those funding events and position sizes; changing the holding window or price path changes F. It is not a universal target or a forecast.
The calculation assumes the trade survives until its chosen exit. A funding-adjusted profit estimate cannot establish that survival.
Margin is collateral, not another percentage fee
Keep the cost base and return denominator separate. In a simplified teaching allocation, 1,000 USDT of position notional at 10× leverage requires 100 USDT before fee reserves or other margin adjustments. The example’s 1.20185 USDT of trading fees and net funding is 0.120185% of entry notional, but 1.20185% of that 100 USDT allocation.
Do not multiply the funding bill by leverage again when quantity already represents the full position. Leverage affects required collateral and risk; it does not create a second identical position in the ledger.
Initial margin is not consumed like a commission. Track reserved collateral, available cash and unrealized P&L separately. Bybit distinguishes isolated position margin from cross-account margin; borrowing, when it occurs, can also incur interest. Do not assume every perpetual position has a separate spot-margin loan. Bybit contract and margin FAQ.
Funding can affect the risk path too. Bybit says a payment may come from initial margin when available balance is insufficient, moving an isolated position’s liquidation price closer to the mark. Funding deductions.
Liquidation changes the trade, not just its final bill
At Bybit, isolated-margin liquidation uses the mark price, rather than the last traded price displayed on a default candle chart. Maintenance requirements depend on risk tiers, and the liquidation process can include canceling orders or partially closing a position. Current liquidation process.
A backtest therefore needs the relevant mark-price path, account or position margin, applicable tier rules and forced-exit behavior. A closing-price curve cannot prove that a position avoided an earlier breach. Neither can subtracting a flat “liquidation fee” from a trade that the model allowed to remain open.
Keep voluntary stop execution and exchange liquidation separate. Record each trigger price source and the modeled event sequence. If bar data cannot resolve the sequence, disclose that uncertainty instead of assigning the favorable exit.
An actual spot audit shows why configuration is insufficient
Two previously executed Stratifyre demo jobs used CRYPTO:BINANCE:BTCUSDT, January–March 2025 hourly bars, 10,000 initial capital and fixed 0.05 BTC EMA20/EMA50 crossover entries. Both used on-open execution, a persisted pessimistic fill setting and 0.05% crypto slippage. The configured crypto commission differed: zero versus 0.10%.
An authenticated reinspection on October 3, 2026, found both jobs complete with 24 trades, −675.79092625 reported P&L and 9,324.20907375 ending equity. Every returned trade fee was zero in both jobs. That observed discrepancy prevents treating the configured percentage as an applied charge.
Its first completed trade held approximately 0.05 BTC from 94,988.220375 to 94,276.688075. The returned −35.576615 P&L matches quantity times the fill-price change, with returned fee zero. That is a useful reconciliation boundary, not proof that every execution assumption is correct.
The discovery checks for this article established the BTC/USDT spot-style instrument but no usable perpetual contract. We did not execute a native perpetual funding, margin or liquidation comparison. The synthetic ledger above remains separate from these spot records; adding its funding amounts to them would not turn them into derivatives results.
Audit cost completeness before comparing strategies
For one representative perpetual position, retain:
- Exact venue, contract, quantity units, collateral and settlement currency.
- Actual fill prices and trading charges, with maker/taker and slippage assumptions.
- Historical funding timestamps, rates, mark prices and quantity held at each event.
- Funding cash debits or credits, borrowing and conversion charges where applicable.
- Initial/maintenance margin, risk tier, collateral changes and forced-exit events.
- A reconciliation between cash changes, open-position value and reported net results.
An omitted item belongs in the limitations of the result. It should not become an undocumented zero. Use the execution-modeling guide to audit one saved backtest’s fills and charged costs before interpreting its report as a complete perpetual simulation.
Put your strategy rules to the test
Build your strategy, inspect historical trades, and review the assumptions behind your results.
Build and test your strategy

