Polars-native technical features for trading pipelines — pure, point-in-time, online-ready
Project description
sabia
Polars-native technical features for trading pipelines — pure, point-in-time, online-ready.
sabia reads price/volume into features, grounded in the trading & finance literature. It is the
features brick in a layered stack:
marketgoblin (data in) → sabia (features) → quale (signals)
Runtime dependencies are just polars and numpy. (The stack's calendar brick
quando will be wired in when calendar-aware seasonality or
the microstructure tier needs it — v1 seasonality is pure vectorized datetime.) Risk/eval math lives
in ruin; signals live in quale. sabia computes features and nothing else.
What it is
Pure factories over OHLCV bars. A factory binds its params and returns a BoundFeature — an immutable
.spec plus a .expr(schema) -> pl.Expr that resolves column roles (close@tr, high@split)
against a caller-supplied BarSchema. Features are strictly trailing, point-in-time correct, and
deterministic. Batch-first, online-ready: nothing streams in v1, but every feature declares the
history it needs and is covered by a windowed-recompute parity test, so a future online engine is a
thin wrapper rather than a rewrite.
Install
uv sync --extra dev
Quickstart
A complete, copy-paste-runnable example — two symbols, 30 daily bars, three features:
import math
import polars as pl
import sabia
from sabia import BarSchema
def bars(symbol, base):
rets = [0.012 if i % 3 else -0.008 for i in range(30)] # deterministic, varied
close, c = [], base
for r in rets:
c *= math.exp(r); close.append(c)
return pl.DataFrame({
"timestamp": pl.datetime_range(pl.datetime(2024, 1, 1), pl.datetime(2024, 1, 30),
interval="1d", time_zone="UTC", eager=True),
"symbol": [symbol] * 30,
"open": [x * 0.999 for x in close],
"high": [x * 1.004 for x in close],
"low": [x * 0.996 for x in close],
"close": close,
"volume": [1_000_000.0 + 1000 * i for i in range(30)],
})
frame = pl.concat([bars("AAA", 100.0), bars("BBB", 50.0)]).sort("symbol", "timestamp")
# BarSchema maps your physical columns to roles. sabia adjusts nothing — you declare which
# adjustment basis each column carries. .ohlcv(...) is the shorthand for the common OHLCV case;
# for richer inputs (a separate total-return close, VWAP, a market factor) build BarSchema(roles=...).
schema = BarSchema.ohlcv() # open/high/low/close/volume; close also backs close@tr
# Factories return BoundFeature objects; compute resolves their roles and materializes. include_keys
# prepends symbol/timestamp, aligned row-for-row, which is what a downstream pipeline wants.
features = sabia.compute(
frame,
sabia.returns.ret_log(period=1),
sabia.momentum.roc(window=5),
sabia.volatility.vol_cc(window=10),
schema=schema,
include_keys=True,
)
print(features.tail(5))
shape: (5, 5)
┌────────┬─────────────────────────┬───────────┬──────────┬───────────┐
│ symbol ┆ timestamp ┆ ret_log_1 ┆ roc_5 ┆ vol_cc_10 │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ datetime[μs, UTC] ┆ f64 ┆ f64 ┆ f64 │
╞════════╪═════════════════════════╪═══════════╪══════════╪═══════════╡
│ BBB ┆ 2024-01-26 00:00:00 UTC ┆ 0.012 ┆ 0.020201 ┆ 0.009661 │
│ BBB ┆ 2024-01-27 00:00:00 UTC ┆ 0.012 ┆ 0.040811 ┆ 0.009661 │
│ BBB ┆ 2024-01-28 00:00:00 UTC ┆ -0.008 ┆ 0.020201 ┆ 0.010328 │
│ BBB ┆ 2024-01-29 00:00:00 UTC ┆ 0.012 ┆ 0.020201 ┆ 0.009661 │
│ BBB ┆ 2024-01-30 00:00:00 UTC ┆ 0.012 ┆ 0.040811 ┆ 0.009661 │
└────────┴─────────────────────────┴───────────┴──────────┴───────────┘
Each feature emits null during its warm-up window (a rolling stat needs a full window first); use
sabia.drop_warmup(...) to trim those rows. Query the shipped catalog by horizon or data tier:
reg = sabia.Registry.default()
reg.where(lambda s: sabia.Horizon.MEDIUM in s.native_band)
reg.available(sabia.DataTier.DAILY)
Invariants
Causality · point-in-time correctness · purity (no I/O, clocks, randomness) · Polars-native
(no pandas) · determinism within a declared tolerance. All enforced by tests, not convention. See
FEATURES.md for the full spec.
Reproducibility & versioning
sabia pins polars==1.39.3 exactly and targets Python ≥ 3.13 on purpose: the manifest's
feature fingerprint (§3.4) folds in the Polars version, so a stored dataset's exact feature
definitions stay provable across train and serve. These pins are deliberate, not an oversight — they
will relax toward a range once the fingerprint contract is settled past 1.0.
The fingerprint is a best-effort reproducibility hash, not a behavioral guarantee: it hashes each
feature's bound params, roles, dependencies, the Polars version, and the normalized source of its
expression (and first-party helpers). That catches the changes that matter in practice — a retuned
constant, a swapped role, an edited formula — but, being source-based, two mathematically equivalent
rewrites can still produce different fingerprints. Treat a fingerprint change as "prove this was
intended" (the CI manifest gate enforces exactly that), not as a proof of behavioral difference.
FeatureSetManifest serializes (to_json / from_json) so a dataset can carry its definitions.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sabia-0.3.0.tar.gz.
File metadata
- Download URL: sabia-0.3.0.tar.gz
- Upload date:
- Size: 52.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8e543483dfed3862f269f7985077cc87375f8138e3b5f22b2c083034116d48
|
|
| MD5 |
5ca15442c070ee5013bf383bc9626b7a
|
|
| BLAKE2b-256 |
1b40f89ef8a4dcf13a7f4e0d118de8ba853c3f7a0793cf602ef6a1608030c0c5
|
Provenance
The following attestation bundles were made for sabia-0.3.0.tar.gz:
Publisher:
publish.yml on aexsalomao/sabia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sabia-0.3.0.tar.gz -
Subject digest:
3d8e543483dfed3862f269f7985077cc87375f8138e3b5f22b2c083034116d48 - Sigstore transparency entry: 1705218950
- Sigstore integration time:
-
Permalink:
aexsalomao/sabia@9bd244cbead8612bf6c13f8d4c19217f43a1fc3d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/aexsalomao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9bd244cbead8612bf6c13f8d4c19217f43a1fc3d -
Trigger Event:
release
-
Statement type:
File details
Details for the file sabia-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sabia-0.3.0-py3-none-any.whl
- Upload date:
- Size: 67.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c244ed3019906702ffb4dc325c310856048887053e28e5d68154dd948f434011
|
|
| MD5 |
aecdc84b0d88d716485ba2c89803eec8
|
|
| BLAKE2b-256 |
bc92ba64470ca5615ea0daf622a51f24de373b010244e19b91c883046ce34607
|
Provenance
The following attestation bundles were made for sabia-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on aexsalomao/sabia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sabia-0.3.0-py3-none-any.whl -
Subject digest:
c244ed3019906702ffb4dc325c310856048887053e28e5d68154dd948f434011 - Sigstore transparency entry: 1705218991
- Sigstore integration time:
-
Permalink:
aexsalomao/sabia@9bd244cbead8612bf6c13f8d4c19217f43a1fc3d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/aexsalomao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9bd244cbead8612bf6c13f8d4c19217f43a1fc3d -
Trigger Event:
release
-
Statement type: