Skip to main content

A lightweight pandas-based backtesting framework extracted from deribit-arb.

Project description

quantframe

quantframe is a lightweight Python backtesting framework extracted from the deribit-arb backtest engine.

It provides:

  • backtest(weights, prices, config) for DataFrame-based target weights.
  • run_strategy(strategy, prices, config) for event-style strategies, with optional metadata for explicit symbol lifetimes.
  • TWAP and VWAP execution models.
  • gross PnL, fee PnL, optional funding PnL, and common performance metrics.
  • BacktestResult.plot() for quick result inspection.

Install

uv sync

Yahoo Finance downloads are optional:

pip install quantframe-lib[yfinance]

Run Tests

uv run pytest

Minimal Usage

import pandas as pd

from quantframe.backtest import BacktestConfig, backtest

prices = pd.DataFrame(
    {
        "timestamp": pd.date_range("2024-01-01", periods=3, freq="1min", tz="UTC"),
        "symbol": ["ETH-PERPETUAL"] * 3,
        "close": [100.0, 101.0, 102.0],
    }
)
weights = pd.DataFrame(
    {
        "timestamp": [pd.Timestamp("2024-01-01", tz="UTC")],
        "symbol": ["ETH-PERPETUAL"],
        "weight": [1.0],
    }
)

result = backtest(weights, prices, BacktestConfig(exec_horizon=1))
print(result.metrics)

Use compound cumulative returns and CAGR-style APR when needed:

result = backtest(
    weights,
    prices,
    BacktestConfig(exec_horizon=1, return_mode="compound"),
)

Loading Bar Data

from quantframe.data.yfinance import YahooFinanceProvider
from quantframe.data import prices

bars = YahooFinanceProvider().load_bars(
    ["BTC-USD", "GC=F"],
    start="2016-01-01",
    end="2026-04-30",
    interval="1d",
)

aligned = prices.merge(bars, symbols=["BTC-USD", "GC=F"], how="inner")

Custom providers can subclass DataProvider and implement fetch_bars(). Returned bars are validated and normalized before use. Use prices.merge(..., how="outer") when you want to keep the union of trading calendars and handle missing market bars yourself.

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

quantframe_lib-0.1.5.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

quantframe_lib-0.1.5-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file quantframe_lib-0.1.5.tar.gz.

File metadata

  • Download URL: quantframe_lib-0.1.5.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for quantframe_lib-0.1.5.tar.gz
Algorithm Hash digest
SHA256 e15a03c61f199a44f89efb01034bd91c972e3058858ce1c0e6a9790b66c1532b
MD5 7600cde8c98e97f7f3bcb8960b38aa02
BLAKE2b-256 bce7b4ce9835e756447847055c4944e3995211b30a45a8bceb0dcc786a8f743e

See more details on using hashes here.

File details

Details for the file quantframe_lib-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: quantframe_lib-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for quantframe_lib-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 13a8178526e74565870b3c4d199d69c9990a0bfed649c7ddbd2c107bf37eff7a
MD5 c60e4c91223e041d5b107d0f65ed2c02
BLAKE2b-256 dfb115e2289817ccd700eece2a7e78a7b075672c8a496d50f4ace5a656108067

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