---
title: "lean cloud optimize"
description: "API reference for the command `lean cloud optimize` in command line console."
canonical: https://www.quantconnect.com/docs/v2/lean-cli/api-reference/lean-cloud-optimize
markdown: https://www.quantconnect.com/docs/v2/lean-cli/api-reference/lean-cloud-optimize.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/05%20Lean%20CLI/99%20API%20Reference/16%20lean%20cloud%20optimize
modified: 2026-10-30
index: https://www.quantconnect.com/llms.txt
---

# lean cloud optimize

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Lean CLI](https://www.quantconnect.com/docs/v2/lean-cli.md) > [API Reference](https://www.quantconnect.com/docs/v2/lean-cli/api-reference.md) > lean cloud optimize

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Optimize a project in the cloud.

```
$ lean cloud optimize [OPTIONS] PROJECT
```

To use the CLI, you must be a member in an [organization](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/tier-features.md) on a paid tier.

## Description

Runs an optimization for a cloud project. While running the optimization, a progress bar shows to keep you up-to-date on the status of the optimization. After running the optimization, the optimal parameters and the statistics of the backtest with the optimal parameters are logged.

By default, an interactive wizard is shown, letting you configure the target, the parameters, the constraints, the node type, and the number of parallel nodes. When `--target` is given the command runs in non-interactive mode and does not prompt for input or confirmation.

When `--target` is given, the optimizer configuration is read from the command-line options. This means the `--target`, `--target-direction`, `--parameter`, `--node`, and `--parallel-nodes` options become required. Additionally, you can also use `--constraint` to specify optimization constraints.

In non-interactive mode, the parameters can be configured using the `--parameter` option. This option takes the following values: the name of the parameter, its minimum value, its maximum value, and its step size. You can provide this option multiple times to configure multiple parameters.

In non-interactive mode, the constraints can be configured using the `--constraint` option. This option takes a "statistic operator value" string as value, where the statistic must be a path to a property in a backtest's output file, like "TotalPerformance.PortfolioStatistics.SharpeRatio". This statistic can also be shortened to "SharpeRatio" or "Sharpe Ratio", in which case, the command automatically converts it to the longer version. The value must be a number and the operator must be `<`, `>`, `<=`, `>=`, `==`, or `==`. You can provide this option multiple times to configure multiple constraints.

Example non-interactive usage:

```
$ lean cloud optimize "My Project" \
    --target "Sharpe Ratio" \
    --target-direction "max" \
    --parameter my-first-parameter 1 10 0.5 \
    --parameter my-second-parameter 20 30 5 \
    --constraint "Drawdown < 0.5" \
    --constraint "Sharpe Ratio >= 1" \
    --node O4-12 \
    --parallel-nodes 12 \
    --push
```

If you have a local copy of the cloud project, you can use the `--push` option to push local modifications to the cloud before starting the optimization.

## Arguments

The `lean cloud optimize` command expects the following arguments:

| Argument | Description |
| --- | --- |
| `<project>` | The name or Id of the project to optimize. |

## Options

The `lean cloud optimize` command supports the following options:

| Option | Description |
| --- | --- |
| `--target <string>` | The target statistic of the optimization |
| `--target-direction <enum: min\|max>` | Whether the target must be minimized or maximized |
| `--parameter <<string> <float> <float> <float>>...` | The 'parameter min max step' pairs configuring the parameters to optimize |
| `--constraint <string>` | The 'statistic operator value' pairs configuring the constraints of the optimization |
| `--node <enum: O2-8\|O4-12\|O8-16>` | The node type to run the optimization on |
| `--parallel-nodes <integer>` | The number of nodes that may be run in parallel |
| `--name <string>` | The name of the optimization (a random one is generated if not specified) |
| `--push` | Push local modifications to the cloud before starting the optimization |
| `--verbose` | Enable debug logging |
| `--help` | Display the help text of the `lean cloud optimize` command and exit |
