LEAN

Warning

LEAN and Lean CLI are standalone QuantConnect tools. They do not depend on QRT. These guides document a tested local workflow. The optional q.bt.lean adapter orchestrates the same commands through Python without replacing LEAN as the execution engine.

LEAN is an event-driven trading engine. Lean CLI manages its local Docker image, workspaces, projects, data, backtests, and reports.

Guides

  • Install and initialize: install Lean CLI with uv, create an organization workspace, and understand the generated files.
  • Projects and backtests: choose an algorithm file, pass parameters, pin engine behavior, and inspect artifacts.
  • Native data formats: complete Stockholm equity, metadata, corporate-action, and storage reference.
  • Generate the Sweden fixture: create 100 synthetic XSTO assets at tick through daily resolution.
  • Universes and composites: use native daily, ETF, and Index constituent files, including an OMXS30-style composite.
  • 20/100 SMA strategy: run a dynamic-universe crossover strategy over the 100-asset fixture.
  • Generate reports: create reports, select exact result JSON files, and handle custom-market SIDs safely.
  • Troubleshooting: diagnose missing files, currencies, models, permissions, result selection, and report errors.
  • q.bt integration: run Lean CLI from Python, retain exact artifacts, and build native QRT reports.

Tested fixture

The repository tracks the reusable fixture at lean/demo-generated-data. Generated data, backtests, reports, storage, and local Lean CLI identity remain ignored by Git. Its generator creates:

  • 100 synthetic equities, AAA through ADV;
  • 270 XSTO sessions from 2023-12-01 through 2024-12-30;
  • native tick, minute, hour, and daily files with matching intraday quotes;
  • map files, factor files, market hours, and symbol properties;
  • a 100-member daily universe and weighted 30-member OMXS30 Index universe;
  • validation algorithms for imports, universes, a 20/100 SMA crossover, and reports.

The fixture is test data, not a claim about historical Swedish prices or constituents.

Boundary with QRT

QRT currently contributes reusable preparation primitives such as:

import qrt as q

sessions = q.calendar.schedule(
    "2024-01-01",
    "2024-12-31",
    exchange="XSTO",
)
prices = q.stats.random_walk(
    periods=10_000,
    paths=100,
    seed=42,
)

LEAN owns event progression, subscriptions, orders, fills, portfolio accounting, and result production. QRT’s adapter owns validation, process lifecycle, artifact selection, normalization, and native report generation.

Back to top