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.0.tar.gz (15.6 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.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 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.0.tar.gz
Algorithm Hash digest
SHA256 d6e413085015e68b56bbf77953b30d8c2be653f26ac7c050fec08775c1ec9d1b
MD5 5a2224930cfab8c1c6975c4568973a60
BLAKE2b-256 eeda256fd87eae0bc6eef1ab0725524ea597631bdebbe0422077b453dd753ac2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83e6ca2a0382f6e48439c88d7c0555646a5623704c7d8481c8c48f4aa24f87e6
MD5 7ca5ec709ce7f1b749cb1671fb7fd454
BLAKE2b-256 8b29fea1b6a5570d729e4ba8e225c6e9215d8fc5f5e761ad0f039b93561c99da

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