Skip to main content

A lightweight Python library for backtesting analysis and visualization of trading strategies

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.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


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.1.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.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: btutils-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 340f66b31b0307c01169f05a8ec2dd57dadea81a22ea3342414f03e602b5c8c2
MD5 4e4065d8f9c11e8c4f6166b9a6c61cf3
BLAKE2b-256 e8ef1e0187b05534f53226a01dbd5ee7fc6afd0ea82d108b101eb70a683ea547

See more details on using hashes here.

File details

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

File metadata

  • Download URL: btutils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 098ff25ee52cef2327fe498bb3d2210625e578b98cc463729de7d46421f3b3e1
MD5 1f1f6566bc67d26ffa7a5a46ce25231e
BLAKE2b-256 2984971c5d67496461d3ca39422d46c9ebbd67057ca3eeedbab02e30d2e868cb

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