A lightweight Python library for backtesting analysis and visualization of trading strategies
Project description
BTUtils
Overview
BTUtils (Backtest Utilities) is a lightweight Python library for backtesting analysis and visualization of trading strategies. Inspired by the excellent QuantStats package, BTUtils provides a simplified and streamlined approach to analyze and visualize trading performance.
Features
-
Calculate key performance metrics:
- Returns (cumulative, annual)
- Risk metrics (volatility, drawdowns, VaR/CVaR)
- Ratios (Sharpe, Sortino)
- Alpha/Beta analysis
- Win rate and payoff statistics
-
Visualize strategy performance:
- Cumulative returns with drawdowns
- Return distribution analysis
- Monthly/yearly heatmaps
- Rolling metrics (volatility, Sharpe, Sortino, etc.)
- Comparative analysis against benchmarks
Installation
pip install btutils
Quick Start
import pandas as pd
import btutils
from btutils import Backtest
# Create a Backtest instance from a pandas Series of returns
returns = pd.Series(...) # Your daily returns data
bt = Backtest(returns, name="My Strategy")
# Display key metrics
print(bt.metrics())
# Compare with a benchmark
benchmark = pd.Series(...) # Benchmark returns
print(bt.metrics(index_list=[benchmark]))
# Visualize performance
bt.plots.line(benchmark=benchmark, show_drawdown=True)
bt.plots.hist()
bt.plots.heatmap(freq="ME") # Monthly heatmap
bt.plots.rolling_sharpe(window=60)
Documentation
The library consists of three main classes:
Backtest: The main class for handling return seriesStats: For calculating performance metricsPlots: For visualizing performance
Requirements
- Python 3.7+
- pandas
- numpy
- matplotlib
- seaborn
- scipy
License
MIT License
Acknowledgements
BTUtils was inspired by QuantStats but with the goal of providing a more streamlined API focused on the most essential backtesting analytics.
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
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 btutils-0.1.2.tar.gz.
File metadata
- Download URL: btutils-0.1.2.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd9a565e16f072ac827842ef186365fe5affe397e4efa70c5edf54db6c5f70c4
|
|
| MD5 |
2b5389bf5bf474dea660f79d0031520d
|
|
| BLAKE2b-256 |
059ec7aaac09827b5a02b35091ce73355a19c21b942b9631ec51a4bf2c9ae710
|
File details
Details for the file btutils-0.1.2-py3-none-any.whl.
File metadata
- Download URL: btutils-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a98e63418b0b6317faa702c72214d70aa70b1037d9dd85e4ce06e159f31b6412
|
|
| MD5 |
4ce563f4879b260ac96262df27d0857f
|
|
| BLAKE2b-256 |
e0119c17b732e28f041487b7424661e9ca6f46168459125d64c121113038b589
|