Guides

Sync backtests

Run local backtests, sync them to AlphaLens, and understand the Strategy Center data model.

Backtests are local Python runs. AlphaLens receives the finished result and renders it as a Strategy Center source.

Run from the CLI

bash
ALPHALENS_API_KEY=alens_... alphalens run --strategy my_strategy:MyStrategy

The strategy import path is module:ClassName. Run from the directory where the module is importable.

Common overrides:

bash
alphalens run \
  --strategy my_strategy:MyStrategy \
  --start 2021-01-01 \
  --end 2025-12-31 \
  --resolution 1day \
  --cash 250000 \
  --benchmark SPY \
  --param leverage=1.5

Useful output flags:

FlagPurpose
--report report.htmlWrite a local HTML report
--save-equity equity.csvSave local equity series
--save-trades trades.csvSave local trades
--save-orders orders.csvSave local orders
--no-progressSuppress monthly progress logs
--no-trackSkip local run registry tracking

Run from Python

python
from alphalens_core import AlphaLensClient
from my_strategy import MyStrategy

al = AlphaLensClient(api_key="alens_...")
result = al.backtest(MyStrategy)

print(result.stats)

If api_key is omitted, AlphaLensClient reads ALPHALENS_API_KEY.

What the engine does

When you run a backtest, alphalens-core:

  1. Loads the strategy class.
  2. Fetches the requested universe and benchmark data.
  3. Seeds warmup history.
  4. Calls initialize.
  5. Replays bars through schedules and on_data.
  6. Simulates fills using next-bar execution.
  7. Computes metrics, returns, trades, orders, and position values.
  8. Syncs the normalized result to AlphaLens when cloud auth is configured.

What appears in Strategy Center

Synced backtests become backtest:<run_id> sources.

Strategy Center uses the synced data for:

  • Strategy and run lists.
  • Equity and daily performance.
  • Benchmark comparison.
  • Drawdown and underwater curves.
  • Rolling Sharpe.
  • Trades and orders.
  • Position allocation over time.
  • KPI values such as return, Sharpe, Calmar, PSR, Omega, win rate, and P&L.

Standard Portfolio output

Backtests are normalized into the same dashboard contract as broker accounts.

FieldWhy it matters
NAV pointsPerformance, benchmark comparison, drawdown, rolling Sharpe
PositionsHoldings table and allocation chart
Trades and ordersWin/loss, trade analytics, audit trail
MetricsKPI strip and run comparison
WarningsMissing data, stale source, or reconciliation issues

This is why Strategy Center looks like the portfolio dashboard instead of a separate research-only report.

Parameter sweeps

Add sweep_grid to the class for repeatable research:

python
class MyStrategy(Algorithm):
    sweep_grid = {
        "lookback": [63, 126, 189],
        "top_n": [1, 2, 3],
    }

Then run batch or walk-forward workflows from the CLI. Promote only the runs that pass your research criteria into paper deployment.