alphaengine 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alphaengine-0.1.0/.github/workflows/ci.yml +62 -0
- alphaengine-0.1.0/.github/workflows/publish.yml +54 -0
- alphaengine-0.1.0/.gitignore +14 -0
- alphaengine-0.1.0/CHANGELOG.md +46 -0
- alphaengine-0.1.0/LICENSE +202 -0
- alphaengine-0.1.0/PKG-INFO +157 -0
- alphaengine-0.1.0/README.md +116 -0
- alphaengine-0.1.0/SECURITY.md +39 -0
- alphaengine-0.1.0/pyproject.toml +154 -0
- alphaengine-0.1.0/src/alphaengine/__init__.py +47 -0
- alphaengine-0.1.0/src/alphaengine/_version.py +15 -0
- alphaengine-0.1.0/src/alphaengine/core/__init__.py +63 -0
- alphaengine-0.1.0/src/alphaengine/core/backtest.py +676 -0
- alphaengine-0.1.0/src/alphaengine/core/factors.py +136 -0
- alphaengine-0.1.0/src/alphaengine/core/pairs.py +514 -0
- alphaengine-0.1.0/src/alphaengine/core/performance.py +108 -0
- alphaengine-0.1.0/src/alphaengine/core/risk.py +127 -0
- alphaengine-0.1.0/src/alphaengine/core/technical.py +213 -0
- alphaengine-0.1.0/src/alphaengine/core/validation.py +361 -0
- alphaengine-0.1.0/src/alphaengine/py.typed +0 -0
- alphaengine-0.1.0/src/alphaengine/study/__init__.py +32 -0
- alphaengine-0.1.0/src/alphaengine/study/schema.py +146 -0
- alphaengine-0.1.0/src/alphaengine/sweep/__init__.py +18 -0
- alphaengine-0.1.0/src/alphaengine/sweep/runner.py +321 -0
- alphaengine-0.1.0/tests/test_goldens.py +138 -0
- alphaengine-0.1.0/tests/test_smoke.py +62 -0
- alphaengine-0.1.0/tests/test_sweep.py +184 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
18
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
19
|
+
# The numpy 2.0 ABI break is real and quant environments are split
|
|
20
|
+
# across it for a while yet. Test the floor of what we support on one
|
|
21
|
+
# runner so a 1.x-only user is not our first bug report.
|
|
22
|
+
include:
|
|
23
|
+
- os: ubuntu-latest
|
|
24
|
+
python: "3.10"
|
|
25
|
+
numpy: "numpy<2"
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- uses: actions/setup-python@v5
|
|
29
|
+
with:
|
|
30
|
+
python-version: ${{ matrix.python }}
|
|
31
|
+
- run: python -m pip install --upgrade pip
|
|
32
|
+
- run: pip install -e ".[dev]"
|
|
33
|
+
- if: matrix.numpy
|
|
34
|
+
run: pip install "${{ matrix.numpy }}"
|
|
35
|
+
- run: pytest
|
|
36
|
+
|
|
37
|
+
lint:
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- uses: actions/setup-python@v5
|
|
42
|
+
with:
|
|
43
|
+
python-version: "3.12"
|
|
44
|
+
- run: pip install -e ".[dev]"
|
|
45
|
+
- run: ruff check src tests
|
|
46
|
+
- run: ruff format --check src tests
|
|
47
|
+
- run: mypy src
|
|
48
|
+
|
|
49
|
+
# The numbers this library returns are a public contract once published: a
|
|
50
|
+
# study written today has to reproduce in two years. This job exists to make
|
|
51
|
+
# a silent change to a computed value impossible — if a golden moves, the
|
|
52
|
+
# build fails and the change has to be argued for in the PR and carried by a
|
|
53
|
+
# major version bump.
|
|
54
|
+
goldens:
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v4
|
|
58
|
+
- uses: actions/setup-python@v5
|
|
59
|
+
with:
|
|
60
|
+
python-version: "3.12"
|
|
61
|
+
- run: pip install -e ".[dev]"
|
|
62
|
+
- run: pytest tests -m golden -q
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI on a version tag.
|
|
4
|
+
#
|
|
5
|
+
# TRUSTED PUBLISHING VIA OIDC — there is no API token anywhere in this repo or
|
|
6
|
+
# in its secrets. GitHub mints a short-lived identity token that PyPI verifies
|
|
7
|
+
# against a publisher it has on record for this repo, workflow and environment.
|
|
8
|
+
# A long-lived PyPI token is the standard way a package gets hijacked; this
|
|
9
|
+
# removes the credential rather than protecting it.
|
|
10
|
+
#
|
|
11
|
+
# One-time PyPI setup (do this BEFORE the first tag):
|
|
12
|
+
# PyPI -> the project -> Publishing -> Add a new pending publisher
|
|
13
|
+
# owner: quantOSC
|
|
14
|
+
# repository: alphaengine
|
|
15
|
+
# workflow: publish.yml
|
|
16
|
+
# environment: pypi
|
|
17
|
+
|
|
18
|
+
on:
|
|
19
|
+
push:
|
|
20
|
+
tags: ["v*"]
|
|
21
|
+
workflow_dispatch:
|
|
22
|
+
|
|
23
|
+
permissions:
|
|
24
|
+
contents: read
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
# Build once, publish that exact artifact. Building inside the publish job
|
|
28
|
+
# would make the tested artifact and the shipped artifact different objects.
|
|
29
|
+
build:
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
- uses: actions/setup-python@v5
|
|
34
|
+
with:
|
|
35
|
+
python-version: "3.12"
|
|
36
|
+
- run: python -m pip install --upgrade build
|
|
37
|
+
- run: python -m build
|
|
38
|
+
- uses: actions/upload-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: dist
|
|
41
|
+
path: dist/
|
|
42
|
+
|
|
43
|
+
publish:
|
|
44
|
+
needs: build
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
environment: pypi
|
|
47
|
+
permissions:
|
|
48
|
+
id-token: write # the OIDC token. the only credential involved.
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/download-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist
|
|
53
|
+
path: dist/
|
|
54
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every entry that changes a computed value says so in the first line, because a
|
|
4
|
+
saved study has to reproduce years after it was written. See `_version.py` for
|
|
5
|
+
the versioning rule: while the leading digit is 0, a changed figure costs a
|
|
6
|
+
minor bump.
|
|
7
|
+
|
|
8
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-07-30
|
|
11
|
+
|
|
12
|
+
First public release. No figures changed, because there is nothing yet to
|
|
13
|
+
change them from.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `sweep()`, which runs a parameter grid through the caller's own backtest
|
|
18
|
+
function and derives the trial count from the grid rather than accepting it as
|
|
19
|
+
an argument. The signature has no `n_trials` parameter and a test pins that
|
|
20
|
+
absence, since a supplied count makes the deflation self-reported.
|
|
21
|
+
- `SweepResult.verdict()`, reporting the deflated Sharpe ratio, PSR, minimum
|
|
22
|
+
track record length and a performance summary. Probability of backtest
|
|
23
|
+
overfitting is reported beside them under `selection` and is deliberately not
|
|
24
|
+
the gate: measured on a null-versus-edge fixture it does not discriminate
|
|
25
|
+
where the deflated Sharpe does, so gating on it would reject real results.
|
|
26
|
+
- `SweepResult.surface()`, classifying the parameter neighbourhood as a plateau,
|
|
27
|
+
a ridge or a knife edge, with the robust region per parameter when parameters
|
|
28
|
+
are being stored.
|
|
29
|
+
- The `Study` artifact and its versioned JSON schema. `load()` refuses an
|
|
30
|
+
unknown major version rather than half-parsing it, and tolerates unknown
|
|
31
|
+
fields within a known major so a newer writer stays readable by an older
|
|
32
|
+
build. A study holds derived figures and hashes, never a series.
|
|
33
|
+
- `alphaengine.core`: deflated Sharpe, PSR, PBO by CSCV, minimum track record
|
|
34
|
+
length, a performance report, value at risk and conditional value at risk,
|
|
35
|
+
factor decomposition, cointegration tests and a signal backtest. Each cites
|
|
36
|
+
its source in the docstring.
|
|
37
|
+
|
|
38
|
+
### Notes on defaults
|
|
39
|
+
|
|
40
|
+
- Parameter values are **not** stored unless `store_params=True`. A parameter
|
|
41
|
+
grid is frequently larger intellectual property than the return series it
|
|
42
|
+
produced. Hashes are always kept, so two runs stay comparable without the
|
|
43
|
+
values leaving the machine.
|
|
44
|
+
- Data identity is a content hash of the series, never a caller-supplied label,
|
|
45
|
+
so renaming an experiment does not detach it from its history.
|
|
46
|
+
- Importing the package makes no network call and requires no account.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: alphaengine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Validated research tooling for investment strategies: deflation, overfitting detection, and honest trial counts.
|
|
5
|
+
Project-URL: Homepage, https://github.com/quantOSC/alphaengine
|
|
6
|
+
Project-URL: Documentation, https://github.com/quantOSC/alphaengine#readme
|
|
7
|
+
Project-URL: Source, https://github.com/quantOSC/alphaengine
|
|
8
|
+
Project-URL: Issues, https://github.com/quantOSC/alphaengine/issues
|
|
9
|
+
Author: QuantOS
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: backtesting,deflated-sharpe,overfitting,quantitative-finance,research
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: numpy>=1.24
|
|
26
|
+
Requires-Dist: scipy>=1.10
|
|
27
|
+
Provides-Extra: agents
|
|
28
|
+
Requires-Dist: anthropic>=0.40; extra == 'agents'
|
|
29
|
+
Provides-Extra: connectors
|
|
30
|
+
Requires-Dist: httpx>=0.27; extra == 'connectors'
|
|
31
|
+
Requires-Dist: pyarrow>=15.0; extra == 'connectors'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: mypy==2.3.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff==0.16.1; extra == 'dev'
|
|
37
|
+
Requires-Dist: statsmodels>=0.14; extra == 'dev'
|
|
38
|
+
Provides-Extra: factors
|
|
39
|
+
Requires-Dist: statsmodels>=0.14; extra == 'factors'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# AlphaEngine
|
|
43
|
+
|
|
44
|
+
Validated research tooling for investment strategies. Run a parameter search,
|
|
45
|
+
get back the shape of the result and an honest read on whether it survives the
|
|
46
|
+
number of things you tried.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install alphaengine
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from alphaengine import sweep
|
|
54
|
+
|
|
55
|
+
r = sweep(backtest_fn, {"fast": [5, 10, 20], "slow": [50, 100, 200]}, data=prices)
|
|
56
|
+
|
|
57
|
+
r.surface() # is the result a broad plateau or a single lucky configuration?
|
|
58
|
+
r.verdict() # deflated for the 9 trials that were actually run
|
|
59
|
+
r.save() # study.json, on your disk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## What it does
|
|
63
|
+
|
|
64
|
+
**Runs your parameter grid.** `sweep()` calls your backtest function once per
|
|
65
|
+
combination. It does not backtest anything itself, so the engine you already
|
|
66
|
+
trust stays the engine you trust.
|
|
67
|
+
|
|
68
|
+
**Counts the trials for you.** The statistics that correct a Sharpe ratio for
|
|
69
|
+
multiple testing need to know how many variants were tested. That number is
|
|
70
|
+
almost never recorded, because nobody counts what they discarded. Running the
|
|
71
|
+
grid makes it `len(grid)`, so it never has to be asked for or asserted.
|
|
72
|
+
|
|
73
|
+
**Shows you the neighbourhood.** The output is whether your result sits on a
|
|
74
|
+
broad plateau or a knife edge, and where the robust region is centred. A single
|
|
75
|
+
spike surrounded by failures is a result fitted to its own parameters.
|
|
76
|
+
|
|
77
|
+
**Produces a portable study.** A JSON artifact holding what was tried, what came
|
|
78
|
+
back, and a content hash of the data it ran on. Readable in a text editor,
|
|
79
|
+
diffable, and versioned so it still parses in two years.
|
|
80
|
+
|
|
81
|
+
## What is in it
|
|
82
|
+
|
|
83
|
+
| Module | Contents |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `alphaengine.core` | deflated Sharpe, PSR, PBO via CSCV, CPCV, minimum track record length, performance and risk statistics |
|
|
86
|
+
| `alphaengine.sweep` | the grid runner and the sensitivity surface |
|
|
87
|
+
| `alphaengine.study` | the study artifact and its schema |
|
|
88
|
+
|
|
89
|
+
Two runtime dependencies, numpy and scipy, both already present in a typical
|
|
90
|
+
research environment. `import alphaengine` makes no network call and needs no
|
|
91
|
+
account. Factor decomposition and cointegration testing need statsmodels and
|
|
92
|
+
are available as `pip install 'alphaengine[factors]'`.
|
|
93
|
+
|
|
94
|
+
## Where this sits in QuantOS
|
|
95
|
+
|
|
96
|
+
AlphaEngine is the open research layer of the [QuantOS](https://github.com/quantOSC)
|
|
97
|
+
platform. It is the piece that runs on your machine, against your data, and it
|
|
98
|
+
is complete on its own: everything above works offline and forever, at no cost.
|
|
99
|
+
|
|
100
|
+
The QuantOS platform builds on it. Studies produced here can be persisted to a
|
|
101
|
+
firm's record, referenced when an idea becomes a position, and assembled into
|
|
102
|
+
the reports that go to an investment committee or an allocator. The library
|
|
103
|
+
computes; the platform remembers and reports. The two halves are separated so
|
|
104
|
+
that the part touching your data has no reason to phone home.
|
|
105
|
+
|
|
106
|
+
## The methods
|
|
107
|
+
|
|
108
|
+
Everything in `core` comes from the published literature. Nothing here is a
|
|
109
|
+
proprietary formula, which is deliberate: a referee whose reasoning you cannot
|
|
110
|
+
inspect is not a referee.
|
|
111
|
+
|
|
112
|
+
**Deflated Sharpe Ratio, Probabilistic Sharpe Ratio, minimum track record length**
|
|
113
|
+
Bailey, D. H., and López de Prado, M. (2012). "The Sharpe Ratio Efficient
|
|
114
|
+
Frontier." *Journal of Risk* 15(2), 3 to 44.
|
|
115
|
+
Bailey, D. H., and López de Prado, M. (2014). "The Deflated Sharpe Ratio:
|
|
116
|
+
Correcting for Selection Bias, Backtest Overfitting, and Non-Normality."
|
|
117
|
+
*Journal of Portfolio Management* 40(5), 94 to 107.
|
|
118
|
+
|
|
119
|
+
**Probability of Backtest Overfitting via CSCV**
|
|
120
|
+
Bailey, D. H., Borwein, J., López de Prado, M., and Zhu, Q. J. (2017). "The
|
|
121
|
+
Probability of Backtest Overfitting." *Journal of Computational Finance* 20(4),
|
|
122
|
+
39 to 69.
|
|
123
|
+
|
|
124
|
+
**Combinatorial purged cross-validation**
|
|
125
|
+
López de Prado, M. (2018). *Advances in Financial Machine Learning.* Wiley,
|
|
126
|
+
chapters 7 and 12.
|
|
127
|
+
|
|
128
|
+
**Multiple testing in asset pricing**
|
|
129
|
+
Harvey, C. R., Liu, Y., and Zhu, H. (2016). "... and the Cross-Section of
|
|
130
|
+
Expected Returns." *Review of Financial Studies* 29(1), 5 to 68.
|
|
131
|
+
Harvey, C. R., and Liu, Y. (2015). "Backtesting." *Journal of Portfolio
|
|
132
|
+
Management* 42(1), 13 to 28.
|
|
133
|
+
|
|
134
|
+
**Downside deviation**
|
|
135
|
+
Sortino, F. A., and Price, L. N. (1994). "Performance Measurement in a Downside
|
|
136
|
+
Risk Framework." *Journal of Investing* 3(3), 59 to 64.
|
|
137
|
+
|
|
138
|
+
**Factor regression standard errors** (in the `factors` extra)
|
|
139
|
+
Newey, W. K., and West, K. D. (1987). "A Simple, Positive Semi-Definite,
|
|
140
|
+
Heteroskedasticity and Autocorrelation Consistent Covariance Matrix."
|
|
141
|
+
*Econometrica* 55(3), 703 to 708.
|
|
142
|
+
|
|
143
|
+
**Unit root testing for cointegration** (in the `factors` extra)
|
|
144
|
+
Dickey, D. A., and Fuller, W. A. (1979). "Distribution of the Estimators for
|
|
145
|
+
Autoregressive Time Series with a Unit Root." *Journal of the American
|
|
146
|
+
Statistical Association* 74(366), 427 to 431.
|
|
147
|
+
|
|
148
|
+
## Reproducibility
|
|
149
|
+
|
|
150
|
+
The values these functions return are treated as a public contract. A study
|
|
151
|
+
written today has to reproduce in two years, so a change to a computed value is
|
|
152
|
+
a breaking change requiring a major version bump even when the signature is
|
|
153
|
+
unchanged. CI fails if a pinned value moves.
|
|
154
|
+
|
|
155
|
+
## Licence
|
|
156
|
+
|
|
157
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# AlphaEngine
|
|
2
|
+
|
|
3
|
+
Validated research tooling for investment strategies. Run a parameter search,
|
|
4
|
+
get back the shape of the result and an honest read on whether it survives the
|
|
5
|
+
number of things you tried.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install alphaengine
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from alphaengine import sweep
|
|
13
|
+
|
|
14
|
+
r = sweep(backtest_fn, {"fast": [5, 10, 20], "slow": [50, 100, 200]}, data=prices)
|
|
15
|
+
|
|
16
|
+
r.surface() # is the result a broad plateau or a single lucky configuration?
|
|
17
|
+
r.verdict() # deflated for the 9 trials that were actually run
|
|
18
|
+
r.save() # study.json, on your disk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What it does
|
|
22
|
+
|
|
23
|
+
**Runs your parameter grid.** `sweep()` calls your backtest function once per
|
|
24
|
+
combination. It does not backtest anything itself, so the engine you already
|
|
25
|
+
trust stays the engine you trust.
|
|
26
|
+
|
|
27
|
+
**Counts the trials for you.** The statistics that correct a Sharpe ratio for
|
|
28
|
+
multiple testing need to know how many variants were tested. That number is
|
|
29
|
+
almost never recorded, because nobody counts what they discarded. Running the
|
|
30
|
+
grid makes it `len(grid)`, so it never has to be asked for or asserted.
|
|
31
|
+
|
|
32
|
+
**Shows you the neighbourhood.** The output is whether your result sits on a
|
|
33
|
+
broad plateau or a knife edge, and where the robust region is centred. A single
|
|
34
|
+
spike surrounded by failures is a result fitted to its own parameters.
|
|
35
|
+
|
|
36
|
+
**Produces a portable study.** A JSON artifact holding what was tried, what came
|
|
37
|
+
back, and a content hash of the data it ran on. Readable in a text editor,
|
|
38
|
+
diffable, and versioned so it still parses in two years.
|
|
39
|
+
|
|
40
|
+
## What is in it
|
|
41
|
+
|
|
42
|
+
| Module | Contents |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `alphaengine.core` | deflated Sharpe, PSR, PBO via CSCV, CPCV, minimum track record length, performance and risk statistics |
|
|
45
|
+
| `alphaengine.sweep` | the grid runner and the sensitivity surface |
|
|
46
|
+
| `alphaengine.study` | the study artifact and its schema |
|
|
47
|
+
|
|
48
|
+
Two runtime dependencies, numpy and scipy, both already present in a typical
|
|
49
|
+
research environment. `import alphaengine` makes no network call and needs no
|
|
50
|
+
account. Factor decomposition and cointegration testing need statsmodels and
|
|
51
|
+
are available as `pip install 'alphaengine[factors]'`.
|
|
52
|
+
|
|
53
|
+
## Where this sits in QuantOS
|
|
54
|
+
|
|
55
|
+
AlphaEngine is the open research layer of the [QuantOS](https://github.com/quantOSC)
|
|
56
|
+
platform. It is the piece that runs on your machine, against your data, and it
|
|
57
|
+
is complete on its own: everything above works offline and forever, at no cost.
|
|
58
|
+
|
|
59
|
+
The QuantOS platform builds on it. Studies produced here can be persisted to a
|
|
60
|
+
firm's record, referenced when an idea becomes a position, and assembled into
|
|
61
|
+
the reports that go to an investment committee or an allocator. The library
|
|
62
|
+
computes; the platform remembers and reports. The two halves are separated so
|
|
63
|
+
that the part touching your data has no reason to phone home.
|
|
64
|
+
|
|
65
|
+
## The methods
|
|
66
|
+
|
|
67
|
+
Everything in `core` comes from the published literature. Nothing here is a
|
|
68
|
+
proprietary formula, which is deliberate: a referee whose reasoning you cannot
|
|
69
|
+
inspect is not a referee.
|
|
70
|
+
|
|
71
|
+
**Deflated Sharpe Ratio, Probabilistic Sharpe Ratio, minimum track record length**
|
|
72
|
+
Bailey, D. H., and López de Prado, M. (2012). "The Sharpe Ratio Efficient
|
|
73
|
+
Frontier." *Journal of Risk* 15(2), 3 to 44.
|
|
74
|
+
Bailey, D. H., and López de Prado, M. (2014). "The Deflated Sharpe Ratio:
|
|
75
|
+
Correcting for Selection Bias, Backtest Overfitting, and Non-Normality."
|
|
76
|
+
*Journal of Portfolio Management* 40(5), 94 to 107.
|
|
77
|
+
|
|
78
|
+
**Probability of Backtest Overfitting via CSCV**
|
|
79
|
+
Bailey, D. H., Borwein, J., López de Prado, M., and Zhu, Q. J. (2017). "The
|
|
80
|
+
Probability of Backtest Overfitting." *Journal of Computational Finance* 20(4),
|
|
81
|
+
39 to 69.
|
|
82
|
+
|
|
83
|
+
**Combinatorial purged cross-validation**
|
|
84
|
+
López de Prado, M. (2018). *Advances in Financial Machine Learning.* Wiley,
|
|
85
|
+
chapters 7 and 12.
|
|
86
|
+
|
|
87
|
+
**Multiple testing in asset pricing**
|
|
88
|
+
Harvey, C. R., Liu, Y., and Zhu, H. (2016). "... and the Cross-Section of
|
|
89
|
+
Expected Returns." *Review of Financial Studies* 29(1), 5 to 68.
|
|
90
|
+
Harvey, C. R., and Liu, Y. (2015). "Backtesting." *Journal of Portfolio
|
|
91
|
+
Management* 42(1), 13 to 28.
|
|
92
|
+
|
|
93
|
+
**Downside deviation**
|
|
94
|
+
Sortino, F. A., and Price, L. N. (1994). "Performance Measurement in a Downside
|
|
95
|
+
Risk Framework." *Journal of Investing* 3(3), 59 to 64.
|
|
96
|
+
|
|
97
|
+
**Factor regression standard errors** (in the `factors` extra)
|
|
98
|
+
Newey, W. K., and West, K. D. (1987). "A Simple, Positive Semi-Definite,
|
|
99
|
+
Heteroskedasticity and Autocorrelation Consistent Covariance Matrix."
|
|
100
|
+
*Econometrica* 55(3), 703 to 708.
|
|
101
|
+
|
|
102
|
+
**Unit root testing for cointegration** (in the `factors` extra)
|
|
103
|
+
Dickey, D. A., and Fuller, W. A. (1979). "Distribution of the Estimators for
|
|
104
|
+
Autoregressive Time Series with a Unit Root." *Journal of the American
|
|
105
|
+
Statistical Association* 74(366), 427 to 431.
|
|
106
|
+
|
|
107
|
+
## Reproducibility
|
|
108
|
+
|
|
109
|
+
The values these functions return are treated as a public contract. A study
|
|
110
|
+
written today has to reproduce in two years, so a change to a computed value is
|
|
111
|
+
a breaking change requiring a major version bump even when the signature is
|
|
112
|
+
unchanged. CI fails if a pinned value moves.
|
|
113
|
+
|
|
114
|
+
## Licence
|
|
115
|
+
|
|
116
|
+
Apache-2.0. See [LICENSE](LICENSE).
|