Skip to main content

A minimal, extensible backtesting toolkit (CAGR, Max Drawdown).

Project description

Mini Backtest

A lightweight, pandas‑first toolkit for quick backtesting experiments. It focuses on the essentials: generating reproducible sample OHLCV data, transforming data into analysis‑friendly shapes, and computing core performance metrics such as CAGR and Maximum Drawdown. The API is intentionally small, composable, and easy to integrate with your own research code.

Features

  • Simple, pandas‑centric API for inputs and outputs.
  • Deterministic sample data generation for demos and tests.
  • Core metrics: CAGR and Maximum Drawdown.
  • Minimal Backtester wrapper that computes metrics from close‑price DataFrames.

Installation

pip install mini_backtest

Quick Start

from mini_backtest import load_sample_prices, Backtester

# Load a reproducible wide close‑price DataFrame (index=date, columns=symbol)
prices = load_sample_prices(n_symbols=10, start="2020-01-01", end="2022-12-31", seed=42)

# Compute per‑symbol metrics
res = Backtester(prices).run()
print(res.head())

API Overview

  • mini_backtest.data

    • load_sample_dataset(n_symbols=10, start="2020-01-01", end="2022-12-31", seed=42) -> pd.DataFrame
      • Returns a reproducible tidy OHLCV DataFrame without writing to disk.
    • load_sample_prices(n_symbols=10, start="2020-01-01", end="2022-12-31", seed=42) -> pd.DataFrame
      • Returns a reproducible wide close-price DataFrame.
    • generate_sample_data(file_path, symbols=None, start="2020-01-01", end="2022-12-31", seed=42) -> Path
      • Writes the simulated dataset to a JSON file for offline use.
    • load_data(file_path) -> pd.DataFrame
      • Loads the JSON dataset into a tidy DataFrame with columns: date, symbol, open, high, low, close, volume.
    • pivot_close(df) -> pd.DataFrame
      • Pivots the tidy data to a wide close‑price DataFrame (index = date, columns = symbols).
  • mini_backtest.metrics

    • compute_cagr(prices, periods_per_year=252) -> pd.Series
    • compute_max_drawdown(prices) -> pd.Series
    • compute_metrics(prices, periods_per_year=252) -> pd.DataFrame
  • mini_backtest.backtester

    • Backtester(prices: pd.DataFrame, periods_per_year: int = 252)
    • Backtester.run() -> pd.DataFrame

Design Notes

  • This project is intentionally minimal and metric‑oriented. It does not attempt to be an event‑driven engine or a full execution simulator.
  • Inputs and outputs are pandas DataFrames to maximize composability with your own research pipeline.

Requirements

  • Python 3.8+
  • pandas>=1.4, numpy>=1.22

Testing (optional)

If you clone the repository and want to run the tests:

pytest -q

Versioning

This package follows semantic versioning for public APIs exposed in mini_backtest.

Security & Privacy

The published distribution includes only the mini_backtest package and this README. It does not ship any credentials, local configuration, or example datasets.

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

mini_backtest-0.1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

mini_backtest-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file mini_backtest-0.1.2.tar.gz.

File metadata

  • Download URL: mini_backtest-0.1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mini_backtest-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5f46e24bce18d7006b898b8f27616b080ddc03057d043968860b12a9da52ea12
MD5 1e9c267948938e81e2c1b4ed5be8ae10
BLAKE2b-256 ba027963f0f9713ef56dbc56b32d6aafd3547673267756dd291b2a4f517f961f

See more details on using hashes here.

File details

Details for the file mini_backtest-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mini_backtest-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mini_backtest-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4fc832fab2b2b95647ab88119449668d62cb4703d41a4773225496f5d9e3b708
MD5 e8c166929f72d8f18fb8fb1926981c96
BLAKE2b-256 eecb74106a0c8e574627fe355aae1f83772f1457d29ed0515219004e0e059f64

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