Skip to main content

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 lifecycleinitialize, 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.
  • Reportingresult.stats, an HTML result.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alphalens_core-0.3.4.tar.gz (305.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alphalens_core-0.3.4-py3-none-any.whl (286.5 kB view details)

Uploaded Python 3

File details

Details for the file alphalens_core-0.3.4.tar.gz.

File metadata

  • Download URL: alphalens_core-0.3.4.tar.gz
  • Upload date:
  • Size: 305.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for alphalens_core-0.3.4.tar.gz
Algorithm Hash digest
SHA256 91afe5af0e79744a6d8b40e4878da0f7db728c312a74e9201967a69ee077c175
MD5 5c91b4517bc0534f33c3f05afc36f7f1
BLAKE2b-256 f3632396a513a57658ca566c521396a88b6d5aab63e471e65b7a2cff87b6169e

See more details on using hashes here.

Provenance

The following attestation bundles were made for alphalens_core-0.3.4.tar.gz:

Publisher: release.yml on AlphaLens-LLC/alphalens-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alphalens_core-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: alphalens_core-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 286.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for alphalens_core-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 18d3b342c1e95950a216dddb84a0a4244ba7681d85588517859ad9eb1bd2ec3a
MD5 e549f0800e7f677139b481d39b79d9d5
BLAKE2b-256 8c2511c0617b977cbc810bce7a8fa2b76b10d9e96bad97f6445a80eb6983f6b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for alphalens_core-0.3.4-py3-none-any.whl:

Publisher: release.yml on AlphaLens-LLC/alphalens-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page