ManifoldBT

Rust-powered backtesting engine for quantitative research.

ManifoldBT is a high-performance backtesting framework with a Python DSL that compiles strategies into an optimized Rust expression graph. It is designed for speed, correctness, and ergonomics.

Highlights

  • Rust core — vectorized engine handles 1-minute resolution across years of data
  • Python DSL — fluent strategy builder with indicators, signals, and sizing
  • Monte Carlo — permutation-based simulation for robustness testing
  • Walk-Forward — out-of-sample validation with rolling windows
  • Parameter Sweeps — 2D heatmaps and 3D surface plots
  • Portfolio — multi-strategy portfolio with risk rules and rebalancing

Installation

pip install manifoldbt

With plotting support:

pip install manifoldbt[all]

Quick Start

import manifoldbt as mbt
from manifoldbt.indicators import close, ema
from manifoldbt.helpers import time_range, Interval, Slippage

# Define indicators
fast = ema(close, 12)
slow = ema(close, 26)

# Build strategy
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))
)

# Configure backtest
start, end = time_range("2022-01-01", "2025-01-01")
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,
)

# Run
store = mbt.DataStore(data_root="data", metadata_db="metadata/metadata.sqlite")
result = mbt.run(strategy, config, store)
print(result.summary())

Examples

See the examples/ directory for complete runnable strategies:

# Example Description
00 Template Minimal starting point
01 Trend Following EMA crossover with stop-loss and volume filter
02 Mean Reversion EMA crossover with parameter sweep
03 Multi-Asset Momentum Cross-asset momentum signals
04 Linear Regression Regression-based signal
05 Statistical Arbitrage Pairs trading with spread z-score
06 Full Visualization Complete tearsheet and charts
07 Walk-Forward Out-of-sample validation
08 2D Sweep Heatmap Parameter grid search
09 3D Surface 3D parameter surface plot
10 Monte Carlo Permutation-based robustness
11 Portfolio Multi-strategy portfolio

Documentation

Performance

Run the benchmark yourself:

python benchmarks/bench_vs_competitors.py --rows 500000 --runs 5

License

MIT

S
Description
No description provided
Readme Apache-2.0
1.2 MiB
Languages
Python 100%