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.4.tar.gz (336.3 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.4-cp312-cp312-win_amd64.whl (11.5 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

wbt-0.1.4-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.4.tar.gz.

File metadata

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

File hashes

Hashes for wbt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4f3d3dea96fde0c8d4244f3e24c6204cec60b042a79173222a7420795530a87f
MD5 a4b6bfdd548a5d534ea5b6ca55fea5f3
BLAKE2b-256 7481b72127c3675d3222da610feecce1c0a79371117c5f2f806685f610084ecc

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.4.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.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: wbt-0.1.4-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.12

File hashes

Hashes for wbt-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d84b465c44d7222eb999900299bb6469ac129b955f6acf6bbff25cb6254446bd
MD5 db60a4f40cb4171fd33dd955dc0d5312
BLAKE2b-256 38be23cddf715d0facc567ab2ac760f99d1157a9398656c947ffb5cfd32802f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.4-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.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: wbt-0.1.4-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.12

File hashes

Hashes for wbt-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e331079d70a6d9be916fcb4f1e629ad621f34390cf79ee67e8ff01af1bcbd79d
MD5 360fdc3ae8b60136e50cc92f7881104f
BLAKE2b-256 2adc61648e57c1345c188f60f5a64fee91e1de6c588968236788f70b6751acff

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.4-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.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for wbt-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a55a5484ada90f0f1427c3ed8702c4706f6fea7d8100f45ed5fae385c73468a
MD5 00c3af551e6d349b73e0ad469da798fe
BLAKE2b-256 af76b57cf7ccc92f0581a8c46af0cc353ea6a53dcb35bef4a162bceb3009f1e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for wbt-0.1.4-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