Skip to content

BacktestingSetupHandler

QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler

BacktestingSetupHandler()

Bases: Object, ISetupHandler

Backtesting setup handler processes the algorithm initialize method and sets up the internal state of the algorithm class.

Initialize the backtest setup handler.

initialization_time_out

initialization_time_out: timedelta

Get the maximum time that the initialization of an algorithm can take

This codeEntityType is protected.

algorithm_creation_timeout

algorithm_creation_timeout: timedelta

Get the maximum time that the creation of an algorithm can take

This codeEntityType is protected.

worker_thread

worker_thread: WorkerThread

The worker thread instance the setup handler should use

errors

errors: List[Exception]

Internal errors list from running the setup procedures.

maximum_runtime

maximum_runtime: timedelta

Maximum runtime of the algorithm in seconds.

starting_portfolio_value

starting_portfolio_value: float

Starting capital according to the users initialize routine.

starting_date

starting_date: datetime

Start date for analysis loops to search for data.

max_orders

max_orders: int

Maximum number of orders for this backtest.

create_algorithm_instance

create_algorithm_instance(
    algorithm_node_packet: AlgorithmNodePacket,
    assembly_path: str,
) -> IAlgorithm

Create a new instance of an algorithm from a physical dll path.

Parameters:

Name Type Description Default
assembly_path str

The path to the assembly's location

required
algorithm_node_packet AlgorithmNodePacket

Details of the task required

required

Returns:

Type Description
IAlgorithm

A new instance of IAlgorithm, or throws an exception if there was an error.

create_brokerage

create_brokerage(
    algorithm_node_packet: AlgorithmNodePacket,
    uninitialized_algorithm: IAlgorithm,
    factory: Optional[IBrokerageFactory],
) -> Tuple[IBrokerage, IBrokerageFactory]

Creates a new BacktestingBrokerage instance

Parameters:

Name Type Description Default
algorithm_node_packet AlgorithmNodePacket

Job packet

required
uninitialized_algorithm IAlgorithm

The algorithm instance before Initialize has been called

required
factory Optional[IBrokerageFactory]

The brokerage factory

required

Returns:

Type Description
Tuple[IBrokerage, IBrokerageFactory]

The brokerage instance, or throws if error creating instance.

dispose

dispose() -> None

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

setup

setup(parameters: SetupHandlerParameters) -> bool

Setup the algorithm cash, dates and data subscriptions as desired.

Parameters:

Name Type Description Default
parameters SetupHandlerParameters

The parameters object to use

required

Returns:

Type Description
bool

Boolean true on successfully initializing the algorithm.