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
Release history Release notifications | RSS feed
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.0a3.tar.gz
(166.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ml4t_backtest-0.1.0a3.tar.gz.
File metadata
- Download URL: ml4t_backtest-0.1.0a3.tar.gz
- Upload date:
- Size: 166.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c8426578024b4f4a96526bf3fc63da1203297833fd6b6adcdcdb5ba4bc263bc
|
|
| MD5 |
0d21f9b6ea06d2506c45328bd37a7eda
|
|
| BLAKE2b-256 |
8e2f7ddb6fa2cbddad9c441b46b51eaf3a7b87256727bfca45c49efc75d255a2
|
File details
Details for the file ml4t_backtest-0.1.0a3-py3-none-any.whl.
File metadata
- Download URL: ml4t_backtest-0.1.0a3-py3-none-any.whl
- Upload date:
- Size: 116.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d9fcb9bbb82c5844f350fd029e959f4eca876e2b33a66392a78696bdef544d
|
|
| MD5 |
0e7223c130d2e46a08685b14097a783f
|
|
| BLAKE2b-256 |
a118fc3bf6f10a226c81a02f205f1fbf04c467169e2efe23c9be93e0c502e6f0
|