Skip to main content

What Is Vectorized Backtesting?

Vectorized backtesting processes entire arrays of historical data at once using NumPy/pandas operations. This is how most popular frameworks work:
This feels natural to Python developers. It’s fast. It’s concise. And it produces fundamentally unreliable results.

The Four Structural Flaws

Flaw 1: Lookahead Bias Is One Typo Away

In vectorized code, the entire price history exists as a single array. Accidentally using future data is trivially easy:
In ClyptQ, this is structurally impossible. Each operator receives a RollingBuffer containing only [t-lookback : t]. There is no array of future prices to accidentally reference:

Flaw 2: No Real State Management

Vectorized backtests compute positions as arrays:
This misses critical real-world state:
  • Partial fills: What if your order only partially fills?
  • Margin requirements: Do you have enough margin for this position?
  • Cash constraints: You can’t buy 10,000ofBTCwith10,000 of BTC with 5,000 cash
  • Funding rate costs: Perpetual futures charge funding every 8 hours
  • Liquidation risk: Over-leveraged positions get liquidated
ClyptQ tracks all of this through the STATE protocol:

Flaw 3: Order Execution Is Fantasy

Vectorized backtests assume every order fills instantly at the exact close price:
Real execution involves:
  • Slippage: Large orders move the market
  • Tiered fees: Maker/taker rates differ, VIP levels change fees
  • Minimum order sizes: Exchanges have lot size and notional minimums
  • Rate limits: You can’t send 1,000 orders per second
  • Network latency: Orders arrive milliseconds after you decide
ClyptQ models exchange-specific execution:

Flaw 4: Research Code ≠ Live Code

The most fundamental flaw: vectorized backtest code cannot run live. A pandas DataFrame doesn’t exist in live trading — you have a stream of ticks. So you must rewrite everything:
Two codebases. Two potential sources of bugs. Two systems that can drift apart silently. ClyptQ has one codebase. The same operator code, the same graph, the same execution path — in backtest and live.

Framework-by-Framework Analysis

Freqtrade

What it is: Open-source crypto trading bot with backtesting. Python-based, primarily for single-exchange strategies. Architecture: Hybrid — uses vectorized pandas for some calculations with an event-driven loop on top. Strategies inherit from IStrategy class. Freqtrade’s strengths: Easy to get started for single-pair strategies. Large community. Good documentation. Freqtrade’s limitations: Candle-level granularity means you can’t model intra-candle events. No proper multi-asset portfolio management. No institutional-grade cost modeling. Research code eventually diverges from live.

Zipline / Zipline-Reloaded

What it is: Originally developed by Quantopian (now defunct). The community-maintained fork “Zipline-Reloaded” has limited activity. Zipline’s legacy: Pioneered cloud-hosted quant trading via Quantopian. The architecture was sound for daily equity strategies but never adapted to crypto, futures, or intraday trading.

Backtrader

What it is: Feature-rich Python backtesting library. Event-driven architecture, but with significant complexity. Backtrader’s strength: Flexible and feature-rich. Good for educational purposes. Backtrader’s limitation: Strategies are monolithic classes that mix signal generation, position sizing, and order management. This makes them hard to test, compose, and maintain. The implicit broker state creates the research-live gap.

VectorBT

What it is: High-performance vectorized backtesting using NumPy. Designed for speed — can test millions of parameter combinations. VectorBT’s niche: Fast initial screening of parameter spaces. Useful for exploration, but results need validation in an event-driven framework before trusting them. Important: VectorBT and ClyptQ are not substitutes — they serve different purposes. VectorBT is for rapid exploration. ClyptQ is for validated execution. Some traders use VectorBT for initial screening, then validate promising strategies in ClyptQ.

The Speed vs Accuracy Trade-off

Vectorized frameworks are fast because they skip the hard parts: ClyptQ is slower per backtest because it does all of these. But an accurate slow backtest is worth more than a fast inaccurate one:
The “fast” backtest lost you money. The “slow” backtest made you money.

Migration Path

If you’re currently using a vectorized framework, migrating to ClyptQ means:
  1. Extract your signal logic into ClyptQ operators (most ta-lib indicators have direct equivalents in ClyptQ’s operator library)
  2. Define your data and execution in a TradingSpec
  3. Connect operators in a graph instead of chaining pandas operations
  4. Run the same code live — no production rewrite needed
The ClyptQ version is slightly more verbose, but it runs identically in backtest and live — no rewrite needed.

Summary

Relationship to Other Concepts