Skip to main content

Welcome to HftBacktest

HftBacktest is a high-frequency trading and market-making backtesting framework designed for developing HFT strategies with accurate simulation of market conditions.

Installation

Get started with Python or Rust installation

Quick Start

Run your first backtest in minutes

Examples

Learn market-making strategies and techniques

API Reference

Explore the complete API documentation

Key Features

Accurate Fill Simulation

Simulates order fills accounting for queue position and latencies

Full Order Book Replay

Complete tick-by-tick simulation with Level-2 and Level-3 support

Latency Modeling

Accounts for both feed and order latency using custom models

Multi-Asset Support

Backtest strategies across multiple assets and exchanges

High Performance

Python code runs in Numba JIT, Rust provides native performance

Live Trading

Deploy the same code for live trading (Rust only)

Why Accurate Backtesting Matters

Trading is a highly competitive field where only small edges usually exist, but they can still make a significant difference. Because of this, backtesting must accurately simulate real-world conditions.
Foundation First: Accurate backtesting is the foundation. Without it, all further analysis—whether conservative or aggressive—becomes unreliable.
This framework focuses on:
  • Not overly pessimistic: Avoids hiding small edges and profit opportunities
  • Not overly optimistic: Prevents unrealistic simulation that overstates performance
  • Validation ready: Backtests should closely align with live trading results for the same period
If you run a live trading strategy in January 2025, the backtest for that exact period should produce results that closely align with actual results. This validates your backtesting accuracy before proceeding to optimization.

What You Can Build

Market Making

Build sophisticated market-making strategies with spread management

Grid Trading

Implement high-frequency grid trading with queue positioning

Arbitrage

Develop cross-exchange arbitrage strategies

Statistical Arbitrage

Create multi-asset statistical arbitrage strategies

Alpha Strategies

Integrate alpha signals with market-making

Risk Management

Test risk mitigation in extreme market conditions

Language Support

HftBacktest is available in two implementations:
from hftbacktest import BacktestAsset, HashMapMarketDepthBacktest
from numba import njit

@njit
def strategy(hbt):
    # Your strategy logic here
    pass

Python

  • Version: Python 3.11+
  • Performance: Runs in Numba JIT for near-native speed
  • Use Case: Rapid prototyping, research, and strategy development
  • Ecosystem: Integrates with NumPy, Polars, Matplotlib

Rust

  • Version: Rust 1.91.1+
  • Performance: Native compiled performance
  • Use Case: Production backtesting and live trading deployment
  • Features: Type safety, memory safety, concurrent execution

Getting Started

Ready to start backtesting? Follow these steps:
1

Install HftBacktest

Choose Python or Rust and install the package
2

Prepare Your Data

Get market data in the required format (order book and trades)
3

Write Your Strategy

Implement your trading logic using the framework API
4

Run Backtest

Execute your backtest and analyze the results
5

Optimize & Deploy

Refine your strategy and deploy to live trading (Rust)

Next: Install HftBacktest

Get HftBacktest installed on your system

Build docs developers (and LLMs) love