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.0a2.tar.gz (165.2 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.0a2-py3-none-any.whl (114.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ml4t_backtest-0.1.0a2.tar.gz
  • Upload date:
  • Size: 165.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ml4t_backtest-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 10015d0d9ca0eb66dbb926bf8e2c7b9a36d47631ca90186fab7ca1955032858b
MD5 caae4cdb4b808a8de6690f4631999505
BLAKE2b-256 261ca904241365180abc86fd187fb9f83e75d6874ca1efff645f16b5407853bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ml4t_backtest-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 e8044b39fcb3907313a8806a455eb3135ce763125c1c99f268754091cea4e960
MD5 ff256c1c6b38df4855b9e335244136b5
BLAKE2b-256 11d6a398a778ece7d87aace76c5d085a76d8cff7c3a7a979485cf83e5747b059

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