update project metadata and documentation for clarity and branding
This commit is contained in:
+7
-2
@@ -2,9 +2,14 @@
|
|||||||
name = "raptorbt"
|
name = "raptorbt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "High-performance Rust backtesting engine for Quant5"
|
description = "High-performance Rust backtesting engine with Python bindings. Drop-in VectorBT replacement with up insanely faster performance at fractional memory footprint."
|
||||||
authors = ["Quant5 team"]
|
authors = ["Alphabench <contact@alphabench.in>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
repository = "https://github.com/alphabench/raptorbt"
|
||||||
|
homepage = "https://github.com/alphabench/raptorbt"
|
||||||
|
readme = "README.md"
|
||||||
|
keywords = ["backtesting", "trading", "quantitative-finance", "rust", "python"]
|
||||||
|
categories = ["finance", "simulation"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "raptorbt"
|
name = "raptorbt"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 Quant5 team
|
Copyright (c) 2024 Alphabench
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,6 +1,50 @@
|
|||||||
# RaptorBT
|
# RaptorBT
|
||||||
|
|
||||||
**RaptorBT** is a high-performance backtesting engine written in Rust with Python bindings via PyO3. It serves as a drop-in replacement for VectorBT, providing significant performance improvements while maintaining full metric parity.
|
[](https://pypi.org/project/raptorbt/)
|
||||||
|
[](https://opensource.org/licenses/MIT)
|
||||||
|
[](https://www.python.org/downloads/)
|
||||||
|
[](https://www.rust-lang.org/)
|
||||||
|
|
||||||
|
**Blazing-fast backtesting for the modern quant.**
|
||||||
|
|
||||||
|
RaptorBT is a high-performance backtesting engine written in Rust with Python bindings via PyO3. It serves as a drop-in replacement for VectorBT — delivering **HFT-grade compute efficiency** with full metric parity.
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<strong>5,800x faster</strong> · <strong>45x smaller</strong> · <strong>100% deterministic</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Quick Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install raptorbt
|
||||||
|
```
|
||||||
|
|
||||||
|
### 30-Second Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
import numpy as np
|
||||||
|
import raptorbt
|
||||||
|
|
||||||
|
# Configure
|
||||||
|
config = raptorbt.PyBacktestConfig(initial_capital=100000, fees=0.001)
|
||||||
|
|
||||||
|
# Run backtest
|
||||||
|
result = raptorbt.run_single_backtest(
|
||||||
|
timestamps=timestamps, open=open, high=high, low=low, close=close,
|
||||||
|
volume=volume, entries=entries, exits=exits,
|
||||||
|
direction=1, weight=1.0, symbol="AAPL", config=config,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Results
|
||||||
|
print(f"Return: {result.metrics.total_return_pct:.2f}%")
|
||||||
|
print(f"Sharpe: {result.metrics.sharpe_ratio:.2f}")
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Developed and maintained by the [Alphabench](https://alphabench.in) team.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
@@ -13,8 +57,7 @@
|
|||||||
- [Metrics](#metrics)
|
- [Metrics](#metrics)
|
||||||
- [Indicators](#indicators)
|
- [Indicators](#indicators)
|
||||||
- [Stop-Loss & Take-Profit](#stop-loss--take-profit)
|
- [Stop-Loss & Take-Profit](#stop-loss--take-profit)
|
||||||
- [Python Integration](#python-integration)
|
- [VectorBT Comparison](#vectorbt-comparison)
|
||||||
- [VectorBT Drop-in Replacement](#vectorbt-drop-in-replacement)
|
|
||||||
- [API Reference](#api-reference)
|
- [API Reference](#api-reference)
|
||||||
- [Building from Source](#building-from-source)
|
- [Building from Source](#building-from-source)
|
||||||
- [Testing](#testing)
|
- [Testing](#testing)
|
||||||
@@ -23,7 +66,7 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
RaptorBT was built to address the performance limitations of VectorBT in production environments:
|
RaptorBT was built to address the performance limitations of VectorBT. Benchmarked by the Alphabench team:
|
||||||
|
|
||||||
| Metric | VectorBT | RaptorBT | Improvement |
|
| Metric | VectorBT | RaptorBT | Improvement |
|
||||||
| ----------------------------- | ------------------- | ------------ | ------------------------- |
|
| ----------------------------- | ------------------- | ------------ | ------------------------- |
|
||||||
@@ -473,93 +516,75 @@ config.set_risk_reward_target(ratio=2.0) # 2:1 risk-reward ratio
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Python Integration
|
## VectorBT Comparison
|
||||||
|
|
||||||
RaptorBT integrates seamlessly with the Quant5 golf runner through `rpbt.py`.
|
RaptorBT is designed as a drop-in replacement for VectorBT. Here's a side-by-side comparison:
|
||||||
|
|
||||||
### Enable RaptorBT
|
### VectorBT (before)
|
||||||
|
|
||||||
```bash
|
|
||||||
export USE_RAPTORBT=1
|
|
||||||
```
|
|
||||||
|
|
||||||
Or in Python:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import os
|
import vectorbt as vbt
|
||||||
os.environ["USE_RAPTORBT"] = "1"
|
import pandas as pd
|
||||||
```
|
|
||||||
|
|
||||||
### Integration Functions
|
# Run backtest
|
||||||
|
pf = vbt.Portfolio.from_signals(
|
||||||
```python
|
close=close_series,
|
||||||
from app.engine.golf.rpbt import (
|
entries=entries,
|
||||||
is_raptorbt_enabled,
|
exits=exits,
|
||||||
RaptorBTConfig,
|
init_cash=100000,
|
||||||
RaptorBTPortfolioWrapper,
|
fees=0.001,
|
||||||
run_single_backtest_raptorbt,
|
|
||||||
run_basket_backtest_raptorbt,
|
|
||||||
run_pairs_backtest_raptorbt,
|
|
||||||
run_options_backtest_raptorbt,
|
|
||||||
run_multi_backtest_raptorbt,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if RaptorBT is enabled
|
# Get metrics
|
||||||
if is_raptorbt_enabled():
|
print(pf.stats()["Total Return [%]"])
|
||||||
print("Using RaptorBT backend")
|
print(pf.stats()["Sharpe Ratio"])
|
||||||
|
print(pf.stats()["Max Drawdown [%]"])
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
### RaptorBT (after)
|
||||||
|
|
||||||
## VectorBT Drop-in Replacement
|
|
||||||
|
|
||||||
RaptorBT provides a `RaptorBTPortfolioWrapper` that mimics the VectorBT Portfolio interface:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from app.engine.golf.rpbt import (
|
import raptorbt
|
||||||
RaptorBTPortfolioWrapper,
|
import numpy as np
|
||||||
run_single_backtest_raptorbt,
|
|
||||||
RaptorBTConfig,
|
# Configure backtest
|
||||||
|
config = raptorbt.PyBacktestConfig(
|
||||||
|
initial_capital=100000,
|
||||||
|
fees=0.001,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Run backtest
|
# Run backtest
|
||||||
result = run_single_backtest_raptorbt(compiled, ohlcv_df, config, symbol)
|
result = raptorbt.run_single_backtest(
|
||||||
|
timestamps=timestamps,
|
||||||
|
open=open_prices, high=high_prices,
|
||||||
|
low=low_prices, close=close_prices,
|
||||||
|
volume=volume,
|
||||||
|
entries=entries, exits=exits,
|
||||||
|
direction=1, weight=1.0,
|
||||||
|
symbol="SYMBOL",
|
||||||
|
config=config,
|
||||||
|
)
|
||||||
|
|
||||||
# Wrap result for VectorBT compatibility
|
# Get metrics
|
||||||
portfolio = RaptorBTPortfolioWrapper(result)
|
print(f"Total Return: {result.metrics.total_return_pct}%")
|
||||||
|
print(f"Sharpe Ratio: {result.metrics.sharpe_ratio}")
|
||||||
# Use like VectorBT Portfolio
|
print(f"Max Drawdown: {result.metrics.max_drawdown_pct}%")
|
||||||
stats = portfolio.stats() # Returns pd.Series with VectorBT-format keys
|
|
||||||
equity = portfolio.value() # Returns equity curve as pd.Series
|
|
||||||
dd = portfolio.drawdown() # Returns drawdown curve as pd.Series
|
|
||||||
trades_df = portfolio.trades() # Returns trades as pd.DataFrame
|
|
||||||
|
|
||||||
# Access properties
|
|
||||||
print(portfolio.total_return) # Total return percentage
|
|
||||||
print(portfolio.sharpe_ratio) # Sharpe ratio
|
|
||||||
print(portfolio.max_drawdown) # Max drawdown percentage
|
|
||||||
print(portfolio.win_rate) # Win rate percentage
|
|
||||||
print(portfolio.profit_factor) # Profit factor
|
|
||||||
print(portfolio.sqn) # System Quality Number
|
|
||||||
print(portfolio.expectancy) # Expected value per trade
|
|
||||||
print(portfolio.omega_ratio) # Omega ratio
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Stats Format
|
### Metric Mapping
|
||||||
|
|
||||||
The `stats()` method returns a pandas Series with VectorBT-compatible keys:
|
| VectorBT Key | RaptorBT Attribute |
|
||||||
|
| ---------------------- | ------------------------------ |
|
||||||
```python
|
| `Total Return [%]` | `metrics.total_return_pct` |
|
||||||
stats = portfolio.stats()
|
| `Sharpe Ratio` | `metrics.sharpe_ratio` |
|
||||||
print(stats["Total Return [%]"])
|
| `Sortino Ratio` | `metrics.sortino_ratio` |
|
||||||
print(stats["Sharpe Ratio"])
|
| `Max Drawdown [%]` | `metrics.max_drawdown_pct` |
|
||||||
print(stats["Max Drawdown [%]"])
|
| `Win Rate [%]` | `metrics.win_rate_pct` |
|
||||||
print(stats["Win Rate [%]"])
|
| `Profit Factor` | `metrics.profit_factor` |
|
||||||
print(stats["Profit Factor"])
|
| `SQN` | `metrics.sqn` |
|
||||||
print(stats["SQN"])
|
| `Omega Ratio` | `metrics.omega_ratio` |
|
||||||
print(stats["Omega Ratio"])
|
| `Total Trades` | `metrics.total_trades` |
|
||||||
# ... and 20+ more metrics
|
| `Expectancy` | `metrics.expectancy` |
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -686,12 +711,6 @@ maturin build --release
|
|||||||
pip install target/wheels/raptorbt-*.whl
|
pip install target/wheels/raptorbt-*.whl
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using the Build Script
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./scripts/build-engine.sh --install
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
@@ -705,9 +724,7 @@ cargo test
|
|||||||
|
|
||||||
### Python Integration Tests
|
### Python Integration Tests
|
||||||
|
|
||||||
```bash
|
```python
|
||||||
# Test basic functionality
|
|
||||||
uv run python -c "
|
|
||||||
import raptorbt
|
import raptorbt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@@ -728,13 +745,11 @@ result = raptorbt.run_single_backtest(
|
|||||||
)
|
)
|
||||||
print(f'Total Return: {result.metrics.total_return_pct:.2f}%')
|
print(f'Total Return: {result.metrics.total_return_pct:.2f}%')
|
||||||
print('RaptorBT is working correctly!')
|
print('RaptorBT is working correctly!')
|
||||||
"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Comparison Test (VectorBT vs RaptorBT)
|
### Comparison Test (VectorBT vs RaptorBT)
|
||||||
|
|
||||||
```bash
|
```python
|
||||||
USE_RAPTORBT=1 uv run python << 'EOF'
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import vectorbt as vbt
|
import vectorbt as vbt
|
||||||
@@ -769,26 +784,25 @@ result = raptorbt.run_single_backtest(
|
|||||||
|
|
||||||
print(f"VectorBT: {pf.stats()['Total Return [%]']:.4f}%")
|
print(f"VectorBT: {pf.stats()['Total Return [%]']:.4f}%")
|
||||||
print(f"RaptorBT: {result.metrics.total_return_pct:.4f}%")
|
print(f"RaptorBT: {result.metrics.total_return_pct:.4f}%")
|
||||||
print(f"Match: {abs(pf.stats()['Total Return [%]'] - result.metrics.total_return_pct) < 0.01}")
|
# Results should match within 0.01%
|
||||||
EOF
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
RaptorBT is proprietary software developed for the Quant5 platform.
|
MIT License - see [LICENSE](LICENSE) for details.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
### v0.1.0 (2024-01)
|
### v0.1.0
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
- 5 strategy types: single, basket, pairs, options, multi
|
- 5 strategy types: single, basket, pairs, options, multi
|
||||||
- 30+ performance metrics
|
- 30+ performance metrics with full VectorBT parity
|
||||||
- 10 technical indicators
|
- 10 technical indicators (SMA, EMA, RSI, MACD, Stochastic, ATR, Bollinger Bands, ADX, VWAP, Supertrend)
|
||||||
- Fixed, ATR, and trailing stops
|
- Stop-loss management: fixed, ATR-based, and trailing stops
|
||||||
- PyO3 Python bindings
|
- Take-profit management: fixed, ATR-based, and risk-reward targets
|
||||||
- VectorBT-compatible wrapper
|
- PyO3 Python bindings for seamless Python integration
|
||||||
|
|||||||
+2
-2
@@ -5,12 +5,12 @@ build-backend = "maturin"
|
|||||||
[project]
|
[project]
|
||||||
name = "raptorbt"
|
name = "raptorbt"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "High-performance Rust backtesting engine with Python bindings"
|
description = "High-performance Rust backtesting engine with Python bindings. Drop-in VectorBT replacement with up insanely faster performance at fractional memory footprint."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
license = {file = "LICENSE"}
|
license = {file = "LICENSE"}
|
||||||
authors = [
|
authors = [
|
||||||
{name = "Quant5 team"}
|
{name = "Alphabench", email = "contact@alphabench.in"}
|
||||||
]
|
]
|
||||||
keywords = [
|
keywords = [
|
||||||
"backtesting",
|
"backtesting",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
RaptorBT - High-performance Rust backtesting engine for Quant5.
|
RaptorBT - High-performance Rust backtesting engine.
|
||||||
|
|
||||||
This module provides Python bindings for the Rust-based backtesting engine,
|
This module provides Python bindings for the Rust-based backtesting engine,
|
||||||
offering significant performance improvements over vectorbt:
|
offering significant performance improvements over vectorbt:
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// Suppress warning from PyO3 macro expansion (fixed in newer PyO3 versions)
|
// Suppress warning from PyO3 macro expansion (fixed in newer PyO3 versions)
|
||||||
#![allow(non_local_definitions)]
|
#![allow(non_local_definitions)]
|
||||||
|
|
||||||
//! RaptorBT - High-performance Rust backtesting engine for Quant5.
|
//! RaptorBT - High-performance Rust backtesting engine.
|
||||||
//!
|
//!
|
||||||
//! This crate provides a complete backtesting solution with:
|
//! This crate provides a complete backtesting solution with:
|
||||||
//! - Technical indicators (SMA, EMA, RSI, MACD, etc.)
|
//! - Technical indicators (SMA, EMA, RSI, MACD, etc.)
|
||||||
|
|||||||
Reference in New Issue
Block a user