Lean  $LEAN_TAG$
CoarseFundamental.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 System.Linq;
18 using System.Globalization;
19 
21 {
22  /// <summary>
23  /// Defines summary information about a single symbol for a given date
24  /// </summary>
25  public class CoarseFundamental : BaseData
26  {
27  /// <summary>
28  /// Gets the market for this symbol
29  /// </summary>
30  public string Market => Symbol.ID.Market;
31 
32  /// <summary>
33  /// Gets the day's dollar volume for this symbol
34  /// </summary>
35  public virtual double DollarVolume { get; }
36 
37  /// <summary>
38  /// Gets the day's total volume
39  /// </summary>
40  public virtual long Volume { get; }
41 
42  /// <summary>
43  /// Returns whether the symbol has fundamental data for the given date
44  /// </summary>
45  public virtual bool HasFundamentalData { get; }
46 
47  /// <summary>
48  /// Gets the price factor for the given date
49  /// </summary>
50  public virtual decimal PriceFactor { get; } = 1;
51 
52  /// <summary>
53  /// Gets the split factor for the given date
54  /// </summary>
55  public virtual decimal SplitFactor { get; } = 1;
56 
57  /// <summary>
58  /// Gets the combined factor used to create adjusted prices from raw prices
59  /// </summary>
61 
62  /// <summary>
63  /// Gets the split and dividend adjusted price
64  /// </summary>
65  public decimal AdjustedPrice => Price * PriceScaleFactor;
66 
67  /// <summary>
68  /// The end time of this data.
69  /// </summary>
70  public override DateTime EndTime
71  {
72  get { return Time + QuantConnect.Time.OneDay; }
73  set { Time = value - QuantConnect.Time.OneDay; }
74  }
75 
76  /// <summary>
77  /// Gets the raw price
78  /// </summary>
79  public override decimal Price => Value;
80 
81  /// <summary>
82  /// Initializes a new instance of the <see cref="CoarseFundamental"/> class
83  /// </summary>
85  {
86  }
87 
88  /// <summary>
89  /// Return the URL string source of the file. This will be converted to a stream
90  /// </summary>
91  /// <param name="config">Configuration object</param>
92  /// <param name="date">Date of this source file</param>
93  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
94  /// <returns>String URL of source file.</returns>
95  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
96  {
97  throw new InvalidOperationException($"Coarse type is obsolete, please use {nameof(Fundamental)}");
98  }
99 
100  /// <summary>
101  /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
102  /// each time it is called.
103  /// </summary>
104  /// <param name="config">Subscription data config setup object</param>
105  /// <param name="line">Line of the source document</param>
106  /// <param name="date">Date of the requested data</param>
107  /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
108  /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
109  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
110  {
111  throw new InvalidOperationException($"Coarse type is obsolete, please use {nameof(Fundamental)}");
112  }
113 
114  /// <summary>
115  /// Converts a given fundamental data point into row format
116  /// </summary>
117  public static string ToRow(CoarseFundamental coarse)
118  {
119  // sid,symbol,close,volume,dollar volume,has fundamental data,price factor,split factor
120  var values = new object[]
121  {
122  coarse.Symbol.ID,
123  coarse.Symbol.Value,
124  coarse.Value,
125  coarse.Volume,
126  coarse.DollarVolume,
127  coarse.HasFundamentalData,
128  coarse.PriceFactor,
129  coarse.SplitFactor
130  };
131 
132  return string.Join(",", values.Select(s => Convert.ToString(s, CultureInfo.InvariantCulture)));
133  }
134  }
135 }