Skip to main content

State-of-the-art event-driven backtesting engine for quantitative trading

Project description

ml4t-backtest

Event-driven backtesting engine for ML4T quantitative trading strategies.

Features

  • Event-Driven Architecture: Point-in-time correctness with no look-ahead bias
  • Exit-First Processing: Matches real broker order execution behavior
  • VectorBT Validation: Results validated against VectorBT Pro
  • Account Policies: Cash and margin account support
  • Minimal Core: ~2,800 lines of focused, maintainable code
  • 100k+ events/sec: High-performance event processing

Installation

pip install ml4t-backtest

Quick Start

from ml4t.backtest import Engine, Strategy, BacktestConfig

class SimpleMovingAverage(Strategy):
    def __init__(self, fast=10, slow=30):
        self.fast = fast
        self.slow = slow
        
    def on_bar(self, bar):
        fast_ma = bar.close_ma(self.fast)
        slow_ma = bar.close_ma(self.slow)
        
        if fast_ma > slow_ma and self.position == 0:
            self.buy(size=100)
        elif fast_ma < slow_ma and self.position > 0:
            self.close()

config = BacktestConfig(
    initial_cash=100_000,
    commission=0.001,
)

engine = Engine(data, SimpleMovingAverage(), config)
result = engine.run()

print(f"Total Return: {result.total_return:.2%}")
print(f"Sharpe Ratio: {result.metrics['sharpe']:.2f}")

Documentation

  • AGENT.md: Comprehensive API reference for agents and developers
  • api.yaml: Machine-readable API specification

Part of ML4T

This library is part of the ML4T quantitative trading toolkit:

  • ml4t-data: Market data acquisition and storage
  • ml4t-engineer: Feature engineering and indicators
  • ml4t-diagnostic: Statistical validation and evaluation
  • ml4t-backtest: Event-driven backtesting (this library)
  • ml4t-live: Live trading platform

License

MIT License - see LICENSE for details.

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

ml4t_backtest-0.1.0a5.tar.gz (181.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ml4t_backtest-0.1.0a5-py3-none-any.whl (122.6 kB view details)

Uploaded Python 3

File details

Details for the file ml4t_backtest-0.1.0a5.tar.gz.

File metadata

  • Download URL: ml4t_backtest-0.1.0a5.tar.gz
  • Upload date:
  • Size: 181.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for ml4t_backtest-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 705befd0a6e5569d4a57470957bf89c16b673a79f141dd56a23f29d7570e91ff
MD5 c4ee3e23898b6441b1749b4e2c71d9dd
BLAKE2b-256 3c5419d2d23248e7baaae4bb419a15a219e69a754b2f664d3f7f45f659e81503

See more details on using hashes here.

File details

Details for the file ml4t_backtest-0.1.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for ml4t_backtest-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 caf8305372874b6b47b1f56a2d027d6073de9bed1829e5d668c3faa848a8af65
MD5 bf082dbd130e51c6d416cd79f8ba2d45
BLAKE2b-256 94beb04d51865b426ba2eb0334038d1cd7c659a9e67781bbed2e96034e8efa2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page