The Problem with Most Backtests
Most backtesting frameworks produce results that don’t match reality. The reasons are structural:
ClyptQ addresses all five problems through its tick-by-tick state machine architecture.
How ClyptQ Backtesting Works
Every backtest tick follows the same pipeline as live trading:Five Layers of Accuracy
1. Structural Lookahead Prevention
Operators see only past data throughRollingBuffer — a pre-allocated circular buffer that physically cannot contain future data.
Lookahead Bias Prevention
How RollingBuffer, warmup calculation, and Input declarations make lookahead bias structurally impossible
2. Exchange-Specific Cost Models
Fees are auto-fetched from each exchange via CCXT. Maker/taker splits, VIP tier overrides, and slippage modeling are all configurable per venue:Deep Dive: Cost Models
CostModelSpec, VenueFeeResolver, CCXT auto-fetch, and slippage modeling
3. Funding Rate Simulation
Perpetual futures funding rates are applied at 8-hour intervals (00:00, 08:00, 16:00 UTC), matching real exchange settlement cycles. Funding data is auto-injected — if you have a futures account, ClyptQ automatically fetches historical funding rates:Deep Dive: Funding Rates
How ClyptQ simulates 8-hour funding settlement and its impact on P&L
4. Margin-Based Liquidation
Leveraged positions are liquidated when margin ratios breach exchange-specific thresholds. Each exchange has different maintenance margin rates (MMR), liquidation fees, and margin ratio formulas:Deep Dive: Liquidation Logic
Exchange-specific margin calculations, cross vs isolated mode, and simulation method
5. Order Validation
Every order is validated against exchange-specific limits before execution:- Minimum order amount (e.g., 0.001 BTC on Binance)
- Minimum order value (e.g., $10 notional on Gateio)
- Quantity precision (rounded to exchange lot size)
- Margin availability (checked before futures orders)
- Reduce-only constraints (can’t increase position with reduce_only=True)
Execution Modes
BacktestFactory supports two simulation modes:INSTANT Mode (Default)
Orders fill immediately at the current market price (with slippage and fees applied). Simple, fast, suitable for most strategies:LATENT Mode
Orders enter a queue and fill against an orderbook simulator on subsequent ticks. Models realistic fill dynamics:- Partial fills based on available liquidity
- Price impact from walking the orderbook
- Maker/taker determination based on limit price vs best bid/ask
TP/SL (Take Profit / Stop Loss)
Conditional orders are registered after trade execution and checked every tick using OHLC data:- Long positions: TP triggers at candle high, SL triggers at candle low
- Short positions: TP triggers at candle low, SL triggers at candle high
- Both triggered in same candle: Conservative assumption — SL executes first
- Paired positions (arbitrage): When one leg’s TP/SL triggers, the paired leg closes automatically
What This Means in Practice
ClyptQ’s five layers of accuracy — structural lookahead prevention, exchange-specific cost models, funding rate simulation, margin-based liquidation, and order validation — work together to produce backtest results that closely reflect real trading conditions.Helper: Exchange Discovery
Before configuring a backtest, use theHelper class to discover available exchanges, symbols, data, and margin parameters:
Helper is a read-only discovery API — it doesn’t modify anything. Use it to explore what’s available before writing your TradingSpec.
Deep Dives
Lookahead Bias Prevention
How ClyptQ makes it structurally impossible to use future data
Cost Models
Exchange-specific fees, slippage, and CCXT auto-fetch
Funding Rate Simulation
8-hour settlement cycles and their P&L impact
Liquidation Logic
Exchange-specific margin calculations and liquidation simulation
Exchange Specifics
Per-exchange parameters: fees, limits, leverage, and market types

