Lean  $LEAN_TAG$
Equity.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;
17 using QuantConnect.Data;
21 
23 {
24  /// <summary>
25  /// Equity Security Type : Extension of the underlying Security class for equity specific behaviours.
26  /// </summary>
27  /// <seealso cref="Security"/>
28  public class Equity : Security
29  {
30  /// <summary>
31  /// The default number of days required to settle an equity sale
32  /// </summary>
33  public const int DefaultSettlementDays = 2;
34 
35  /// <summary>
36  /// The default time of day for settlement
37  /// </summary>
38  public static readonly TimeSpan DefaultSettlementTime = new TimeSpan(8, 0, 0);
39 
40  /// <summary>
41  /// Checks if the equity is a shortable asset. Note that this does not
42  /// take into account any open orders or existing holdings. To check if the asset
43  /// is currently shortable, use QCAlgorithm's ShortableQuantity property instead.
44  /// </summary>
45  /// <returns>True if the security is a shortable equity</returns>
46  public bool Shortable
47  {
48  get
49  {
50  var shortableQuantity = ShortableProvider.ShortableQuantity(Symbol, LocalTime);
51  // null means we don't have the data
52  return shortableQuantity == null || shortableQuantity > 0m;
53  }
54  }
55 
56  /// <summary>
57  /// Gets the total quantity shortable for this security. This does not take into account
58  /// any open orders or existing holdings. To check the asset's currently shortable quantity,
59  /// use QCAlgorithm's ShortableQuantity property instead.
60  /// </summary>
61  /// <returns>Zero if not shortable, null if infinitely shortable, or a number greater than zero if shortable</returns>
62  public long? TotalShortableQuantity => ShortableProvider.ShortableQuantity(Symbol, LocalTime);
63 
64  /// <summary>
65  /// Equity primary exchange.
66  /// </summary>
67  public Exchange PrimaryExchange { get; }
68 
69  /// <summary>
70  /// Construct the Equity Object
71  /// </summary>
72  public Equity(Symbol symbol,
73  SecurityExchangeHours exchangeHours,
74  Cash quoteCurrency,
75  SymbolProperties symbolProperties,
76  ICurrencyConverter currencyConverter,
78  SecurityCache securityCache,
79  Exchange primaryExchange = null)
80  : base(symbol,
81  quoteCurrency,
82  symbolProperties,
83  new EquityExchange(exchangeHours),
84  securityCache,
86  new EquityFillModel(),
88  NullSlippageModel.Instance,
90  Securities.VolatilityModel.Null,
91  new SecurityMarginModel(2m),
92  new EquityDataFilter(),
94  currencyConverter,
95  registeredTypes,
96  Securities.MarginInterestRateModel.Null
97  )
98  {
99  Holdings = new EquityHolding(this, currencyConverter);
100  PrimaryExchange = primaryExchange ?? QuantConnect.Exchange.UNKNOWN;
101  }
102 
103  /// <summary>
104  /// Construct the Equity Object
105  /// </summary>
106  public Equity(SecurityExchangeHours exchangeHours,
107  SubscriptionDataConfig config,
108  Cash quoteCurrency,
109  SymbolProperties symbolProperties,
110  ICurrencyConverter currencyConverter,
111  IRegisteredSecurityDataTypesProvider registeredTypes,
112  Exchange primaryExchange = null)
113  : base(
114  config,
115  quoteCurrency,
116  symbolProperties,
117  new EquityExchange(exchangeHours),
118  new EquityCache(),
120  new EquityFillModel(),
122  NullSlippageModel.Instance,
124  Securities.VolatilityModel.Null,
125  new SecurityMarginModel(2m),
126  new EquityDataFilter(),
128  currencyConverter,
129  registeredTypes,
130  Securities.MarginInterestRateModel.Null
131  )
132  {
133  Holdings = new EquityHolding(this, currencyConverter);
134  PrimaryExchange = primaryExchange ?? QuantConnect.Exchange.UNKNOWN;;
135  }
136 
137  /// <summary>
138  /// Sets the data normalization mode to be used by this security
139  /// </summary>
141  {
142  base.SetDataNormalizationMode(mode);
143 
144  if (mode == DataNormalizationMode.Adjusted)
145  {
147  }
148  else
149  {
151  }
152  }
153  }
154 }