Skip to main content

Add your description here

Project description

BTUtils

Python Version License: MIT

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 series
  • Stats: For calculating performance metrics
  • Plots: For visualizing performance

Requirements

  • Python 3.13+
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

btutils-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

btutils-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file btutils-0.1.0.tar.gz.

File metadata

  • Download URL: btutils-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for btutils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b1706c7f66033286e47f77e410f84a1bef9345ddd32000d0f992bdc88e9a3f6e
MD5 6810f5f01e0e933b1e3cb5af233cb95a
BLAKE2b-256 68457d23889ca97a6593e7c393a2b473612f49711c1a82a1a1d052f9cd5d3c4d

See more details on using hashes here.

File details

Details for the file btutils-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: btutils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for btutils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd4a6866f80c07f9533dff8edf648c4250c09160f069e5358a4e361442e0b049
MD5 11b080feb618ea7dfc724ff9759c977a
BLAKE2b-256 2079cdc320f9ef3ad60c66f5cd1372e82589e95569588e07f867edcee542c497

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