Validated research tooling for investment strategies: deflation, overfitting detection, and honest trial counts.
Project description
AlphaEngine
Validated research tooling for investment strategies. Run a parameter search, get back the shape of the result and an honest read on whether it survives the number of things you tried.
pip install alphaengine
from alphaengine import sweep
r = sweep(backtest_fn, {"fast": [5, 10, 20], "slow": [50, 100, 200]}, data=prices)
r.surface() # is the result a broad plateau or a single lucky configuration?
r.verdict() # deflated for the 9 trials that were actually run
r.save() # study.json, on your disk
What it does
Runs your parameter grid. sweep() calls your backtest function once per
combination. It does not backtest anything itself, so the engine you already
trust stays the engine you trust.
Counts the trials for you. The statistics that correct a Sharpe ratio for
multiple testing need to know how many variants were tested. That number is
almost never recorded, because nobody counts what they discarded. Running the
grid makes it len(grid), so it never has to be asked for or asserted.
Shows you the neighbourhood. The output is whether your result sits on a broad plateau or a knife edge, and where the robust region is centred. A single spike surrounded by failures is a result fitted to its own parameters.
Produces a portable study. A JSON artifact holding what was tried, what came back, and a content hash of the data it ran on. Readable in a text editor, diffable, and versioned so it still parses in two years.
What is in it
| Module | Contents |
|---|---|
alphaengine.core |
deflated Sharpe, PSR, PBO via CSCV, CPCV, minimum track record length, performance and risk statistics |
alphaengine.sweep |
the grid runner and the sensitivity surface |
alphaengine.study |
the study artifact and its schema |
Two runtime dependencies, numpy and scipy, both already present in a typical
research environment. import alphaengine makes no network call and needs no
account. Factor decomposition and cointegration testing need statsmodels and
are available as pip install 'alphaengine[factors]'.
Getting a study to somebody else
save() writes to your disk and needs no account. When the work has to reach
the PM who will act on it, report() sends the study — and only the study.
import os
from alphaengine import Study, sweep
os.environ["QUANTOS_API_KEY"] = "ae_live_..." # created in the portal
r = sweep(backtest_fn, grid, data=prices)
r.save() # yours, on your disk, always
Study.from_sweep(r, label="momentum, 9 configs").report()
What crosses is an explicit allowlist: the trial count and how it was obtained, a content hash of the data, the verdict, the shape of the neighbourhood, the performance figures. Your returns, your prices and your parameter grid stay on the machine, and a guard keyed on length rather than field name refuses to send anything series-shaped whatever it is called.
Reporting is the only part of this package that touches a network, so it is the
only part that is not imported until you call it. import alphaengine still
makes no network call.
Where this sits in QuantOS
AlphaEngine is the open research layer of the QuantOS platform. It is the piece that runs on your machine, against your data, and it is complete on its own: everything above works offline and forever, at no cost.
The QuantOS platform builds on it. Studies produced here can be persisted to a firm's record, referenced when an idea becomes a position, and assembled into the reports that go to an investment committee or an allocator. The library computes; the platform remembers and reports. The two halves are separated so that the part touching your data has no reason to phone home.
The methods
Everything in core comes from the published literature. Nothing here is a
proprietary formula, which is deliberate: a referee whose reasoning you cannot
inspect is not a referee.
Deflated Sharpe Ratio, Probabilistic Sharpe Ratio, minimum track record length Bailey, D. H., and López de Prado, M. (2012). "The Sharpe Ratio Efficient Frontier." Journal of Risk 15(2), 3 to 44. Bailey, D. H., and López de Prado, M. (2014). "The Deflated Sharpe Ratio: Correcting for Selection Bias, Backtest Overfitting, and Non-Normality." Journal of Portfolio Management 40(5), 94 to 107.
Probability of Backtest Overfitting via CSCV Bailey, D. H., Borwein, J., López de Prado, M., and Zhu, Q. J. (2017). "The Probability of Backtest Overfitting." Journal of Computational Finance 20(4), 39 to 69.
Combinatorial purged cross-validation López de Prado, M. (2018). Advances in Financial Machine Learning. Wiley, chapters 7 and 12.
Multiple testing in asset pricing Harvey, C. R., Liu, Y., and Zhu, H. (2016). "... and the Cross-Section of Expected Returns." Review of Financial Studies 29(1), 5 to 68. Harvey, C. R., and Liu, Y. (2015). "Backtesting." Journal of Portfolio Management 42(1), 13 to 28.
Downside deviation Sortino, F. A., and Price, L. N. (1994). "Performance Measurement in a Downside Risk Framework." Journal of Investing 3(3), 59 to 64.
Factor regression standard errors (in the factors extra)
Newey, W. K., and West, K. D. (1987). "A Simple, Positive Semi-Definite,
Heteroskedasticity and Autocorrelation Consistent Covariance Matrix."
Econometrica 55(3), 703 to 708.
Unit root testing for cointegration (in the factors extra)
Dickey, D. A., and Fuller, W. A. (1979). "Distribution of the Estimators for
Autoregressive Time Series with a Unit Root." Journal of the American
Statistical Association 74(366), 427 to 431.
Reproducibility
The values these functions return are treated as a public contract. A study written today has to reproduce in two years, so a change to a computed value is a breaking change requiring a major version bump even when the signature is unchanged. CI fails if a pinned value moves.
Licence
Apache-2.0. 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 alphaengine-0.1.1.tar.gz.
File metadata
- Download URL: alphaengine-0.1.1.tar.gz
- Upload date:
- Size: 67.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18996e4f6d22d65ad9049aec6e50ba6eaf04b465abc524692cbcb7a3629bb820
|
|
| MD5 |
421f3234e851b3c8341cd8392a819581
|
|
| BLAKE2b-256 |
ccefcd98f6892e990b72591cae47aa942a1122ed740ec61c456735a186c7a30f
|
Provenance
The following attestation bundles were made for alphaengine-0.1.1.tar.gz:
Publisher:
publish.yml on quantOSC/alphaengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphaengine-0.1.1.tar.gz -
Subject digest:
18996e4f6d22d65ad9049aec6e50ba6eaf04b465abc524692cbcb7a3629bb820 - Sigstore transparency entry: 2310189273
- Sigstore integration time:
-
Permalink:
quantOSC/alphaengine@8d8fcbb3ff85b33e84f3db4bb57001a6b2f46581 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/quantOSC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d8fcbb3ff85b33e84f3db4bb57001a6b2f46581 -
Trigger Event:
push
-
Statement type:
File details
Details for the file alphaengine-0.1.1-py3-none-any.whl.
File metadata
- Download URL: alphaengine-0.1.1-py3-none-any.whl
- Upload date:
- Size: 65.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08e5fbe4b98a3f8b051571fc5cf5c779669ab7bc54babc14e2787446a89016bf
|
|
| MD5 |
190214946f0fdf67d423fc5c4afeb47f
|
|
| BLAKE2b-256 |
885aaf2c87d76214844362276676072a532bdc645623e2971bdad6e9f42c4ca6
|
Provenance
The following attestation bundles were made for alphaengine-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on quantOSC/alphaengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphaengine-0.1.1-py3-none-any.whl -
Subject digest:
08e5fbe4b98a3f8b051571fc5cf5c779669ab7bc54babc14e2787446a89016bf - Sigstore transparency entry: 2310189303
- Sigstore integration time:
-
Permalink:
quantOSC/alphaengine@8d8fcbb3ff85b33e84f3db4bb57001a6b2f46581 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/quantOSC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d8fcbb3ff85b33e84f3db4bb57001a6b2f46581 -
Trigger Event:
push
-
Statement type: