16 using Newtonsoft.Json;
24 using System.Collections.Generic;
27 using System.Threading;
33 public static void Main(
string[] args)
41 using var endedEvent =
new ManualResetEvent(
false);
49 var optimizationStrategyName =
Config.
Get(
"optimization-strategy",
50 "QuantConnect.Optimizer.GridSearchOptimizationStrategy");
52 var optimizationId =
Config.
Get(
"optimization-id", Guid.NewGuid().ToString());
55 OptimizationId = optimizationId,
56 OptimizationStrategy = optimizationStrategyName,
58 "optimization-strategy-settings",
59 "{\"$type\":\"QuantConnect.Optimizer.Strategies.OptimizationStrategySettings, QuantConnect.Optimizer\"}"),
new JsonSerializerSettings(){TypeNameHandling = TypeNameHandling.All}),
60 Criterion = JsonConvert.DeserializeObject<
Target>(
Config.
Get(
"optimization-criterion",
"{\"target\":\"Statistics.TotalProfit\", \"extremum\": \"max\"}")),
61 Constraints = JsonConvert.DeserializeObject<List<Constraint>>(
Config.
Get(
"constraints",
"[]")).AsReadOnly(),
62 OptimizationParameters = JsonConvert.DeserializeObject<HashSet<OptimizationParameter>>(
Config.
Get(
"parameters",
"[]")),
63 MaximumConcurrentBacktests =
Config.
GetInt(
"maximum-concurrent-backtests", Math.Max(1, Environment.ProcessorCount / 2)),
67 var outOfSampleMaxEndDate =
Config.
Get(
"out-of-sample-max-end-date");
68 if (!
string.IsNullOrEmpty(outOfSampleMaxEndDate))
70 packet.OutOfSampleMaxEndDate =
Time.
ParseDate(outOfSampleMaxEndDate);
72 packet.OutOfSampleDays =
Config.
GetInt(
"out-of-sample-days");
79 var backtestsCount = optimizer.GetCurrentEstimate();
80 Log.
Trace($
"Optimization estimate: {backtestsCount}");
82 optimizer.DisposeSafely();
89 optimizer.Ended += (s, e) =>
91 optimizer.DisposeSafely();
102 endedEvent.WaitOne();