public void ThrowOnReinitialization() { int nextId = 1; Strategy.NewParameterSet += (s, parameterSet) => { Assert.AreEqual(nextId++, parameterSet.Id); }; var set1 = new HashSet <OptimizationParameter>() { new OptimizationStepParameter("ema-fast", 10, 100, 1) }; Strategy.Initialize(new Target("Profit", new Maximization(), null), new List <Constraint>(), set1, CreateSettings()); Strategy.PushNewResults(OptimizationResult.Initial); Assert.Greater(nextId, 1); var set2 = new HashSet <OptimizationParameter>() { new OptimizationStepParameter("ema-fast", 10, 100, 1), new OptimizationStepParameter("ema-slow", 10, 100, 2) }; Assert.Throws <InvalidOperationException>(() => { Strategy.Initialize(new Target("Profit", new Minimization(), null), null, set2, CreateSettings()); }); }
/// <summary> /// Starts the optimization /// </summary> public virtual void Start() { lock (RunningParameterSetForBacktest) { Strategy.PushNewResults(OptimizationResult.Initial); // if after we started there are no running parameter sets means we have failed to start if (RunningParameterSetForBacktest.Count == 0) { throw new InvalidOperationException($"LeanOptimizer.Start({GetLogDetails()}): failed to start"); } Log.Trace($"LeanOptimizer.Start({GetLogDetails()}): start ended. Waiting on {RunningParameterSetForBacktest.Count + PendingParameterSet.Count} backtests"); } SetOptimizationStatus(OptimizationStatus.Running); ProcessUpdate(forceSend: true); }