Skip to content

Welcome to RustyBT

Modern Python backtesting engine built on Zipline-Reloaded, enhanced with Decimal precision, Polars data engine, and live trading capabilities

PyPI version Python License CI codecov

What is RustyBT?

RustyBT is a next-generation algorithmic trading framework that extends Zipline-Reloaded with modern enhancements for professional traders and quantitative researchers.

Key Features

✨ Decimal Precision - Financial-grade arithmetic using Python's Decimal type 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 (50-80% smaller than HDF5)

📊 Multi-Strategy Portfolio - Advanced capital allocation and risk management across multiple strategies

🔧 Strategy Optimization - Grid search, Bayesian optimization, genetic algorithms, and walk-forward analysis

🔴 Live Trading - Production-ready engine for executing strategies in real-time markets (CCXT, Interactive Brokers, Binance, Bybit, Hyperliquid)

🐍 Modern Python - Requires Python 3.12+ for structural pattern matching and enhanced type hints

Quick Start

Installation

# Install from PyPI (recommended)
pip install rustybt

# Or with optional features
pip install rustybt[optimization]

Full installation instructions →

Your First Backtest

Step 1: Create a strategy file strategy.py:

from rustybt.api import order_target, record, symbol

def initialize(context):
    context.asset = symbol('AAPL')

def handle_data(context, data):
    # Simple moving average crossover
    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()

    if short_mavg > long_mavg:
        order_target(context.asset, 100)
    elif short_mavg < long_mavg:
        order_target(context.asset, 0)

Step 2: Ingest sample data (first time only):

rustybt ingest -b yfinance-profiling

This downloads free sample data from Yahoo Finance (20 top US stocks, 2 years of history). No API key required!

Step 3: Run the backtest:

rustybt run -f strategy.py -b yfinance-profiling --start 2020-01-01 --end 2023-12-31

Troubleshooting

  • "no data for bundle": Run rustybt ingest -b yfinance-profiling first
  • "fatal: bad revision 'HEAD'": Reinstall with pip install --upgrade --force-reinstall rustybt
  • Segmentation fault: Check Python version (3.12+ required) and reinstall

Complete quick start guide →

Documentation Navigation

🚀 Getting Started

New to RustyBT? Start here!

📚 User Guides

In-depth guides for specific features:

💡 Examples & Tutorials

Learn by example with 13 Jupyter notebooks and 20+ Python examples:

Interactive Tutorials: - Getting Started, Data Ingestion, Strategy Development - Performance Analysis, Optimization, Walk-Forward Analysis - Risk Analytics, Portfolio Construction, Paper Trading - Full Workflow, Advanced Topics, Crypto & Equity Backtests

Python Examples: - Data ingestion (Yahoo Finance, CCXT, CSV) - Live trading & paper trading - Portfolio allocation & transaction costs - Strategy optimization (Grid, Bayesian, Genetic, Walk-Forward) - Report generation & attribution analysis

Browse all examples →

📖 API Reference

Complete API documentation:

â„šī¸ About

Project information:

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)
Multi-Strategy Limited Advanced portfolio management
Optimization Basic Grid, Bayesian, Genetic, Walk-Forward

Feature Highlights

Decimal Precision

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

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')

Multi-Strategy Portfolio Management

from rustybt.portfolio import PortfolioAllocator
from rustybt.portfolio.allocation import RiskParityAllocation

# Manage multiple strategies with intelligent allocation
allocator = PortfolioAllocator(
    strategies=[strategy1, strategy2, strategy3],
    allocation_algorithm=RiskParityAllocation()
)

Strategy Optimization

from rustybt.optimization import Optimizer, WalkForwardOptimizer

# Optimize strategy parameters
optimizer = Optimizer(
    strategy=my_strategy,
    param_space={'fast_ma': (10, 50), 'slow_ma': (50, 200)}
)
results = optimizer.optimize()

Live Trading

from rustybt.live import LiveTradingEngine
from rustybt.live.brokers import CCXTBrokerAdapter

# Connect to exchange for live trading
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()

Community & Support

Project Status

Completed ✅

  • Epic 1: Project setup and architecture foundations
  • Epic 2: Decimal precision financial calculations
  • Epic 3: Modern data architecture (Polars/Parquet)
  • Epic 4: Enhanced transaction costs and multi-strategy
  • Epic 5: Strategy optimization framework
  • Epic 6: Live trading engine with broker integrations
  • Epic 8: Analytics and production readiness

In Progress 🚧

  • Epic 7: Rust performance optimizations
  • Epic X2: Production readiness validation

Planned 📋

  • Epic 9: REST API and WebSocket interface
  • v1.0.0: Production-ready stable release

Acknowledgments

RustyBT is built on the shoulders of giants:

We are grateful to the Quantopian team, Stefan Jansen, and the entire open-source algorithmic trading community.


Development Status

RustyBT is under active development. APIs may change until version 1.0.0.

Ready to get started? Head to the Installation Guide →