2026-03-17 16:35:09 +01:00
|
|
|
<p align="center">
|
|
|
|
|
<strong>ManifoldBT</strong><br>
|
|
|
|
|
Rust-powered backtesting engine for quantitative research
|
|
|
|
|
</p>
|
2026-03-17 16:13:34 +01:00
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
<p align="center">
|
2026-03-19 00:34:28 +01:00
|
|
|
<a href="https://www.manifoldbt.com">Website</a> ·
|
|
|
|
|
<a href="https://www.manifoldbt.com/docs/documentation.html">Documentation</a> ·
|
2026-03-17 16:35:09 +01:00
|
|
|
<a href="examples/">Examples</a>
|
|
|
|
|
</p>
|
2026-03-17 16:13:34 +01:00
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
---
|
2026-03-17 16:13:34 +01:00
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
ManifoldBT compiles Python strategy definitions into an optimized Rust expression graph.
|
|
|
|
|
Write strategies in a fluent Python DSL — execute them on a vectorized Rust engine.
|
2026-03-17 16:13:34 +01:00
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
## Why ManifoldBT
|
|
|
|
|
|
|
|
|
|
- **Fast** — 500K bars in ~26ms. 161x faster than vectorbt, 1000x+ faster than backtrader.
|
|
|
|
|
- **Expressive** — fluent DSL with 30+ indicators, conditional logic, cross-asset references
|
|
|
|
|
- **Rigorous** — Monte Carlo, walk-forward, parameter sweeps, lookahead detection, exposure diagnostics
|
|
|
|
|
- **Portable** — `pip install`, no Rust toolchain needed. Works on Python 3.9+.
|
2026-03-17 16:13:34 +01:00
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pip install manifoldbt
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
With all extras (plotting, pandas, polars):
|
2026-03-17 16:13:34 +01:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pip install manifoldbt[all]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Quick Start
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import manifoldbt as mbt
|
|
|
|
|
from manifoldbt.indicators import close, ema
|
|
|
|
|
from manifoldbt.helpers import time_range, Interval, Slippage
|
|
|
|
|
|
|
|
|
|
fast = ema(close, 12)
|
|
|
|
|
slow = ema(close, 26)
|
|
|
|
|
|
|
|
|
|
strategy = (
|
|
|
|
|
mbt.Strategy.create("ema_crossover")
|
|
|
|
|
.signal("fast", fast)
|
|
|
|
|
.signal("slow", slow)
|
|
|
|
|
.signal("signal", mbt.when(fast > slow, mbt.lit(1.0), mbt.lit(-1.0)))
|
|
|
|
|
.size(mbt.col("signal") * mbt.lit(0.25))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
start, end = time_range("2022-01-01", "2025-01-01")
|
2026-03-17 16:35:09 +01:00
|
|
|
|
2026-03-17 16:13:34 +01:00
|
|
|
config = mbt.BacktestConfig(
|
|
|
|
|
universe=[1],
|
|
|
|
|
time_range_start=start,
|
|
|
|
|
time_range_end=end,
|
|
|
|
|
bar_interval=Interval.hours(12),
|
|
|
|
|
initial_capital=10_000,
|
|
|
|
|
execution=mbt.ExecutionConfig(allow_short=True, max_position_pct=0.5),
|
|
|
|
|
fees=mbt.FeeConfig.binance_perps(),
|
|
|
|
|
slippage=Slippage.fixed_bps(2),
|
|
|
|
|
warmup_bars=30,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
store = mbt.DataStore(data_root="data", metadata_db="metadata/metadata.sqlite")
|
|
|
|
|
result = mbt.run(strategy, config, store)
|
|
|
|
|
print(result.summary())
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
| # | Example | What it shows |
|
|
|
|
|
|---|---------|---------------|
|
2026-03-17 16:13:34 +01:00
|
|
|
| 00 | [Template](examples/00_template.py) | Minimal starting point |
|
2026-03-17 16:35:09 +01:00
|
|
|
| 01 | [Trend Following](examples/01_trend_following.py) | EMA crossover, volume filter, stop-loss |
|
2026-03-17 16:13:34 +01:00
|
|
|
| 02 | [Mean Reversion](examples/02_mean_reversion.py) | EMA crossover with parameter sweep |
|
2026-03-17 16:35:09 +01:00
|
|
|
| 03 | [Multi-Asset Momentum](examples/03_multi_asset_momentum.py) | Cross-asset signals |
|
2026-03-17 16:13:34 +01:00
|
|
|
| 04 | [Linear Regression](examples/04_linear_regression.py) | Regression-based signal |
|
2026-03-17 16:35:09 +01:00
|
|
|
| 05 | [Statistical Arbitrage](examples/05_stat_arb.py) | Pairs trading, spread z-score |
|
|
|
|
|
| 06 | [Full Visualization](examples/06_full_visualization.py) | Tearsheet and charts |
|
2026-03-17 16:13:34 +01:00
|
|
|
| 07 | [Walk-Forward](examples/07_walk_forward.py) | Out-of-sample validation |
|
2026-03-17 16:35:09 +01:00
|
|
|
| 08 | [2D Sweep](examples/08_sweep_2d_heatmap.py) | Parameter grid heatmap |
|
|
|
|
|
| 09 | [3D Surface](examples/09_surface_3d.py) | Parameter surface plot |
|
2026-03-17 16:13:34 +01:00
|
|
|
| 10 | [Monte Carlo](examples/10_monte_carlo.py) | Permutation-based robustness |
|
|
|
|
|
| 11 | [Portfolio](examples/11_portfolio.py) | Multi-strategy portfolio |
|
|
|
|
|
|
|
|
|
|
## Performance
|
|
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
EMA(12/26) + RSI(14) on 500K synthetic 1-min bars (median of 5 runs):
|
2026-03-17 16:13:34 +01:00
|
|
|
|
2026-03-17 16:35:09 +01:00
|
|
|
| Engine | Time | vs ManifoldBT |
|
|
|
|
|
|--------|------|---------------|
|
|
|
|
|
| **ManifoldBT** (Rust) | **26 ms** | 1x |
|
|
|
|
|
| vectorbt (NumPy) | 4,094 ms | 161x slower |
|
|
|
|
|
| backtrader (Python) | — | ~1000x slower |
|
|
|
|
|
|
|
|
|
|
Reproduce: `python benchmarks/bench_vs_competitors.py --rows 500000 --runs 5`
|
|
|
|
|
|
|
|
|
|
## Documentation
|
|
|
|
|
|
|
|
|
|
Full API reference, indicator list, configuration guide, and best practices:
|
|
|
|
|
|
2026-03-19 00:34:28 +01:00
|
|
|
**[www.manifoldbt.com/docs/documentation.html](https://www.manifoldbt.com/docs/documentation.html)**
|
2026-03-17 16:35:09 +01:00
|
|
|
|
|
|
|
|
## Community vs Pro
|
|
|
|
|
|
|
|
|
|
| | Community | Pro |
|
|
|
|
|
|---|---|---|
|
|
|
|
|
| Output resolution | Daily | 1m, 5m, 15m, 1h |
|
|
|
|
|
| Monte Carlo | 1K sims | Unlimited |
|
|
|
|
|
| Walk-Forward | - | Anchored + Rolling |
|
|
|
|
|
| Parameter Stability | - | Yes |
|
2026-03-18 03:43:17 +01:00
|
|
|
| Crypto connectors (Binance, Hyperliquid) | Yes | Yes |
|
|
|
|
|
| Databento & Massive connectors | - | Yes |
|
|
|
|
|
| Safety checks (lookahead, exposure) | - | Yes |
|
|
|
|
|
| Tearsheets & export | - | Yes |
|
2026-03-17 16:13:34 +01:00
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
2026-04-29 03:57:14 +02:00
|
|
|
Apache 2.0 with Commons Clause. The source is available, free to use,
|
|
|
|
|
modify and self-host. Reselling the software or offering it as a paid
|
|
|
|
|
hosted service is not permitted. See [LICENSE](LICENSE) for the full text.
|