BagelQuant Core
bagelquant-core is the Polars-native panel and graph layer for BagelQuant.
Panel data is long-form and keyed by time and asset_id. Numeric panels use a
single value column:
import polars as pl
from bagelquant_core import Domain, Panel
from bagelquant_core.composer import div
from bagelquant_core.transformer import rank, zscore
static_domain = Domain(
calendar=["2024-01-02", "2024-01-03"],
universe=["AAA", "BBB"],
)
dynamic_domain = Domain(
calendar=["2024-01-02", "2024-01-03"],
universe=pl.DataFrame(
{
"time": ["2024-01-02", "2024-01-03"],
"asset_id": ["AAA", "BBB"],
"active": [True, True],
}
),
)
domain = static_domain
price = Panel.from_domain(
pl.DataFrame(
{
"time": ["2024-01-02", "2024-01-02"],
"asset_id": ["AAA", "BBB"],
"value": [100.0, 50.0],
}
),
domain,
name="price",
)
book = Panel.from_domain(
pl.DataFrame(
{
"time": ["2024-01-02", "2024-01-02"],
"asset_id": ["AAA", "BBB"],
"value": [40.0, 25.0],
}
),
domain,
name="book",
)
factor = rank(zscore(div(book, price)), name="factor")
factor.compute()
print(factor.output.data)
Graphs also have a JSON-compatible declarative representation. Only registered BagelQuant transformers and composers can be restored, and panel inputs are resolved explicitly by symbolic name:
specification = factor.spec().to_dict()
compiled = Graph.compile(specification)
result = compiled.compute({"price": price, "book": book})
Core 0.2 keeps sparse inputs as Polars LazyFrame plans. Use
panel.collect(dense=False) for sparse output, panel.collect() or
panel.data for a dense domain-aligned result, and pass an
ExecutionRuntime when a compiled graph is rebound repeatedly.
Time-series operations group by asset_id and order by time.
Cross-sectional operations group by time.
Composer operations join inputs on (time, asset_id).
Universes can be static lists/Series or sparse dynamic membership frames with
time, asset_id, and boolean active; missing dynamic rows are inactive and
are not forward-filled.
Development
uv run ruff check .
uv run python -m pytest
Metadata
Release files for bagelquant-core 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bagelquant_core-0.3.0.tar.gz | 82.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bagelquant_core-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 166.0 kB
Release files / bagelquant_core-0.3.0.tar.gz
| Download URL | bagelquant_core-0.3.0.tar.gz |
|---|---|
| Size | 82.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb544dbd4acb7770b941f31aa3a1f4a3925bf831f33bcd13f47893eb4edad46e
|
|
BLAKE2b-256 checksum How to use checksums |
95db771abff2c6ecf03a37846488195b52222a6ac3514c6336c380b1dc8f859d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / bagelquant_core-0.3.0-py3-none-any.whl
| Download URL | bagelquant_core-0.3.0-py3-none-any.whl |
|---|---|
| Size | 84.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
026ceae88f53dd10e74e5f087ad78b65fe3c8b2457d2fd9003f12e298b0c807a
|
|
BLAKE2b-256 checksum How to use checksums |
60c29b218d11ee72675db6f33b972e57794d3f6f4a71d0306395504fd7672275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|