Lean  $LEAN_TAG$
Position.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 
17 {
18  /// <summary>
19  /// Defines a quantity of a security's holdings for inclusion in a position group
20  /// </summary>
21  public class Position : IPosition
22  {
23  /// <summary>
24  /// The symbol
25  /// </summary>
26  public Symbol Symbol { get; }
27 
28  /// <summary>
29  /// The quantity
30  /// </summary>
31  public decimal Quantity { get; }
32 
33  /// <summary>
34  /// The unit quantity. The unit quantities of a group define the group. For example, a covered
35  /// call has 100 units of stock and -1 units of call contracts.
36  /// </summary>
37  public decimal UnitQuantity { get; }
38 
39  /// <summary>
40  /// Initializes a new instance of the <see cref="Position"/> class
41  /// </summary>
42  /// <param name="symbol">The symbol</param>
43  /// <param name="quantity">The quantity</param>
44  /// <param name="unitQuantity">The position's unit quantity within its group</param>
45  public Position(Symbol symbol, decimal quantity, decimal unitQuantity)
46  {
47  Symbol = symbol;
48  Quantity = quantity;
49  UnitQuantity = unitQuantity;
50  }
51 
52  /// <summary>
53  /// Initializes a new instance of the <see cref="Position"/> class using the security's lot size
54  /// as it's unit quantity. If quantity is null, then the security's holdings quantity is used.
55  /// </summary>
56  /// <param name="security">The security</param>
57  /// <param name="quantity">The quantity, if null, the security's holdings quantity is used</param>
58  public Position(Security security, decimal? quantity = null)
59  : this(security.Symbol, quantity ?? security.Holdings.Quantity, security.SymbolProperties.LotSize)
60  {
61  }
62 
63  /// <summary>Returns a string that represents the current object.</summary>
64  /// <returns>A string that represents the current object.</returns>
65  public override string ToString()
66  {
67  return $"{Symbol}: {Quantity}";
68  }
69  }
70 }