Single-factor evaluation/testing toolkit (pandas-first).
Project description
bagel-factor
A small, pandas-first toolkit for single-factor evaluation/testing.
Scope (by design)
This package focuses on:
- canonical point-in-time data helpers (
(date, asset)panel) - preprocessing transforms (clip / z-score / rank)
- single-factor evaluation (IC/ICIR, quantile returns, long-short, coverage, turnover)
It intentionally does not implement multi-factor modeling or portfolio backtesting.
Install
Requires Python >=3.12
pip install bagel-factor
Install (dev / from source)
This repo is managed with uv.
uv sync
Quickstart
1) Prepare a canonical panel
Most APIs expect a canonical panel:
pd.DataFrame- indexed by
pd.MultiIndexwith names("date", "asset")
import pandas as pd
from bagelfactor.data import ensure_panel_index
raw = pd.DataFrame(
{
"date": ["2020-01-01", "2020-01-01"],
"asset": ["A", "B"],
"close": [10.0, 20.0],
"alpha": [1.0, 2.0],
}
)
panel = ensure_panel_index(raw)
2) (Optional) preprocess the factor
from bagelfactor.preprocess import Clip, Pipeline, Rank, ZScore
preprocess = Pipeline([
Clip("alpha", lower=0.0, upper=2.0),
ZScore("alpha"),
Rank("alpha"),
])
3) Run single-factor evaluation
horizons supports multiple forward-return windows (tuple of positive integers).
from bagelfactor.single_factor import SingleFactorJob
res = SingleFactorJob.run(
panel,
factor="alpha",
price="close",
horizons=(1, 5, 20),
n_quantiles=5,
preprocess=preprocess,
)
ic_1d = res.ic[1]
qret_5d = res.quantile_returns[5]
long_short_20d = res.long_short[20]
4) Visualize results
from bagelfactor.visualization import plot_result_summary
fig = plot_result_summary(res, horizon=5)
fig.show()
5) Statistical tests
from bagelfactor.stats import ols_alpha_tstat, ttest_1samp
ic_test = ttest_1samp(res.ic[5], popmean=0.0)
ls_alpha = ols_alpha_tstat(res.long_short[5])
print(ic_test)
print(ls_alpha)
Full example with expected outputs: see docs/example.md.
Benchmarks
- IC (information coefficient): vectorized implementation yields ~4-5x speedup on synthetic panels (examples/benchmark_ic.py) with numeric agreement to baseline.
- Coverage: vectorized implementation yields ~20-30x speedup; results are numerically identical to the baseline implementation.
Reproduce: uv run python examples/benchmark_ic.py (benchmarks included in repository).
Documentation
Table of contents
-
Getting started
-
Modules
-
Design docs
License
MIT (see LICENSE).
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 bagel_factor-0.1.3.tar.gz.
File metadata
- Download URL: bagel_factor-0.1.3.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0557cab0a6bc880f60e368d6fba37dbb4b5f8d9c75fb3a435e852f0d0bd36922
|
|
| MD5 |
d6a5819cf1882c3d458f7dbebe8825ad
|
|
| BLAKE2b-256 |
76ef637d8b1b25891a7e662eb36c35bf68891a7d238ce9fe26ab3793b3c73bc3
|
File details
Details for the file bagel_factor-0.1.3-py3-none-any.whl.
File metadata
- Download URL: bagel_factor-0.1.3-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b304165aa2047dad4990be8340da961158db53c23207f72ac2ecec86bbe65ae
|
|
| MD5 |
2120093d01d7150fa6a36b018d3be446
|
|
| BLAKE2b-256 |
e81627fca2bfd8932da51907bc2d9557b0d1b5cd12e88935182a8b4ac8177798
|