Skip to main content

Weight-based backtesting engine for quantitative trading

Project description

wbt

Position-weighted backtesting engine for quantitative strategies, with a Rust core and Python bindings.

中文说明

Why This Project Exists

Many strategy teams use position weights as the canonical interface between signal generation and execution simulation. Existing backtesting tools often focus on order-level simulation or are too slow for large, multi-symbol weight datasets.

The goals of wbt are:

  1. Keep one consistent data contract for weight-based strategies.
  2. Provide fast and deterministic computation with Rust.
  3. Expose a Python-first API for research workflows.
  4. Offer built-in evaluation outputs and plotting-ready data structures.

What wbt Is Good At

  • Time-series and cross-sectional weight backtests.
  • Multi-symbol daily performance attribution.
  • Long/short decomposition and segment-level metrics.
  • High-throughput computation from pandas, polars, or file inputs.

What wbt Is Not Trying To Solve

  • Tick-level order book simulation.
  • Exchange matching-engine microstructure.
  • Broker-specific execution modeling.

If your strategy logic is naturally represented as target weights over time, wbt is a strong fit.

Repository Layout

  • Rust crate: repository root
  • Python package: python/
wbt/
|-- Cargo.toml
|-- src/
`-- python/
    |-- pyproject.toml
    |-- README.md
    |-- tests/
    `-- wbt/

Quick Start (Python Users)

The Python package is in python/ and keeps the import path as import wbt.

cd python
uv sync --extra dev
uv run maturin develop --release
uv run pytest -v

Then in Python:

import pandas as pd
from wbt import WeightBacktest

df = pd.DataFrame(
    {
        "dt": ["2024-01-02 09:01:00", "2024-01-02 09:02:00", "2024-01-02 09:03:00"],
        "symbol": ["AAPL", "AAPL", "AAPL"],
        "weight": [0.5, 0.0, -0.3],
        "price": [185.0, 186.0, 184.5],
    }
)

wb = WeightBacktest(df, digits=2, fee_rate=0.0002, n_jobs=4, weight_type="ts")

print(wb.stats)
print(wb.long_stats)
print(wb.short_stats)

For complete Python guide, see python/README.md.

Quick Start (Rust Developers)

Run tests from repository root:

cargo test

Use as dependency:

[dependencies]
wbt = "0.1"

Data Contract (Core Idea)

wbt expects four essential columns:

  • dt: bar end timestamp
  • symbol: instrument identifier
  • weight: target position weight at bar end
  • price: trade/mark price

Accepted Python inputs:

  • pandas.DataFrame
  • polars.DataFrame or polars.LazyFrame
  • file path (csv, parquet, feather, arrow)

Outputs You Can Use Immediately

  • wb.stats: full long-short evaluation summary.
  • wb.long_stats and wb.short_stats: directional breakdown.
  • wb.daily_return and wb.dailys: daily series for analytics.
  • wb.alpha and wb.alpha_stats: strategy-vs-benchmark excess analysis.
  • wb.pairs: trade-pair table for per-trade evaluation.
  • wb.segment_stats(...): metrics for arbitrary date windows.
  • wb.long_alpha_stats: volatility-scaled long-side alpha metrics.

Plotting

Plot functions are available under wbt.plotting in the Python package, including:

  • cumulative return curves
  • monthly heatmap
  • drawdown chart
  • daily return distribution
  • trade-pair analysis
  • integrated overview dashboard

Development Workflow

  • Rust checks run from repository root.
  • Python checks run from python/.
  • CI validates both layers.

Typical local quality checks:

# repository root
cargo test

# python subproject
cd python
uv run pytest -v
uv run ruff format --check .
uv run ruff check . --no-fix
uv run basedpyright

Related Docs

  • English Python guide: python/README.md
  • Chinese Python guide: python/README_CN.md
  • Design notes: docs/desgin.md

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wbt-0.1.3.tar.gz (286.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

wbt-0.1.3-cp312-cp312-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.12Windows x86-64

wbt-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (9.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

wbt-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file wbt-0.1.3.tar.gz.

File metadata

  • Download URL: wbt-0.1.3.tar.gz
  • Upload date:
  • Size: 286.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wbt-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cd92975863ff891e146bed0f633c6a268b884b51d826dfbfeae0d46ddf7de5de
MD5 080460f5e8ac9d7b9256718b2b5ccfa4
BLAKE2b-256 a3ab5ca2b65e2565ecdad07e7e991909e285f9626597acfaa60ee86f27ccc799

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.3.tar.gz:

Publisher: release.yml on zengbin93/wbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wbt-0.1.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: wbt-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 11.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wbt-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8098d2441103437da0b6405fc91a6044c5828d8ca36cd12ae424d31b50c02652
MD5 ac7dfffb42b3d4c5a2341e4060ccf825
BLAKE2b-256 0bdcd0a1d6d9ca2355da7fe7d80cde5e4178fcf3a2a0fbd03e4babbfba97593e

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.3-cp312-cp312-win_amd64.whl:

Publisher: release.yml on zengbin93/wbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wbt-0.1.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: wbt-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wbt-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8bb59c5b4ffe3b40a07847c22983701f0bef93e13bbf3e07b149d410adee158
MD5 896a7971e0c5b2174c9ce91f5c900d62
BLAKE2b-256 52b6795544bde248444b0a6de71d538f0086f1bf705e82109760b705ca5fc037

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on zengbin93/wbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wbt-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for wbt-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff04f8a38e36363a90b836210d520891ad31a4ac21bc885ef1513efcca7e3157
MD5 7cecd34ad035976440c1e12edd2401e4
BLAKE2b-256 28aeaedc5e80a9f6547f55988b01afd9152f7df30498e4a040a7673caca141d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on zengbin93/wbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page