Skip to main content

Backtesting and factor evaluation for the BagelQuant ecosystem

Project description

bagelquant-bt

bagelquant-bt provides backtesting, factor evaluation, performance metrics, and Plotly visualization for long-form Polars panels.

The public input shape is always explicit:

  • prices: time, asset_id, price
  • weights: time, asset_id, weight
  • factors: time, asset_id, factor

Weights at time=t earn each asset's close-to-close return from t to the next available observation.

import polars as pl

from bagelquant_bt import BacktestConfig, run_backtest

prices = pl.DataFrame(
    {
        "time": ["2024-01-02", "2024-01-03"],
        "asset_id": ["AAA", "AAA"],
        "price": [100.0, 102.0],
    }
)
weights = pl.DataFrame(
    {"time": ["2024-01-02"], "asset_id": ["AAA"], "weight": [1.0]}
)

result = run_backtest(
    weights,
    prices,
    kind="weights",
    config=BacktestConfig(initial_capital=1_000_000),
)

print(result.returns)
print(result.summary)

Factor evaluation computes daily cross-sectional IC, quantile returns, a top-minus-bottom spread, and a TOP N equal-weight backtest.

Visualization helpers return Plotly figures:

from bagelquant_bt.visualization import plot_cumulative_returns

fig = plot_cumulative_returns(result)
fig.write_html("cumulative_returns.html")

Development

uv run ruff check .
uv run pytest

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

bagelquant_bt-0.1.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

bagelquant_bt-0.1.2-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bagelquant_bt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4c33e9d74d1d2d2a8f9bd949819c52f6eb794f7655ca9a1955b706dbfd9a20ff
MD5 b964e51e87221fb35986f9e99b41bd63
BLAKE2b-256 1f03c51b98879485d96afde5d06602c0b9d084a623785f55e670e7396990b9e6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bagelquant_bt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f17704b99909727469f60253df1d4f4a392ff6dabda89a935e4e20e02f7b399
MD5 2d55c1da40445d7a766ccae637da507a
BLAKE2b-256 5dd5afa6d41b1bb1d685812e80c38dda53bc9d40a631b1165cc4ceadbf27152b

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