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 q1 - qN spread, and a TOP N equal-weight backtest.

Visualization helpers return Plotly figures:

from bagelquant_bt.visualization import plot_coverage, plot_cumulative_returns

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

coverage_fig = plot_coverage(result)
coverage_fig.write_html("coverage.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.5.tar.gz (16.4 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.5-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.5.tar.gz
  • Upload date:
  • Size: 16.4 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.5.tar.gz
Algorithm Hash digest
SHA256 23c65303d5dbc77f0bd8a65d439690e4be893e8dae3e76d66a3cff399a8f5dd8
MD5 db058ff0d6849f7d14929b844a97943f
BLAKE2b-256 f2654a4e7118c65b8b6680a32d4ca9a1044929486ac8e9632723681e8e4fba12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bagelquant_bt-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 22.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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 212e069679ad415f8fe95e9313ecf5cf6d58acacc045cc405a70e63afc09ac2e
MD5 8c3c1df9430f07700c7e0145d20176e0
BLAKE2b-256 b54b1aeb694cd33fada33debbbecad1eaca878fe4fd1076f7bb79824c15bc0b8

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