AlphaLens — an event-driven backtesting & walk-forward engine for systematic strategies
Project description
alphalens-core
An event-driven backtesting & walk-forward engine for systematic trading strategies.
Write a strategy as a Python class, run a single forward pass over an in-memory
OHLCV feed, and get back an equity curve, a trade log, and a rich set of
performance statistics — plus walk-forward analysis, parameter sweeps, and an
HTML dashboard. alphalens-core is the open engine behind AlphaLens.
Install
pip install alphalens-core # core engine (pandas + numpy only)
pip install "alphalens-core[viz]" # + matplotlib / quantstats dashboard & reports
pip install "alphalens-core[polygon]" # + Polygon market-data fetching
pip install "alphalens-core[fast]" # + pyarrow parquet cache
Quickstart
from alphalens_core import Algorithm, Backtester
class GoldenCross(Algorithm):
start = "2020-01-01"
end = "2024-12-31"
universe = ["SPY"]
def initialize(self):
self.set_warmup(50)
def on_data(self, slice):
hist = self.history("SPY", 50)["close"]
if len(hist) < 50:
return
self.set_holdings("SPY", 1.0 if hist.tail(10).mean() > hist.mean() else 0.0)
result = Backtester().run(GoldenCross)
print(result.stats) # Sharpe, Sortino, CAGR, max drawdown, win rate, …
result.dashboard # inline HTML report in Jupyter, or opens in your browser
Live data needs a POLYGON_API_KEY (a .env / .env.local file is loaded
automatically). To run fully offline, inject your own DataFeed.
Features
- Event-driven lifecycle —
initialize,on_data,on_order_event,on_securities_changed,on_end_of_day,on_warmup_finished. - Realistic fills — next-bar execution with pluggable slippage / fee / fill models, and a one-bar look-ahead guard so decisions on bar t can't peek at bar t's close.
- Walk-forward analysis with per-fold parameter search.
- Parameter sweeps + PBO (probability of backtest overfitting).
- Simulated brokerage that mirrors a live-broker API, so a live adapter drops in without strategy changes.
- Reporting —
result.stats, an HTMLresult.dashboard, and quantstats reports.
CLI
alphalens run --strategy mymod:MyStrategy
alphalens wfa --strategy mymod:MyStrategy --train 504 --test 63 --step 63
alphalens cache --info
License
Apache-2.0 © AlphaLens LLC
Project details
Release history Release notifications | RSS feed
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 alphalens_core-0.2.4.tar.gz.
File metadata
- Download URL: alphalens_core-0.2.4.tar.gz
- Upload date:
- Size: 295.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a56beaa2af1288f1fc606d1d65918c508ea4ecb171afa4bc27f28cea50a3acf6
|
|
| MD5 |
c4b188d4de789d0e0ca5dd917ff12aa9
|
|
| BLAKE2b-256 |
93f6980b452e679bf0cc0678074f8fa7869deecaba3d0bf1ec11d7d3f5a92f26
|
Provenance
The following attestation bundles were made for alphalens_core-0.2.4.tar.gz:
Publisher:
release.yml on AlphaLens-LLC/alphalens-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphalens_core-0.2.4.tar.gz -
Subject digest:
a56beaa2af1288f1fc606d1d65918c508ea4ecb171afa4bc27f28cea50a3acf6 - Sigstore transparency entry: 1728438118
- Sigstore integration time:
-
Permalink:
AlphaLens-LLC/alphalens-core@ee7011cacd25fd8a0cbeaebe5318371891e719b7 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/AlphaLens-LLC
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee7011cacd25fd8a0cbeaebe5318371891e719b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file alphalens_core-0.2.4-py3-none-any.whl.
File metadata
- Download URL: alphalens_core-0.2.4-py3-none-any.whl
- Upload date:
- Size: 280.2 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 |
1d243a7cc0506f8f04b785ebff9f5591ae7396512e8afecfbb244f938643358b
|
|
| MD5 |
00aee9d723cb7b7b148ba8ba85aee181
|
|
| BLAKE2b-256 |
b8419260e4ffa61e387a6bbbc14d670cdc9fda5047057d51675f41f88ab92663
|
Provenance
The following attestation bundles were made for alphalens_core-0.2.4-py3-none-any.whl:
Publisher:
release.yml on AlphaLens-LLC/alphalens-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphalens_core-0.2.4-py3-none-any.whl -
Subject digest:
1d243a7cc0506f8f04b785ebff9f5591ae7396512e8afecfbb244f938643358b - Sigstore transparency entry: 1728438197
- Sigstore integration time:
-
Permalink:
AlphaLens-LLC/alphalens-core@ee7011cacd25fd8a0cbeaebe5318371891e719b7 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/AlphaLens-LLC
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ee7011cacd25fd8a0cbeaebe5318371891e719b7 -
Trigger Event:
push
-
Statement type: