Optimization analysis fails on parameter points revisited by Euler search

オープン
#10,057 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
54/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
backend, data

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C#
スター
22.6k
フォーク
5.4k
平均マージ
11時間 39分
マージ済み PR(30日)
104

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

QuantConnect/Lean のほかの issue

QuantConnect/Lean の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。