Optimization analysis fails on parameter points revisited by Euler search
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 54/100
Research direction
Start in Optimizer/Analysis/OptimizationModes.cs at the ToDictionary call in OptimizationModes.Find, then read the analysis flow through OptimizationAnalyzer.Run and LeanOptimizer.TriggerOnEndEvent. Add coverage for duplicate coordinates and overlapping Euler passes, including repeated coordinates with different metrics; done means successful final analysis with the chosen representation policy explicit in tests.
Written by the indexing model from the issue text.
Description
Problem
The final optimization analysis throws when multiple backtests have the same parameter coordinates. Euler search legitimately revisits points from its coarse pass during refinement, so a completed Euler optimization can lose its aggregate analysis even when every backtest succeeds.
OptimizationModes.Find builds a dictionary of grid coordinates using indexed.ToDictionary(...) in Optimizer/Analysis/OptimizationModes.cs:66. Repeated coordinates cause ArgumentException. LeanOptimizer.TriggerOnEndEvent catches the exception and completes the optimization, but the final analysis is not assigned.
This is existing behavior on master; it does not require automatically calculated steps.
Minimal reproduction
using System.Collections.Generic;
using QuantConnect.Optimizer;
using QuantConnect.Optimizer.Analysis;
using QuantConnect.Optimizer.Parameters;
using QuantConnect.Statistics;
var backtests = new List<OptimizationBacktestMetrics>
{
new()
{
BacktestId = "coarse",
Parameters = new Dictionary<string, decimal> { ["x"] = 1m },
SharpeRatio = 1m,
TotalPerformance = new AlgorithmPerformance()
},
new()
{
BacktestId = "refined",
Parameters = new Dictionary<string, decimal> { ["x"] = 1m },
SharpeRatio = 1m,
TotalPerformance = new AlgorithmPerformance()
}
};
var parameters = new HashSet<OptimizationParameter>
{
new OptimizationStepParameter("x", 1m, 2m, 1m)
};
new OptimizationAnalyzer().Run(
new OptimizationAnalysisRunParameters(backtests, parameters));
Observed:
System.ArgumentException: An item with the same key has already been added. Key: 0
at QuantConnect.Optimizer.Analysis.OptimizationModes.Find(...)
at QuantConnect.Optimizer.Analysis.OptimizationAnalyzer.Run(...)
Also reproduced end to end with ParameterizedAlgorithm: Euler search with ema-fast 10..30, step 10, minimum step 5, and ema-slow fixed at 50 produces a three-backtest coarse pass followed by five refined backtests. All eight backtests complete successfully. The repeated points (10,50), (20,50), and (30,50) then trigger the duplicate-key error during final analysis.
Expected behavior
Repeated parameter coordinates must not prevent analysis of an otherwise successful optimization. Define how repeated observations are represented when finding modes, and add coverage for duplicate coordinates and overlapping Euler passes. Any aggregation or representative-selection policy should be explicit and tested, including repeated coordinates with different metrics.
- Dominant language
- C#
- Stars
- 22.6k
- Forks
- 5.4k
- Avg merge
- 11h 39m
- Merged PRs (30d)
- 104
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QuantConnect/Lean
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
QuantConnect/Lean#10216 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10206 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
QuantConnect/Lean#10199 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
QuantConnect/Lean#10198 ·
Maintainers usually reply within 1 day
-
priority:p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
QuantConnect/Lean#10197 ·
Maintainers usually reply within 1 day
All issues in QuantConnect/Lean
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainers usually reply within 1 day
-
triage/untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
unoplatform/uno#26676 ·
Maintainers usually reply within 1 day
-
.NET bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
jhaizhou-ops/S2Arm#2177 · 3 comments ·
Maintainers usually reply within 1 day
-
area-CodeGen-coreclr untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/runtime#138181 · 1 comment ·
Maintainers usually reply within 1 day