Lean  $LEAN_TAG$
Fundamental.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.IO;
19 
21 {
22  /// <summary>
23  /// Lean fundamental data class
24  /// </summary>
26  {
27  /// <summary>
28  /// Gets the day's dollar volume for this symbol
29  /// </summary>
30  public override double DollarVolume => FundamentalService.Get<double>(Time, Symbol.ID, FundamentalProperty.DollarVolume);
31 
32  /// <summary>
33  /// Gets the day's total volume
34  /// </summary>
35  public override long Volume => FundamentalService.Get<long>(Time, Symbol.ID, FundamentalProperty.Volume);
36 
37  /// <summary>
38  /// Returns whether the symbol has fundamental data for the given date
39  /// </summary>
40  public override bool HasFundamentalData => FundamentalService.Get<bool>(Time, Symbol.ID, FundamentalProperty.HasFundamentalData);
41 
42  /// <summary>
43  /// Gets the price factor for the given date
44  /// </summary>
45  public override decimal PriceFactor => FundamentalService.Get<decimal>(Time, Symbol.ID, FundamentalProperty.PriceFactor);
46 
47  /// <summary>
48  /// Gets the split factor for the given date
49  /// </summary>
50  public override decimal SplitFactor => FundamentalService.Get<decimal>(Time, Symbol.ID, FundamentalProperty.SplitFactor);
51 
52  /// <summary>
53  /// Gets the raw price
54  /// </summary>
55  public override decimal Value => FundamentalService.Get<decimal>(Time, Symbol.ID, FundamentalProperty.Value);
56 
57  /// <summary>
58  /// Creates a new empty instance
59  /// </summary>
60  public Fundamental()
61  {
62  }
63 
64  /// <summary>
65  /// Creates a new instance
66  /// </summary>
67  /// <param name="time">The current time</param>
68  /// <param name="symbol">The associated symbol</param>
69  public Fundamental(DateTime time, Symbol symbol)
70  : base(time, symbol)
71  {
72  }
73 
74  /// <summary>
75  /// Return the URL string source of the file. This will be converted to a stream
76  /// </summary>
77  public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
78  {
79  var path = Path.Combine(Globals.DataFolder, "equity", config.Market, "fundamental", "coarse", $"{date:yyyyMMdd}.csv");
80  return new SubscriptionDataSource(path, SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
81  }
82 
83  /// <summary>
84  /// Will read a new instance from the given line
85  /// </summary>
86  /// <param name="config">The associated requested configuration</param>
87  /// <param name="line">The line to parse</param>
88  /// <param name="date">The current time</param>
89  /// <param name="isLiveMode">True if live mode</param>
90  /// <returns>A new instance or null</returns>
91  public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
92  {
93  try
94  {
95  var csv = line.Split(',');
96  var sid = SecurityIdentifier.Parse(csv[0]);
97  // This use case/Reader implementation is only for history, where the user requests specific symbols only
98  // and because we use the same source file as the universe Fundamentals we need to filter out other symbols
99  if (sid == config.Symbol.ID)
100  {
101  return new Fundamental(date, new Symbol(sid, csv[1]));
102  }
103  }
104  catch
105  {
106  // pass
107  }
108  return null;
109  }
110 
111  /// <summary>
112  /// Will clone the current instance
113  /// </summary>
114  /// <returns>The cloned instance</returns>
115  public override BaseData Clone()
116  {
117  return new Fundamental(Time, Symbol);
118  }
119 
120  /// <summary>
121  /// Gets the default resolution for this data and security type
122  /// </summary>
123  public override Resolution DefaultResolution()
124  {
125  return Resolution.Daily;
126  }
127  }
128 }