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.1.tar.gz (15.3 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.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.1.tar.gz
  • Upload date:
  • Size: 15.3 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.1.tar.gz
Algorithm Hash digest
SHA256 8a81bdd1e8fc8bbcc06411f362dbb6aaaa905a63a66857b7da2f24bf720701a9
MD5 675b2c99ee059fef011998851261271f
BLAKE2b-256 47f450e60bebb2fa77e25d61191f7263eae63fc2d535cebbed46d8ee36f8526d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b29b0fd347b3a17f10e730edfa50fd4e2a1dd96a3bc0a8f9c751dace5549c81
MD5 b28285816095f298d23eeb1515471d61
BLAKE2b-256 545df507d7af74d5ec52c526fad37f28b5f231e4a4ae7c9add8eca80164faf52

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