ClawKit Logo
ClawKitReliability Toolkit
Back to Registry
Official Verified

lean

Run QuantConnect LEAN backtests and manage US equity algorithm development. Use when asked to backtest a trading strategy, run a LEAN algorithm, analyze backtest results, download market data, or deploy to Interactive Brokers TWS. Covers algorithm creation, data management, config editing, and result analysis.

skill-install — Terminal

Install via CLI (Recommended)

clawhub install openclaw/skills/skills/cylqqqcyl/lean-engine
Or

LEAN Engine — QuantConnect Algorithmic Trading

Prerequisites & Setup

Required Environment Variables

VariablePurposeExample
LEAN_ROOTPath to cloned LEAN repository/home/user/lean
DOTNET_ROOTPath to .NET SDK installation/home/user/.dotnet
PYTHONNET_PYDLLPath to Python shared library (required by LEAN's pythonnet)$LEAN_ROOT/.libs/libpython3.11.so.1.0

All three must be set before using this skill. Add to your shell profile:

export LEAN_ROOT="$HOME/lean"
export DOTNET_ROOT="$HOME/.dotnet"
export PATH="$PATH:$DOTNET_ROOT"
export PYTHONNET_PYDLL="$LEAN_ROOT/.libs/libpython3.11.so.1.0"

Note: LEAN bundles its own Python shared library in $LEAN_ROOT/.libs/. If you built LEAN from source, the library should be there after dotnet build. If not, install libpython3.11-dev and point PYTHONNET_PYDLL to your system's libpython3.11.so.

First-Time Setup

  1. Install .NET 8 SDK:

    # Linux/macOS
    wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
    chmod +x dotnet-install.sh
    ./dotnet-install.sh --channel 8.0
    export DOTNET_ROOT="$HOME/.dotnet"
    export PATH="$PATH:$DOTNET_ROOT"
    
  2. Clone and build LEAN:

    git clone https://github.com/QuantConnect/Lean.git "$LEAN_ROOT"
    cd "$LEAN_ROOT"
    dotnet build QuantConnect.Lean.sln -c Debug
    
  3. Download initial market data:

    pip install yfinance pandas
    python3 {baseDir}/scripts/download_us_universe.py --symbols sp500 --start 2020-01-01 --data-dir "$LEAN_ROOT/Data"
    
  4. Verify setup:

    ls "$LEAN_ROOT/Data/equity/usa/daily/"  # Should list .zip files
    ls "$LEAN_ROOT/Launcher/bin/Debug/"      # Should contain QuantConnect.Lean.Launcher.dll
    

Environment

  • LEAN source: $LEAN_ROOT/
  • Launcher (pre-built): $LEAN_ROOT/Launcher/bin/Debug/
  • Config: $LEAN_ROOT/Launcher/config.json
  • Python algos: $LEAN_ROOT/Algorithm.Python/
  • Market data: $LEAN_ROOT/Data/
  • dotnet: $DOTNET_ROOT/dotnet (add to PATH: export PATH="$PATH:$DOTNET_ROOT")

Quick Reference

Run a Backtest

  1. Place algorithm in $LEAN_ROOT/Algorithm.Python/YourAlgo.py
  2. Edit config to point to it:
    # Update config.json — set these fields:
    # "algorithm-type-name": "YourClassName"
    # "algorithm-language": "Python"
    # "algorithm-location": "../../../Algorithm.Python/YourAlgo.py"
    
  3. Run:
    export PATH="$PATH:$DOTNET_ROOT"
    cd "$LEAN_ROOT/Launcher/bin/Debug"
    dotnet QuantConnect.Lean.Launcher.dll
    
  4. Results appear in stdout + $LEAN_ROOT/Results/

Or use the helper script:

bash {baseDir}/scripts/run_backtest.sh YourClassName YourAlgo.py

Config Editing

Edit $LEAN_ROOT/Launcher/config.json with these key fields:

Metadata

Author@cylqqqcyl
Stars3409
Views0
Updated2026-03-25
View Author Profile
AI Skill Finder

Not sure this is the right skill?

Describe what you want to build — we'll match you to the best skill from 16,000+ options.

Find the right skill
Add to Configuration

Paste this into your clawhub.json to enable this plugin.

{
  "plugins": {
    "official-cylqqqcyl-lean-engine": {
      "enabled": true,
      "auto_update": true
    }
  }
}
Safety NoteClawKit audits metadata but not runtime behavior. Use with caution.