Lean  $LEAN_TAG$
OptimizationParameter.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 Newtonsoft.Json;
17 
19 {
20  /// <summary>
21  /// Defines the optimization parameter meta information
22  /// </summary>
23  [JsonConverter(typeof(OptimizationParameterJsonConverter))]
24  public abstract class OptimizationParameter
25  {
26  /// <summary>
27  /// Name of optimization parameter
28  /// </summary>
29  [JsonProperty("name")]
30  public string Name { get; }
31 
32  /// <summary>
33  /// Create an instance of <see cref="OptimizationParameter"/> based on configuration
34  /// </summary>
35  /// <param name="name">parameter name</param>
36  protected OptimizationParameter(string name)
37  {
38  Name = name;
39  }
40 
41  /// <summary>
42  /// Indicates whether the current object is equal to another object of the same type.
43  /// </summary>
44  /// <param name="other">An object to compare with this object.</param>
45  /// <returns>
46  /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
47  /// </returns>
48  public bool Equals(OptimizationParameter other)
49  {
50  if (ReferenceEquals(null, other)) return false;
51  if (ReferenceEquals(this, other)) return true;
52  return string.Equals(Name, other?.Name);
53  }
54 
55  /// <summary>
56  /// Determines whether the specified object is equal to the current object.
57  /// </summary>
58  /// <param name="obj">The object to compare with the current object. </param>
59  /// <returns>
60  /// true if the specified object is equal to the current object; otherwise, false.
61  /// </returns>
62  public override bool Equals(object obj)
63  {
64  return Equals(obj as OptimizationParameter);
65  }
66 
67  /// <summary>
68  /// Serves as the default hash function.
69  /// </summary>
70  /// <returns>
71  /// A hash code for the current object.
72  /// </returns>
73  public override int GetHashCode() => this.Name.GetHashCode();
74  }
75 }