User Guides

Workflows

Introduction

The Lean CLI supports multiple workflows, ranging from running everything locally to just using your local development environment but keeping all execution in the cloud. This page contains several examples of common workflows, but you're free to mix local and cloud features in any way you'd like.

Cloud-focused workflow

A cloud-focused workflow (local development, cloud execution) with the CLI might look like this:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean cloud pull to pull remotely changed files.
  3. Start programming locally and run backtests in the cloud with lean cloud backtest "Project Name" --open --push whenever there is something to backtest. The --open flag means that the backtest results are opened in the browser when done, while the --push flag means that local changes are pushed to the cloud before running the backtest.
  4. Whenever you want to create a new project, run lean create-project "Project Name" --push and lean cloud push --project "Project Name" to create a new project containing some basic code and to push it to the cloud.
  5. When you're finished for the moment, run lean cloud push to push all locally changed files to the cloud.

The advantage of this workflow is that you can use all the tools in your local development environment to write your code (i.e. autocomplete, auto-formatting, etc.) while using QuantConnect's computing infrastructure and data when running your code. This advantage means you don't need to have a powerful computer and you don't need to have your own data, since that's all provided by us. The downside to this workflow is that you need a constant internet connection because without an internet connection the CLI can't communicate with the cloud.

Locally-focused workflow

A locally-focused workflow (local development, local execution) with the CLI might look like this:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean create-project "Project Name" to create a new project with some basic code to get you started.
  3. Work on your strategy in ./Project Name.
  4. Run lean research "Project Name" to start a Jupyter Lab session to perform research in.
  5. Run lean backtest "Project Name" to run a backtest whenever there's something to test. This command runs your strategy in a Docker container containing the same packages as the ones used on QuantConnect.com, but with your own data.

With this workflow, you are not limited to the computing power that's available in QuantConnect's infrastructure, because everything runs locally. On the other hand, this also means you must have all your required data available locally. When using this workflow you might be interested in the Local data tutorials, which explain how to download some of QuantConnect's data for local usage.

Mixed workflow

A mixed workflow (local development, local debugging, and cloud execution) with the CLI might look like this:

  1. Open a terminal in the directory you ran lean init in.
  2. Run lean cloud pull to pull remotely changed files.
  3. Start programming on your strategies.
  4. Whenever you want to debug a strategy, follow the Debugging local backtests to debug your backtests in your local development environment.
  5. Whenever you want to backtest a strategy, run lean cloud backtest "Project Name" --open --push to push local changes to the cloud, run a backtest in the cloud and open the results in the browser once finished.
  6. When you're finished for the moment, run lean cloud push to push all locally changed files to the cloud.

The advantage of this workflow is that you can use your local development environment and its debugging tools when writing your algorithms while using QuantConnect's infrastructure and data in backtesting and live trading. Although this does require you to have a local copy of the data that your strategy needs, it doesn't require you to maintain your own infrastructure and data feeds in live trading. When using this workflow make sure to check out the Local data tutorials, which explain how to download some of QuantConnect's data for local usage.

You can also see our Videos. You can also get in touch with us via Chat.

Did you find this page helpful?

Contribute to the documentation: