Skip to content

LeanOptimizer

QuantConnect.Optimizer.LeanOptimizer

LeanOptimizer(node_packet: OptimizationNodePacket)

Bases: Object, IDisposable

Base Lean optimizer class in charge of handling an optimization job packet

Creates a new instance

This codeEntityType is protected.

Parameters:

Name Type Description Default
node_packet OptimizationNodePacket

The optimization node packet to handle

required

completed_backtests

completed_backtests: int

The total completed backtests count

This codeEntityType is protected.

status

The current optimization status

This codeEntityType is protected.

optimization_target

optimization_target: Target

The optimization target

This codeEntityType is protected.

running_parameter_set_for_backtest

running_parameter_set_for_backtest: ConcurrentDictionary[
    str, ParameterSet
]

Collection holding ParameterSet for each backtest id we are waiting to finish

This codeEntityType is protected.

pending_parameter_set

pending_parameter_set: ConcurrentQueue[ParameterSet]

Collection holding ParameterSet for each backtest id we are waiting to launch

This codeEntityType is protected.

strategy

The optimization strategy being used

This codeEntityType is protected.

node_packet

The optimization packet

This codeEntityType is protected.

disposed

disposed: bool

Indicates whether optimizer was disposed

This codeEntityType is protected.

ended

ended: _EventContainer[
    Callable[[Object, OptimizationResult], Any], Any
]

Event triggered when the optimization work ended

abort_lean

abort_lean(backtest_id: str) -> None

Handles stopping Lean process

This codeEntityType is protected.

Parameters:

Name Type Description Default
backtest_id str

Specified backtest id

required

dispose

dispose() -> None

Disposes of any resources

get_backtest_name

get_backtest_name(parameter_set: ParameterSet) -> str

Get's a new backtest name

This codeEntityType is protected.

get_current_estimate

get_current_estimate() -> int

Returns the current optimization status and strategy estimates

get_log_details

get_log_details() -> str

Helper method to have pretty more informative logs

This codeEntityType is protected.

get_runtime_statistics

get_runtime_statistics() -> Dictionary[str, str]

Get the current runtime statistics

new_result

new_result(
    json_backtest_result: str, backtest_id: str
) -> None

Handles a new backtest json result matching a requested backtest id

This codeEntityType is protected.

Parameters:

Name Type Description Default
json_backtest_result str

The backtest json result

required
backtest_id str

The associated backtest id

required

run_lean

run_lean(
    parameter_set: ParameterSet, backtest_name: str
) -> str

Handles starting Lean for a given parameter set

This codeEntityType is protected.

Parameters:

Name Type Description Default
parameter_set ParameterSet

The parameter set for the backtest to run

required
backtest_name str

The backtest name to use

required

Returns:

Type Description
str

The new unique backtest id.

send_update

send_update() -> None

Sends an update of the current optimization status to the user

This codeEntityType is protected.

set_optimization_status

set_optimization_status(
    optimization_status: OptimizationStatus,
) -> None

Sets the current optimization status

This codeEntityType is protected.

Parameters:

Name Type Description Default
optimization_status OptimizationStatus

The new optimization status

required

start

start() -> None

Starts the optimization

trigger_on_end_event

trigger_on_end_event() -> None

Triggers the optimization job end event

This codeEntityType is protected.