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:
- Keep one consistent data contract for weight-based strategies.
- Provide fast and deterministic computation with Rust.
- Expose a Python-first API for research workflows.
- 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
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wbt-0.1.5.tar.gz.
File metadata
- Download URL: wbt-0.1.5.tar.gz
- Upload date:
- Size: 337.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8961589df2c1782560913212d2ff410d34c84996312cbec9c23c0a9f43bac3cf
|
|
| MD5 |
2f269725b9ceb137e455908a26af3edb
|
|
| BLAKE2b-256 |
af7c7f8ebfa340eb57fd015e941a7cabf4cb041dc707b73d03d5177b1f9f453c
|
Provenance
The following attestation bundles were made for wbt-0.1.5.tar.gz:
Publisher:
release.yml on zengbin93/wbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wbt-0.1.5.tar.gz -
Subject digest:
8961589df2c1782560913212d2ff410d34c84996312cbec9c23c0a9f43bac3cf - Sigstore transparency entry: 1342628282
- Sigstore integration time:
-
Permalink:
zengbin93/wbt@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wbt-0.1.5-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: wbt-0.1.5-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da37beb58d667c46d22e696e540ebb643a78698bb8243494e44f74f7937c9d02
|
|
| MD5 |
9d2bb318b9217cafe5c3596356663713
|
|
| BLAKE2b-256 |
d7c99e30ea2c8ed25dd2f5143c91339e13b7f05604e4150b30c67dbea905fd75
|
Provenance
The following attestation bundles were made for wbt-0.1.5-cp312-cp312-win_amd64.whl:
Publisher:
release.yml on zengbin93/wbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wbt-0.1.5-cp312-cp312-win_amd64.whl -
Subject digest:
da37beb58d667c46d22e696e540ebb643a78698bb8243494e44f74f7937c9d02 - Sigstore transparency entry: 1342628292
- Sigstore integration time:
-
Permalink:
zengbin93/wbt@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wbt-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: wbt-0.1.5-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d5ca7871a376df4b230acca5de0afc127eefaf786e46652b9ddb902abc51507
|
|
| MD5 |
4a1f04dc3737b168601be5221738e4a1
|
|
| BLAKE2b-256 |
bf5ae2d751ab98dc6e85a81349e7c59f06a501e77edccced6686eca6edaaab13
|
Provenance
The following attestation bundles were made for wbt-0.1.5-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
release.yml on zengbin93/wbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wbt-0.1.5-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
3d5ca7871a376df4b230acca5de0afc127eefaf786e46652b9ddb902abc51507 - Sigstore transparency entry: 1342628312
- Sigstore integration time:
-
Permalink:
zengbin93/wbt@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Trigger Event:
push
-
Statement type:
File details
Details for the file wbt-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wbt-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 10.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3881e6cb60cb4a72fd241cf4db0966162d16e192adc251912a4f133fa7727764
|
|
| MD5 |
3fbcf503a617b59ec4ff8c7c2635b8a1
|
|
| BLAKE2b-256 |
df4a106d349eca86fd3f308e3e118c74558f619ac683d5c58c8a465fbaf85f9f
|
Provenance
The following attestation bundles were made for wbt-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on zengbin93/wbt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wbt-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
3881e6cb60cb4a72fd241cf4db0966162d16e192adc251912a4f133fa7727764 - Sigstore transparency entry: 1342628303
- Sigstore integration time:
-
Permalink:
zengbin93/wbt@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/zengbin93
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfb80c9bf13fc12341d541b9b907895f33b93527 -
Trigger Event:
push
-
Statement type: