Skip to content

BobbyAxerol/quantbt

Repository files navigation

QuantBT

Python Numba Backtesting Nautilus

Fast, research-friendly backtesting for crypto and portfolio alphas.

QuantBT gives notebooks and services one stable endpoint over multiple engines: Numba vectorized simulation for sweeps, event-driven order simulation for fills, legacy-compatible portfolio modes, and optional NautilusTrader validation.

Highlights

  • Single-symbol signal backtests with margin, leverage, fees, slippage, funding, and liquidation checks.
  • Structural DCA/grid ladders with high/low limit-touch simulation.
  • Native event-driven orders, fills, baskets, and pair trades.
  • Multi-symbol portfolio modes: longshort, market_neutral, directional, and equal_weight.
  • Optional Nautilus validation for Binance perpetuals: BTC, ETH, BNB, SOL, DOGE, ARB, and LINK.
  • Stable result contract with show_metrics(), full_report(), plots, reports, and export helpers.

Install

pip install numpy pandas numba matplotlib seaborn

Optional Nautilus validation:

poetry add nautilus-trader

Quick Start

from quantbt import QuantBTEndpoint

bt = QuantBTEndpoint.signal_notional(
    backend="native_vectorized",
    initial_capital=20_000,
    leverage=5,
    alloc_per_trade=10_000,
    fee_rate=0.0002,
    slippage_bps=1.0,
    use_funding=False,
)

result = bt.backtest(
    data=df,                    # OHLCV DataFrame
    signal_col="pos_weight",    # 1.0 / -1.0 / 0.0 style signal
    symbols=["ETHUSDT"],
)

result.show_metrics()
bt.quick_plot()

Endpoint Modes

QuantBTEndpoint.pct_equity(...)          # legacy % equity sizing
QuantBTEndpoint.signal_notional(...)     # fixed units between signal changes
QuantBTEndpoint.dca_ladder(...)          # DCA/grid structural levels
QuantBTEndpoint.orders(...)              # explicit OrderIntent simulation
QuantBTEndpoint.basket(...)              # pair/basket event simulation
QuantBTEndpoint.portfolio(...)           # multi-symbol portfolio matrix
QuantBTEndpoint.nautilus_validation(...) # optional Nautilus validation

Nautilus Example

from quantbt import QuantBTEndpoint
from quantbt.adapters.nautilus import NautilusBackendConfig

bt = QuantBTEndpoint.nautilus_validation(
    initial_capital=20_000,
    leverage=5,
    alloc_per_trade=10_000,
    hedge_type="signal_notional",
    use_funding=False,
    nautilus_config=NautilusBackendConfig(timeframe="1h"),
)

result = bt.simulate(
    data=df,
    signal_col="pos_weight",
    symbols=["SOLUSDT-PERP.BINANCE"],
)

result.show_metrics()
fills = bt.fills_report

Nautilus currently validates single-symbol signal sizing modes: signal_notional, notional, unit, and %_equity.

Supported Nautilus validation instruments:

BTCUSDT-PERP.BINANCE, ETHUSDT-PERP.BINANCE, BNBUSDT-PERP.BINANCE, SOLUSDT-PERP.BINANCE, DOGEUSDT-PERP.BINANCE, ARBUSDT-PERP.BINANCE, LINKUSDT-PERP.BINANCE.

Result Helpers

result.show_metrics()
result.full_report()
result.quick_plot()
result.tearsheet()

bt.order_report
bt.fills_report
bt.export_orders("orders.csv")
bt.export_fills("fills.csv")

Documentation

Design Goal

QuantBT is built for the workflow most alpha research needs: fast iteration first, then stricter execution validation where it matters. Use native vectorized mode for broad sweeps, native event mode for order/fill behavior, and Nautilus for small high-fidelity checks.

About

Vectorised backtest SDK with Numba-compiled simulation kernels, nautilus-trader endpoint support validation

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors