AlgorithmSpeedAnalysis
QuantConnect.Lean.Engine.Results.Analysis.Analyses.AlgorithmSpeedAnalysis
Bases: BaseResultsAnalysis
Tracks the algorithm's execution speed from the throughput and progress metrics accumulated by AlgorithmSpeedTracker, reporting slow processing speed, a long projected remaining runtime, degrading throughput, and history-request-dominated data loads. It runs periodically while the backtest is in progress, so the user can decide to stop a slow backtest early, and again on the final analysis against the whole run's metrics. When the tracked metrics cannot measure the processing speed, the engine's completion log line is parsed for the whole-run average rate as a fallback; the line only exists once the backtest ends, so the fallback can only fire on the final analysis. Benchmark speeds: https://www.quantconnect.com/performance
SLOW_DATA_POINTS_PER_SECOND
SLOW_DATA_POINTS_PER_SECOND: int = ...
The data points per second under which execution is reported as slow, from the platform benchmarks.
MINIMUM_COMPLETED_RUNTIME_SECONDS
MINIMUM_COMPLETED_RUNTIME_SECONDS: int = 10
The minimum runtime a completed backtest must have for its whole-run average rate, parsed from the completion log line, to be worth reporting as slow.
DEGRADATION_RATIO
DEGRADATION_RATIO: float = 0.5
The recent-to-initial throughput ratio under which throughput is reported as degrading.
HIGH_HISTORY_DATA_POINTS_SHARE
HIGH_HISTORY_DATA_POINTS_SHARE: float = 0.5
The share of recently processed data points served by the history provider over which the data load is reported as history-request dominated.
MINIMUM_RECENT_HISTORY_DATA_POINTS
MINIMUM_RECENT_HISTORY_DATA_POINTS: int = ...
The minimum number of history data points in the recent window for the history-request load to be worth reporting.
MINIMUM_SAMPLED_SPAN
MINIMUM_SAMPLED_SPAN: timedelta = ...
The minimum wall-clock span the metrics must cover before any finding is reported, so early warm-up noise doesn't produce false positives.
LONG_PROJECTED_REMAINING_TIME
LONG_PROJECTED_REMAINING_TIME: timedelta = ...
The projected remaining runtime over which the backtest is reported as long-running.
SLOW_EXECUTION_NAME
SLOW_EXECUTION_NAME: str = 'SlowExecution'
The name of the slow execution sub-finding.
LONG_PROJECTED_RUNTIME_NAME
LONG_PROJECTED_RUNTIME_NAME: str = 'LongProjectedRuntime'
The name of the long projected runtime sub-finding.
THROUGHPUT_DEGRADATION_NAME
THROUGHPUT_DEGRADATION_NAME: str = 'ThroughputDegradation'
The name of the degrading throughput sub-finding.
HISTORY_REQUEST_LOAD_NAME
HISTORY_REQUEST_LOAD_NAME: str = 'HistoryRequestLoad'
The name of the history-request load sub-finding.
is_state_based
is_state_based: bool
This analysis reads the current speed metrics instead of scanning the order event and log streams, so its in-run findings are replaced on every run.
issue
issue: str
Gets the description of the slow algorithm issue.
weight
weight: int
Gets the severity weight for the algorithm speed analysis. High enough to run before the order-response error analyses in the in-run chain: this analysis drives the user's decision to stop a slow backtest, and it is one of the cheapest in the set, so it should not be the one skipped when the time limit or the failed-analyses cap truncates a run.
runs_in_run
runs_in_run: bool
Whether this analysis can also run while the backtest is still in progress, against a snapshot of the intermediate results. Most analyses read only the result snapshot, so this defaults to true. Analyses that need the completed run (runtime errors, equity curves, final statistics, completion logs) or that read algorithm state that is not safe to access while it runs override this to leave them to the final analysis only.
run
run(
parameters: ResultsAnalysisRunParameters,
) -> Sequence[Analysis]
run(
speed: AlgorithmSpeedTracker, logs: Sequence[str] = None
) -> Sequence[Analysis]
Signature descriptions:
-
Runs the algorithm speed analysis against the speed metrics tracked for the backtest, falling back to the completion log line when they cannot measure the speed.
-
Runs the algorithm speed analysis against the given speed metrics. Each detected condition is reported as its own sub-finding. Every condition must hold for both the current recent window and the window as of the previous run, so a single noisy sample doesn't flag or clear a finding. When the metrics cannot measure the processing speed — the tracker isn't wired in, the backtest finished before it got enough samples, or the data point counters aren't fed — the completion log line's whole-run average is used to detect slow execution instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
speed
|
Optional[AlgorithmSpeedTracker]
|
The speed metrics tracked for the running backtest, or null when not tracked. |
None
|
logs
|
Optional[Sequence[str]]
|
The log lines to search for the completion line, or null when not available. |
None
|
Returns:
| Type | Description |
|---|---|
Sequence[Analysis]
|
The failed sub-findings, or empty when no speed condition failed or none could be measured. |
single_response
single_response(
sample: Any, solutions: Sequence[str] = None
) -> Sequence[Analysis]
single_response(
sample: Any,
count: Optional[int],
solutions: Sequence[str] = None,
) -> Sequence[Analysis]
Wraps a single QuantConnect.Analysis in a one-element read-only list.
create_aggregated_response
Filters responses to those with solutions, prefixes the class name, and returns a flat list.
This Class is protected.
format_code
format_code(code: str, language: Language) -> str
Formats the specified code string according to the conventions of the given programming language.
This Class is protected.