Skip to main content

A CLI aimed at making it easier to run QuantConnect's LEAN engine locally and in the cloud

Project description

Lean CLI

Build Status PyPI Version Project Status

This CLI is still in development. Bugs may still occur and breaking changes may still happen before the first beta release. Use with caution.

The Lean CLI is a cross-platform CLI aimed at making it easier to run the LEAN engine locally and in the cloud.

Roadmap

The following features are currently planned to be implemented (in order of priority):

  • Project scaffolding
  • Local autocompletion
  • CLI configuration
  • Local backtesting
  • Local debugging
  • Local research environment
  • Cloud synchronization
  • Cloud backtesting
  • First beta release
  • Local data downloading
  • Local optimization
  • Local backtest visualization
  • Local live trading
  • Cloud optimization
  • Cloud live trading

Installation

The CLI can be installed and updated by running pip install -U lean.

Note that many commands in the CLI require Docker to run. See Get Docker for instructions on how to install Docker for your operating system.

After installing the CLI, simply cd into an empty directory and run lean init to set up a Lean CLI project. This will scaffold a standard directory structure for you to hit the ground running.

Usage

A workflow with the CLI may look like this:

  1. cd into the Lean CLI project.
  2. Run lean create-project -l python "RSI Strategy" to create a new project with some basic code to get you started.
  3. Work on your strategy in ./RSI Strategy.
  4. Run a backtest with lean backtest "RSI Strategy". This runs your backtest in a Docker container containing the same packages as the ones used on QuantConnect.com, but with your own data.

Debugging backtests

To debug backtests some additional setup is needed depending on the editor and language you use.

Note: When debugging C#, after you attach to the debugger, a breakpoint will be hit for which your editor will tell you it has no code for. This is expected behavior, simply continue from that breakpoint and your algorithm will start running.

VS Code + Python

  1. Install the Python extension.
  2. Run the lean backtest command with the --debug ptvsd option.
  3. Wait until the CLI tells you to attach to the debugger.
  4. In VS Code, open the Run tab and run the configuration called "Debug Python with Lean CLI" (this configuration is created when you run lean init).

VS Code + C#

  1. Install version 15.8 of the Mono Debug extension. You can do this by first installing the latest version and then clicking on the arrow button next to the Uninstall button, which will open a context menu containing the "Install Another Version" option.
  2. Run the lean backtest command with the --debug mono option.
  3. Wait until the CLI tells you to attach to the debugger.
  4. In VS Code, open the Run tab and run the configuration called "Debug C# with Lean CLI" (this configuration is created when you run lean init).

PyCharm + Python

Note: This combination requires PyCharm Professional.

  1. In PyCharm, start debugging using the "Debug with Lean CLI" run configuration (this configuration is created when you run lean init).
  2. Run the lean backtest command with the --debug pycharm option.

Visual Studio + C#

  1. Install the VSMonoDebugger extension.
  2. In Visual Studio, go to "Extensions > Mono > Settings" and enter the following settings:
    • Remote Host IP: 127.0.0.1
    • Remote Host Port: 55555
    • Mono Debug Port: 55555
  3. Run the lean backtest command with the --debug mono option.
  4. Wait until the CLI tells you to attach to the debugger.
  5. In Visual Studio, attach to the debugger using "Extensions > Mono > Attach to mono debugger".

Rider + C#

  1. Run the lean backtest command with the --debug mono option.
  2. Wait until the CLI tells you to attach to the debugger.
  3. In Rider, start debugging using the "Debug with Lean CLI" run configuration (this configuration is created when you run lean init).

Development

To work on the Lean CLI, clone the repository, enter an environment containing Python 3.6+ and run pip install -r requirements.txt. This command will install the required dependencies and installs the CLI in editable mode. This means you'll be able to edit the code and immediately see the results the next time you run lean.

If you need to add dependencies, first update setup.py (if it is a production dependency) or requirements.txt (if it is a development dependency) and then re-run pip install -r requirements.txt.

The automated tests can be ran by running pytest. The filesystem and HTTP requests are mocked when running tests to make sure they run in an isolated environment.

Maintainers can publish new releases by pushing a Git tag containing the new version to GitHub. This will trigger a GitHub Actions workflow which releases the current main branch to PyPI with the value of the tag as version. Make sure the version is not prefixed with "v".

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

lean-0.1.5.tar.gz (63.8 kB view details)

Uploaded Source

Built Distribution

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

lean-0.1.5-py3-none-any.whl (85.8 kB view details)

Uploaded Python 3

File details

Details for the file lean-0.1.5.tar.gz.

File metadata

  • Download URL: lean-0.1.5.tar.gz
  • Upload date:
  • Size: 63.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for lean-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ffe8ce3c64580d724295152dfa17196a34c72df64a23b65977eaa765b6ca08a6
MD5 1d5a7f1db13a58937210c7744195ccc8
BLAKE2b-256 13a59acb61245a815b3c9abb887ef193628e66ba8b67b6d2b663c2bc4c8cb837

See more details on using hashes here.

File details

Details for the file lean-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: lean-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 85.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for lean-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb2bde8825e257b3691647f58babe10e76c11e6d688a2eb5b1d60a2d54a2813
MD5 f942c76dfde8b65d28c28941befad37c
BLAKE2b-256 ee49f6300be14449e03b7e4bf0c06ee900899c309b8023bf7da82c69d58b0842

See more details on using hashes here.

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