BTS: BackTest Strategy
BTS is a Rust library designed for backtesting trading strategies on candlestick data. It enables testing technical indicators, custom strategies, and simulating trading performance on historical or generated data.
🔑 Key Features
- 📊 Technical Indicators: Uses with popular indicators (Impulse MACD, Parabolic SAR, VWAP, etc.) and allows easy addition of new ones.
- 📈 Backtesting: Simulates trading strategies on historical or generated data.
- 🏗️ Market Engine: Processes candles one by one to test strategies under realistic conditions.
- 📉 Performance Metrics: Calculates P&L (Profit & Loss), drawdown, Sharpe ratio, and more.
- 🔧 Flexibility: Compatible with indicators crates for seamless integration.
- 📝 Order & Position Management: Supports market orders, limit orders, take-profit, stop-loss, and trailing stops.
🚀 Usage Example
use Arc;
use *;
use ;
// Candlestick data
let data = vec!;
let candles = from_iter;
// Initialize backtest
let mut bts = new.unwrap;
// Custom strategy
bts.run.unwrap;
// Results
println!;
println!;
println!;
See more examples in examples folder.
📊 Performance Metrics
The backtesting engine automatically calculates the following metrics:
| Metrics | Description |
|---|---|
| Drawdown | Maximum capital decline |
| Profit Factor | Ratio of gross profits to gross losses |
| Sharpe Ratio | Risk-adjusted return measure |
| Win Rate | Percentage of winning trades |
🔗 Integration with Other Crates
BTS is compatible with popular indicators crates for technical analysis, allowing you to easily integrate your trading strategy.
⚡ Advanced Features
- Custom Strategies: Implement your own trading logic.
- Event Tracking: Detailed logging of all trading events.
- Risk Management: Built-in support for stop-loss and take-profit rules.
- Performance Optimization: Uses efficient data structures for order/position management.
- Parameters Optimization: Computes the best parameters (indicators, RR, etc...) for your strategy.
- Draw chart and metrics: Draws the candlesticks data, balance, positions and metrics.
⚠️ Error Handling
BTS provides comprehensive error handling for:
- Insufficient funds
- Invalid orders/positions
- Market data errors
- Configuration issues and more.
📦 Crate Features
The crate includes three main optional features to extend its functionality:
metrics: Exposes the Metrics struct, enabling calculations of key performance indicators such as max drawdown, Sharpe ratio, profit factor, and win rate.optimizer: Provides tools for parameter optimization, allowing you to find the best strategy parameters (e.g., indicator periods, risk-reward ratios) by testing combinations across historical data.draws: Enables integration with the plotters crate to visualize backtest results, including candlestick charts or performance metrics (requires themetricsfeature to be enabled).
🛠️ Getting Started
Add BTS to your Cargo.toml:
[]
= "*"
Then import and use it in your project:
use *;
🤝 Contributing
Contributions are welcome! See Contributing file to contribute to this project.
📄 License
This project is licensed under the MIT License.
Generated by Mistral.ai