Lean  $LEAN_TAG$
ParameterSet.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System.Linq;
17 using Newtonsoft.Json;
18 using QuantConnect.Api;
19 using QuantConnect.Util;
20 using System.Collections.Generic;
21 
23 {
24  /// <summary>
25  /// Represents a single combination of optimization parameters
26  /// </summary>
27  [JsonConverter(typeof(ParameterSetJsonConverter))]
28  public class ParameterSet
29  {
30  /// <summary>
31  /// The unique identifier within scope (current optimization job)
32  /// </summary>
33  /// <remarks>Internal id, useful for the optimization strategy to id each generated parameter sets,
34  /// even before there is any backtest id</remarks>
35  [JsonProperty(PropertyName = "id")]
36  public int Id { get; }
37 
38  /// <summary>
39  /// Represent a combination as key value of parameters, i.e. order doesn't matter
40  /// </summary>
41  [JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Ignore)]
42  public IReadOnlyDictionary<string, string> Value { get; }
43 
44  /// <summary>
45  /// Creates an instance of <see cref="ParameterSet"/> based on new combination of optimization parameters
46  /// </summary>
47  /// <param name="id">Unique identifier</param>
48  /// <param name="value">Combination of optimization parameters</param>
49  public ParameterSet(int id, IReadOnlyDictionary<string, string> value)
50  {
51  Id = id;
52  Value = value;
53  }
54 
55  /// <summary>
56  /// String representation of this parameter set
57  /// </summary>
58  public override string ToString()
59  {
60  return string.Join(',', Value.OrderBy(kvp => kvp.Key).Select(arg => $"{arg.Key}:{arg.Value}"));
61  }
62  }
63 }