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.3.tar.gz (15.8 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.3-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.3.tar.gz
  • Upload date:
  • Size: 15.8 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.3.tar.gz
Algorithm Hash digest
SHA256 8ee6ce8c114cdac10f0cdc27ffffa7ef419e55039f1ff53d3fee518e1f9a3f2a
MD5 b8240b49fe30efd826c9dc4bbcfd538d
BLAKE2b-256 d45a788e288732c46d7b54671ea7bf77b1ef88e93185fce37387981b57c4d06d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0aeb490be367aed597d4576645207585b8bab46b44560d9cdd8f44930896b404
MD5 b729c387ba460ba2b01a2930996d5b3e
BLAKE2b-256 19116fe8fe9ab093e5b0b472f3506f8e1f1ef52bd0e1ac945f8cf7ac49bb7938

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