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.0a4.tar.gz (167.7 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.0a4-py3-none-any.whl (119.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ml4t_backtest-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 dbb85c1fe87ae01b16a4d67ad3c72516c1e3bc1dfdbcb9166bfbc1ed4ed94676
MD5 22eb7f0e8c8300915de845869fba707a
BLAKE2b-256 e4f38cabea300d053e3a3cb4a0336d89f9d084cba569fe9c06e87d3ee4712ac4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ml4t_backtest-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 c7a3f7b74dafca6774800b2b122047a69de838dd7e10d632d333809e07216aeb
MD5 f9f46a601278dcd0b9ed49db8dca38e5
BLAKE2b-256 a32f06d998f37f4d70c2e7acfb7d43a4677e74d36625a9fa2b38882d5e50d6d7

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