RustyBT
Modern Python backtesting engine built on Zipline-Reloaded, enhanced with Decimal precision, Polars data engine, and live trading capabilities
Overview
RustyBT is a next-generation Python-based algorithmic trading framework that extends Zipline-Reloaded with modern enhancements:
- Decimal Precision: Financial-grade arithmetic using Python's
Decimaltype for audit-compliant calculations - Polars Data Engine: 5-10x faster data processing with lazy evaluation and efficient memory usage
- Parquet Storage: Industry-standard columnar format for OHLCV data (50-80% smaller than HDF5)
- Live Trading: Production-ready engine for executing strategies in real-time markets
- Modern Python: Requires Python 3.12+ for structural pattern matching and enhanced type hints
Key Differences from Zipline-Reloaded
| Feature | Zipline-Reloaded | RustyBT |
|---|---|---|
| Numeric Type | float64 |
Decimal (configurable precision) |
| Data Engine | pandas |
polars (pandas compatible) |
| Storage Format | bcolz/HDF5 | Parquet (Arrow-based) |
| Python Version | 3.10+ | 3.12+ |
| Live Trading | No | Yes (multiple brokers) |
| Performance | Baseline | Optimized (Rust modules planned) |
Installation
Prerequisites
- Python 3.12 or higher
- pip (included with Python)
From PyPI (Recommended)
Install the latest stable release from PyPI:
# Install RustyBT
pip install rustybt
# Install with all optional features (recommended for most users)
pip install rustybt[full] # All user-facing features (optimization + benchmarks)
# Or install specific features
pip install rustybt[optimization] # Strategy optimization tools
pip install rustybt[benchmarks] # Performance profiling tools
pip install rustybt[dev] # Development tools (for contributors)
pip install rustybt[test] # Testing tools (for contributors)
Available extras:
full/all- All optional features (optimization + benchmarks) - ~500MBoptimization- Strategy optimization (scikit-learn, genetic algorithms, ray)benchmarks- Performance profiling (pytest-benchmark, memory_profiler, snakeviz)dev- Development tools (jupyter, jupyterlab, ruff, mypy, black, type stubs)test- Testing tools (pytest, hypothesis, coverage)docs- Documentation generation (MkDocs with Material theme)
From Source (Development)
For contributors or those who want the latest development version:
# Clone the repository
git clone https://github.com/jerryinyang/rustybt.git
cd rustybt
# Using uv (recommended for development)
uv sync --extra dev --extra test
# Or using pip
python3.12 -m venv .venv
source .venv/bin/activate # On Unix/macOS
# or .venv\Scripts\activate on Windows
pip install -e ".[dev,test]"
Quick Start
RustyBT maintains backward compatibility with Zipline API:
from rustybt.api import order_target, record, symbol
def initialize(context):
context.i = 0
context.asset = symbol('AAPL')
def handle_data(context, data):
# Skip first 300 days to get full windows
context.i += 1
if context.i < 300:
return
# Compute averages
short_mavg = data.history(context.asset, 'price', bar_count=100, frequency="1d").mean()
long_mavg = data.history(context.asset, 'price', bar_count=300, frequency="1d").mean()
# Trading logic
if short_mavg > long_mavg:
order_target(context.asset, 100)
elif short_mavg < long_mavg:
order_target(context.asset, 0)
# Save values for later inspection
record(AAPL=data.current(context.asset, 'price'),
short_mavg=short_mavg,
long_mavg=long_mavg)
Run the backtest:
# First, ingest sample data (only needed once)
rustybt ingest -b yfinance-profiling
# Run the backtest
rustybt run -f strategy.py -b yfinance-profiling --start 2024-01-01 --end 2025-09-30
Key Features
Decimal Precision (Epic 2)
from decimal import Decimal
from rustybt.finance.decimal import DecimalLedger
# Financial calculations with audit-compliant precision
ledger = DecimalLedger(starting_cash=Decimal("100000.00"))
Modern Data Architecture (Epic 3)
import polars as pl
from rustybt.data.adapters import YFinanceAdapter, CCXTAdapter
# Multiple data sources with intelligent caching
yf_adapter = YFinanceAdapter()
crypto_adapter = CCXTAdapter(exchange_id='binance')
# Fast data processing with Parquet storage
data = pl.read_parquet("ohlcv_data.parquet")
Enhanced Transaction Costs (Epic 4)
from rustybt.finance.slippage import VolumeShareSlippage
from rustybt.finance.commission import TieredCommission
# Realistic transaction cost modeling
slippage = VolumeShareSlippage(volume_limit=0.025)
commission = TieredCommission(tiers=[(0, 0.001), (100000, 0.0005)])
Multi-Strategy Portfolio Management (Epic 4)
from rustybt.portfolio import PortfolioAllocator
from rustybt.portfolio.allocation import RiskParityAllocator
# Manage multiple strategies with intelligent allocation
allocator = PortfolioAllocator(
strategies=[strategy1, strategy2, strategy3],
allocation_algorithm=RiskParityAllocator()
)
Strategy Optimization (Epic 5)
from rustybt.optimization import GridSearchOptimizer, BayesianOptimizer
# Optimize strategy parameters with multiple algorithms
optimizer = BayesianOptimizer(
param_space={'fast_ma': (10, 50), 'slow_ma': (50, 200)},
n_iterations=100
)
results = optimizer.optimize(strategy)
Live Trading (Epic 6)
from rustybt.live import LiveTradingEngine
from rustybt.live.brokers import CCXTBrokerAdapter
# Connect to exchange for live trading with multiple brokers
broker = CCXTBrokerAdapter(
exchange_id='binance',
api_key='YOUR_API_KEY',
api_secret='YOUR_API_SECRET',
testnet=True,
)
engine = LiveTradingEngine(strategy=my_strategy, broker_adapter=broker)
engine.run()
Development
See CONTRIBUTING.md for development setup and contribution guidelines.
Running Tests
# Run full test suite
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=rustybt --cov-report=html
# Run specific test file
pytest tests/finance/test_decimal_ledger.py
Code Quality
# Format code
black rustybt/ tests/
# Lint code
ruff check rustybt/ tests/
# Type check
mypy rustybt/ --strict
Architecture
RustyBT maintains Zipline's proven architecture while adding new capabilities:
rustybt/
├── finance/ # Financial calculations (Decimal-based)
│ └── decimal/ # Decimal arithmetic modules
├── data/ # Data management (Polars-based)
│ ├── polars/ # Polars data layer
│ └── adapters/ # Data source adapters
├── live/ # Live trading engine
│ ├── brokers/ # Broker adapters
│ └── streaming/ # Real-time data feeds
├── assets/ # Asset management (extended for crypto)
├── pipeline/ # Pipeline framework (Polars-compatible)
└── algorithm.py # TradingAlgorithm (extended)
Acknowledgments
RustyBT is built on the shoulders of giants:
- Zipline: Original backtesting library by Quantopian
- Zipline-Reloaded: Maintained fork by Stefan Jansen
- Machine Learning for Algorithmic Trading: Comprehensive guide by Stefan Jansen
We are grateful to the Quantopian team, Stefan Jansen, and the entire open-source algorithmic trading community.
License
RustyBT is licensed under the Apache License, Version 2.0. See LICENSE for details.
This project incorporates code from Zipline and Zipline-Reloaded, both licensed under Apache 2.0.
Known License Limitations
While RustyBT follows an Apache 2.0/MIT-only dependency policy, the following LGPL dependencies currently exist as transitive dependencies:
| Package | License | Type | Source | Status |
|---|---|---|---|---|
frozendict |
LGPL v3 | Production | Via yfinance (Yahoo Finance data) |
Tracked for replacement |
chardet |
LGPL | Development | Via tox (testing tool) |
Tracked for replacement |
Legal Status: LGPL allows use as a dynamically-linked library without GPL license contamination. RustyBT's Apache 2.0 license remains unaffected.
Mitigation Plans:
- frozendict: Evaluating alternative data providers or forking
yfinancewith MIT-licensed replacement - chardet: Considering migration from
toxto modern alternatives (nox,hatch)
For details on dependency security and license compliance, see docs/security-audit.md.
Documentation
- Full Documentation: https://jerryinyang.github.io/rustybt/ (GitHub Pages)
- ReadTheDocs: https://rustybt.readthedocs.io/ (Alternative)
- Architecture Docs: docs/architecture/index.md
- User Guides: docs/guides/
Community
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Roadmap
Completed ✅
- Epic 1: Project setup and architecture foundations
- Epic 2: Decimal precision financial calculations
- Epic 3: Modern data architecture (Polars/Parquet with multiple adapters)
- Epic 4: Enhanced transaction costs and multi-strategy portfolio management
- Epic 5: Strategy optimization framework (Grid, Bayesian, Genetic, Walk-Forward)
- Epic 6: Live trading engine with broker integrations (CCXT, IB, Binance, Bybit, Hyperliquid)
- Epic 8: Analytics and production readiness (reporting, attribution, risk analytics)
In Progress 🚧
- Epic 7: Rust performance optimizations (baseline benchmarks complete)
- Epic X2: Production readiness validation and remediation
Planned 📋
- Epic 9: REST API and WebSocket interface
- v1.0.0: Production-ready stable release
See docs/prd/epic-list.md for detailed epic descriptions and stories.
Note: RustyBT is under active development. APIs may change until version 1.0.0.
Metadata
Release files for rustybt 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rustybt-0.3.3.tar.gz | 22.5 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rustybt-0.3.3-cp312-cp312-macosx_15_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 15.0+ ARM64 | Details |
Total release size: 29.2 MB
Release files / rustybt-0.3.3.tar.gz
| Download URL | rustybt-0.3.3.tar.gz |
|---|---|
| Size | 22.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b8ee4414b6faca61a5a60f28e11070c64e485b446a89ca1972acf8ad1b37886
|
|
BLAKE2b-256 checksum How to use checksums |
f4a11953993f0cb695ec5ebcd1329161e0d85cb8eb93ef77bc45e8b83cd5b9b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Release files / rustybt-0.3.3-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | rustybt-0.3.3-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9db8e265615a09de82790b1c0ede28210f5164b720f9f7f6bd24c2e317ae374a
|
|
BLAKE2b-256 checksum How to use checksums |
bfe1e9585c6e3dbb0e00850e72e0171e930c63f52953c40fccca814bd4916ab2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.9
|
Security for rustybt 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.