/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.IO;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Data.Fundamental
{
///
/// Lean fundamental data class
///
public class Fundamental : FineFundamental
{
///
/// Gets the day's dollar volume for this symbol
///
public override double DollarVolume => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.DollarVolume);
///
/// Gets the day's total volume
///
public override long Volume => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.Volume);
///
/// Returns whether the symbol has fundamental data for the given date
///
public override bool HasFundamentalData => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.HasFundamentalData);
///
/// Gets the price factor for the given date
///
public override decimal PriceFactor => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.PriceFactor);
///
/// Gets the split factor for the given date
///
public override decimal SplitFactor => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.SplitFactor);
///
/// Gets the raw price
///
public override decimal Value => FundamentalService.Get(Time, Symbol.ID, FundamentalProperty.Value);
///
/// Creates a new empty instance
///
public Fundamental()
{
}
///
/// Creates a new instance
///
/// The current time
/// The associated symbol
public Fundamental(DateTime time, Symbol symbol)
: base(time, symbol)
{
}
///
/// Return the URL string source of the file. This will be converted to a stream
///
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
var path = Path.Combine(Globals.DataFolder, "equity", config.Market, "fundamental", "coarse", $"{date:yyyyMMdd}.csv");
return new SubscriptionDataSource(path, SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
}
///
/// Will read a new instance from the given line
///
/// The associated requested configuration
/// The line to parse
/// The current time
/// True if live mode
/// A new instance or null
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
try
{
var csv = line.Split(',');
var sid = SecurityIdentifier.Parse(csv[0]);
// This use case/Reader implementation is only for history, where the user requests specific symbols only
// and because we use the same source file as the universe Fundamentals we need to filter out other symbols
if (sid == config.Symbol.ID)
{
return new Fundamental(date, new Symbol(sid, csv[1]));
}
}
catch
{
// pass
}
return null;
}
///
/// Will clone the current instance
///
/// The cloned instance
public override BaseData Clone()
{
return new Fundamental(Time, Symbol);
}
///
/// Gets the default resolution for this data and security type
///
public override Resolution DefaultResolution()
{
return Resolution.Daily;
}
}
}