---
title: "Create Optimization"
description: "Create an optimization with the specified parameters in QC Cloud through a request with the QC API."
canonical: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/optimization-management/create-optimization
markdown: https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/optimization-management/create-optimization.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/01%20Cloud%20Platform/99%20API%20Reference/08%20Optimization%20Management/01%20Create%20Optimization
modified: 2026-10-28
index: https://www.quantconnect.com/llms.txt
---

# Create Optimization

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Cloud Platform](https://www.quantconnect.com/docs/v2/cloud-platform.md) > [API Reference](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference.md) > [Optimization Management](https://www.quantconnect.com/docs/v2/cloud-platform/api-reference/optimization-management.md) > Create Optimization

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

## Introduction

Create an optimization with the specified parameters.

## Request

Project, compile, and optimization parameters for launching an optimization job. The `/optimizations/create` API accepts requests in the following format:

| `CreateOptimizationRequest` Model - Request to create an optimization job. |  |
| --- | --- |
| projectId | `integer required example: 23456789` Id of the project to optimize. |
| name | `string required example: Mia First Optimization Job` Name of the optimization. |
| target | `string Enum` Target statistic of the optimization to minimize or maximize. Options : ['TotalPerformance.PortfolioStatistics.SharpeRatio', 'TotalPerformance.PortfolioStatistics.CompoundingAnnualReturn', 'TotalPerformance.PortfolioStatistics.ProbabilisticSharpeRatio', 'TotalPerformance.PortfolioStatistics.Drawdown'] |
| targetTo | `string Enum` Target extremum of the optimization. Options : ['min', 'max'] |
| targetValue | `number example: 1` Desired value for the optimization target statistic. |
| strategy | `string Enum` Optimization strategy. Options : ['QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy'] |
| compileId | `string required example: 5d1f2cba3a0ec7407c566614300502b5-173e0419674daf4144ce7c9931155ca8` Optimization compile Id. |
| parameters | `OptimizationParameter Array required` Optimization parameters. |
| constraints | `OptimizationConstraint Array` Optimization constraints. |
| estimatedCost | `number required example: 10` Estimated cost for optimization. |
| nodeType | `string Enum` Optimization node types available in QuantConnect Cloud. Options : ['O2-8', 'O4-12', 'O8-16'] |
| parallelNodes | `integer required example: 4` Number of parallel nodes for optimization. |
| Example | `{ "projectId": 23456789, "name": "Mia First Optimization Job", "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "targetTo": "min", "targetValue": 1, "strategy": "QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy", "compileId": "5d1f2cba3a0ec7407c566614300502b5-173e0419674daf4144ce7c9931155ca8", "parameters": [ { "name": "rsi_period", "min": 10, "max": 20, "step": 1, "minStep": 1 } ], "constraints": [ { "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "operator": "LessOrEqual", "targetValue": 1 } ], "estimatedCost": 10, "nodeType": "O2-8", "parallelNodes": 4 }` |

| `OptimizationTargetStatistic` Model |  |
| --- | --- |
| OptimizationNodeType | `string Enum` /. Options : ['TotalPerformance.PortfolioStatistics.SharpeRatio', 'TotalPerformance.PortfolioStatistics.CompoundingAnnualReturn', 'TotalPerformance.PortfolioStatistics.ProbabilisticSharpeRatio', 'TotalPerformance.PortfolioStatistics.Drawdown'] |
| Example | `{ "OptimizationNodeType": "TotalPerformance.PortfolioStatistics.SharpeRatio" }` |

| `OptimizationTargetTo` Model |  |
| --- | --- |
| OptimizationNodeType | `string Enum` /. Options : ['min', 'max'] |
| Example | `{ "OptimizationNodeType": "min" }` |

| `OptimizationStrategy` Model |  |
| --- | --- |
| OptimizationNodeType | `string Enum` /. Options : ['QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy'] |
| Example | `{ "OptimizationNodeType": "QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy" }` |

| `OptimizationParameter` Model |  |
| --- | --- |
| name | `string required example: rsi_period` Name of optimization parameter. |
| min | `number required example: 10` Minimum value of optimization parameter, applicable for boundary conditions. |
| max | `number required example: 20` Maximum value of optimization parameter, applicable for boundary conditions. |
| step | `number required example: 1` Movement, should be positive. |
| minStep | `number example: 1` Minimal possible movement for current parameter, should be positive. Used by `Strategies.EulerSearchOptimizationStrategy` to determine when this parameter can no longer be optimized. |
| Example | `{ "name": "rsi_period", "min": 10, "max": 20, "step": 1, "minStep": 1 }` |

| `OptimizationConstraint` Model - Backtests in the optimization job that don't respect this constraint are excluded from the optimization result. |  |
| --- | --- |
| target | `string Enum` The target statistic to track. Options : ['TotalPerformance.PortfolioStatistics.SharpeRatio', 'TotalPerformance.PortfolioStatistics.CompoundingAnnualReturn', 'TotalPerformance.PortfolioStatistics.ProbabilisticSharpeRatio', 'TotalPerformance.PortfolioStatistics.Drawdown'] |
| operator | `string Enum required` The target comparison operation. Options : ['LessOrEqual', 'Less', 'GreaterOrEqual', 'Greater', 'NotEqual', 'Equals'] |
| targetValue | `number required example: 1` The threshold value for the target constraint. |
| Example | `{ "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "operator": "LessOrEqual", "targetValue": 1 }` |

| `OptimizationNodeType` Model - Optimization node types available in QuantConnect Cloud. |  |
| --- | --- |
| OptimizationNodeType | `string Enum` Optimization node types available in QuantConnect Cloud. Options : ['O2-8', 'O4-12', 'O8-16'] |
| Example | `{ "OptimizationNodeType": "O2-8" }` |

## Responses

The `/optimizations/create` API provides a response in the following format:

### 200 Success

| `ListOptimizationResponse` Model - Response received when creating an optimization or listing optimizations of a project. |  |
| --- | --- |
| optimizations | `CreateOptimizationResponse Array` Collection of summarized optimization objects. |
| success | `boolean` Indicate if the API request was successful. |
| errors | `string Array` List of errors with the API call. |
| Example | `{ "optimizations": [ { "optimizationId": "O-401d3d40b5a0e9f8c46c954a303f3ddd", "projectId": 23456789, "name": "string", "status": , "nodeType": "O2-8", "criterion": { "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "extremum": "min", "targetValue": 1 }, "created": "2021-11-26T15:18:27.693Z", "psr": 0, "sharpeRatio": 0, "trades": 0, "cloneId": 0, "outOfSampleDays": 0, "outOfSampleMaxEndDate": "2021-11-26T15:18:27.693Z", "parameters": [ { "name": "rsi_period", "min": 10, "max": 20, "step": 1, "minStep": 1 } ] } ], "success": true, "errors": [ "string" ] }` |

| `CreateOptimizationResponse` Model - Response received when launching an optimization job or listing all the optimization jobs of a project. |  |
| --- | --- |
| optimizationId | `string example: O-401d3d40b5a0e9f8c46c954a303f3ddd` Id of the optimization job. |
| projectId | `integer example: 23456789` Id of the project the optimization belongs to. |
| name | `string` Name of the optimization. |
| status | `OptimizationStatus object` Status of the optimization. |
| nodeType | `string Enum` Optimization node types available in QuantConnect Cloud. Options : ['O2-8', 'O4-12', 'O8-16'] |
| criterion | `OptimizationTarget object` Optimization statistical target. |
| created | `string($date-time)` Date and time of when this optimization was created. |
| psr | `number` Probabilistic Sharpe ratio statistic. |
| sharpeRatio | `number` Sharpe ratio statistic. |
| trades | `integer` Number of trades in the best backtest (based on the criterion) of the optimziation. |
| cloneId | `integer` Id of project where this current project was originally cloned. |
| outOfSampleDays | `integer` Number out-of-sample days. |
| outOfSampleMaxEndDate | `string($date-time)` End date of out-of-sample data. |
| parameters | `OptimizationParameter Array` Parameters used in this optimization. |
| Example | `{ "optimizationId": "O-401d3d40b5a0e9f8c46c954a303f3ddd", "projectId": 23456789, "name": "string", "status": , "nodeType": "O2-8", "criterion": { "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "extremum": "min", "targetValue": 1 }, "created": "2021-11-26T15:18:27.693Z", "psr": 0, "sharpeRatio": 0, "trades": 0, "cloneId": 0, "outOfSampleDays": 0, "outOfSampleMaxEndDate": "2021-11-26T15:18:27.693Z", "parameters": [ { "name": "rsi_period", "min": 10, "max": 20, "step": 1, "minStep": 1 } ] }` |

| `OptimizationNodeType` Model - Optimization node types available in QuantConnect Cloud. |  |
| --- | --- |
| OptimizationParameter | `string Enum` Optimization node types available in QuantConnect Cloud. Options : ['O2-8', 'O4-12', 'O8-16'] |
| Example | `{ "OptimizationParameter": "O2-8" }` |

| `OptimizationTarget` Model |  |
| --- | --- |
| target | `string Enum` The target statistic to track. Options : ['TotalPerformance.PortfolioStatistics.SharpeRatio', 'TotalPerformance.PortfolioStatistics.CompoundingAnnualReturn', 'TotalPerformance.PortfolioStatistics.ProbabilisticSharpeRatio', 'TotalPerformance.PortfolioStatistics.Drawdown'] |
| extremum | `string Enum` Defines the direction of optimization. Options : ['min', 'max'] |
| targetValue | `number example: 1` Desired value for the optimization target statistic. |
| Example | `{ "target": "TotalPerformance.PortfolioStatistics.SharpeRatio", "extremum": "min", "targetValue": 1 }` |

| `OptimizationTargetStatistic` Model |  |
| --- | --- |
| OptimizationParameter | `string Enum` /. Options : ['TotalPerformance.PortfolioStatistics.SharpeRatio', 'TotalPerformance.PortfolioStatistics.CompoundingAnnualReturn', 'TotalPerformance.PortfolioStatistics.ProbabilisticSharpeRatio', 'TotalPerformance.PortfolioStatistics.Drawdown'] |
| Example | `{ "OptimizationParameter": "TotalPerformance.PortfolioStatistics.SharpeRatio" }` |

| `OptimizationTargetTo` Model |  |
| --- | --- |
| OptimizationParameter | `string Enum` /. Options : ['min', 'max'] |
| Example | `{ "OptimizationParameter": "min" }` |

| `OptimizationParameter` Model |  |
| --- | --- |
| name | `string required example: rsi_period` Name of optimization parameter. |
| min | `number required example: 10` Minimum value of optimization parameter, applicable for boundary conditions. |
| max | `number required example: 20` Maximum value of optimization parameter, applicable for boundary conditions. |
| step | `number required example: 1` Movement, should be positive. |
| minStep | `number example: 1` Minimal possible movement for current parameter, should be positive. Used by `Strategies.EulerSearchOptimizationStrategy` to determine when this parameter can no longer be optimized. |
| Example | `{ "name": "rsi_period", "min": 10, "max": 20, "step": 1, "minStep": 1 }` |

### 401 Authentication Error

| `UnauthorizedError` Model - Unauthorized response from the API. Key is missing, invalid, or timestamp is too old for hash. |  |
| --- | --- |
| www_authenticate | `string` Header |

## Examples

The following example demonstates creating, reading, updating, deleting, aborting and listing backtests of a project through the cloud API.

```
from base64 import b64encode
from hashlib import sha256
from time import time
from requests import get, post
BASE_URL = 'https://www.quantconnect.com/api/v2/'

# You need to replace these with your actual credentials.
# You can request your credentials at https://www.quantconnect.com/settings/
# You can find our organization ID at https://www.quantconnect.com/organization/
USER_ID = 0
API_TOKEN = '____'
ORGANIZATION_ID = '____'

def get_headers():
    # Get timestamp
    timestamp = f'{int(time())}'
    time_stamped_token = f'{API_TOKEN}:{timestamp}'.encode('utf-8')

    # Get hased API token
    hashed_token = sha256(time_stamped_token).hexdigest()
    authentication = f'{USER_ID}:{hashed_token}'.encode('utf-8')
    authentication = b64encode(authentication).decode('ascii')

    # Create headers dictionary.
    return {
        'Authorization': f'Basic {authentication}',
        'Timestamp': timestamp
    }

# Authenticate to verify credentials
response = post(f'{BASE_URL}/authenticate', headers = get_headers())
print(response.json())

# --------------------

# The project ID of the project to manage an optimization job
project_id = 12345678

### Estimate Optimization Cost
# Send a POST request to the /optimizations/estimate endpoint to estimate cost
response = post(f'{BASE_URL}/optimizations/estimate', headers=get_headers(), json={
    "projectId": project_id,  # ID of the project
    "name": f"Optimization_{compileId[:5]}",  # Name of the optimization (using compile ID prefix)
    "target": "TotalPerformance.PortfolioStatistics.SharpeRatio",  # Optimization target metric
    "targetTo": "max",  # Direction to optimize (maximize)
    "targetValue": None,  # Specific target value (None for max/min)
    "strategy": "QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy",  # Optimization strategy
    "compileId": compile_id,  # Compilation ID for the optimization
    "parameters[0][key]": "ema_fast",  # First parameter key
    "parameters[0][min]": 100,  # Minimum value for first parameter
    "parameters[0][max]": 200,  # Maximum value for first parameter
    "parameters[0][step]": 50,  # Step size for first parameter
    "parameters[1][key]": "ema_slow",  # Second parameter key
    "parameters[1][min]": 200,  # Minimum value for second parameter
    "parameters[1][max]": 300,  # Maximum value for second parameter
    "parameters[1][step]": 50,  # Step size for second parameter
    "constraints": [{  # Constraints for the optimization
        "target": "TotalPerformance.PortfolioStatistics.SharpeRatio",
        "operator": "greater",
        "target-value": 1
    }]
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the estimated cost
if result['success']:
    print("Optimization Cost Estimated Successfully:")
    print(result)

### Create Optimization
# Send a POST request to the /optimizations/create endpoint to create an optimization
response = post(f'{BASE_URL}/optimizations/create', headers=get_headers(), json={
    "projectId": project_id,  # ID of the project
    "name": f"Optimization_{compileId[:5]}",  # Name of the optimization
    "target": "TotalPerformance.PortfolioStatistics.SharpeRatio",  # Optimization target
    "targetTo": "max",  # Direction to optimize
    "targetValue": None,  # Specific target value
    "strategy": "QuantConnect.Optimizer.Strategies.GridSearchOptimizationStrategy",  # Strategy
    "compileId": compile_id,  # Compilation ID
    "parameters[0][key]": "ema_fast",  # First parameter key
    "parameters[0][min]": 100,  # Minimum value
    "parameters[0][max]": 200,  # Maximum value
    "parameters[0][step]": 50,  # Step size
    "parameters[1][key]": "ema_slow",  # Second parameter key
    "parameters[1][min]": 200,  # Minimum value
    "parameters[1][max]": 300,  # Maximum value
    "parameters[1][step]": 50,  # Step size
    "constraints": [{  # Constraints
        "target": "TotalPerformance.PortfolioStatistics.SharpeRatio",
        "operator": "greater",
        "target-value": 1
    }],
    "estimatedCost": 10,  # Estimated cost of optimization
    "nodeType": "O2-8",  # Node type for optimization
    "parallelNodes": 4  # Number of parallel nodes
})
# Parse the JSON response into python managable dict
result = response.json()
# Extract the optimization ID from the response
optimization_id = result['optimizations'][0]['optimizationId']
# Check if the request was successful and print the result
if result['success']:
    print("Optimization Created Successfully:")
    print(result)

### Update Optimization
# Send a POST request to the /optimizations/update endpoint to update the optimization
response = post(f'{BASE_URL}/optimizations/update', headers=get_headers(), json={
    "optimizationId": optimization_id,  # ID of the optimization to update
    "name": f"Optimization_{optimizationId[:5]}"  # New name for the optimization
})
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the result
if result['success']:
    print("Optimization Updated Successfully:")
    print(result)

### Read Optimization
# Prepare data payload to read optimization details
payload = {
    "optimizationId": optimization_id  # ID of the optimization to read
}
# Send a POST request to the /optimizations/read endpoint to get details
response = post(f'{BASE_URL}/optimizations/read', headers=get_headers(), json=payload)
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the details
if result['success']:
    print("Optimization Details:")
    print(result)

### Abort Optimization
# Prepare data payload to abort the optimization
payload = {
    "optimizationId": optimization_id  # ID of the optimization to abort
}
# Send a POST request to the /optimizations/abort endpoint to abort
response = post(f'{BASE_URL}/optimizations/abort', headers=get_headers(), json=payload)
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the result
if result['success']:
    print("Optimization Aborted Successfully:")
    print(result)

### Delete Optimization
# Prepare data payload to delete the optimization
payload = {
    "optimizationId": optimization_id  # ID of the optimization to delete
}
# Send a POST request to the /optimizations/delete endpoint to delete
response = post(f'{BASE_URL}/optimizations/delete', headers=get_headers(), json=payload)
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the result
if result['success']:
    print("Optimization Deleted Successfully:")
    print(result)

### List Optimizations
# Prepare data payload to list optimizations
payload = {
    "projectId": project_id  # ID of the project
}
# Send a POST request to the /optimizations/list endpoint to list optimizations
response = post(f'{BASE_URL}/optimizations/list', headers=get_headers(), json=payload)
# Parse the JSON response into python managable dict
result = response.json()
# Check if the request was successful and print the list
if result['success']:
    print("List of Optimizations:")
    print(result)
```
