/*
* 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.Collections.Generic;
using Python.Runtime;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Data.Fundamental
{
///
/// Lean fundamentals universe data class
///
[Obsolete("'Fundamentals' was renamed to 'FundamentalUniverse'")]
public class Fundamentals : FundamentalUniverse { }
///
/// Lean fundamentals universe data class
///
public class FundamentalUniverse : BaseDataCollection
{
private static readonly Fundamental _factory = new();
///
/// Creates a new instance
///
public FundamentalUniverse()
{
}
///
/// Creates a new instance
///
/// The current time
/// The associated symbol
public FundamentalUniverse(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 = _factory.GetSource(config, date, isLiveMode).Source;
return new SubscriptionDataSource(path, SubscriptionTransportMedium.LocalFile, FileFormat.FoldingCollection);
}
///
/// 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 symbol = new Symbol(SecurityIdentifier.Parse(csv[0]), csv[1]);
return new Fundamental(date, symbol);
}
catch (Exception)
{
return null;
}
}
///
/// Will clone the current instance
///
/// The cloned instance
public override BaseData Clone()
{
return new FundamentalUniverse(Time, Symbol) { Data = Data, EndTime = EndTime };
}
///
/// Gets the default resolution for this data and security type
///
/// This is a method and not a property so that python
/// custom data types can override it
public override Resolution DefaultResolution()
{
return Resolution.Daily;
}
///
/// Creates the universe symbol for the target market
///
/// The universe symbol to use
public override Symbol UniverseSymbol(string market = null)
{
market ??= QuantConnect.Market.USA;
var ticker = $"{GetType().Name}-{market}-{Guid.NewGuid()}";
return Symbol.Create(ticker, SecurityType.Equity, market, baseDataType: GetType());
}
///
/// Creates a new fundamental universe for the USA market
///
/// The selector function
/// The universe settings to use, will default to algorithms if not provided
/// A configured new universe instance
public static FundamentalUniverseFactory USA(Func, IEnumerable> selector, UniverseSettings universeSettings = null)
{
return new FundamentalUniverseFactory(QuantConnect.Market.USA, universeSettings, selector);
}
///
/// Creates a new fundamental universe for the USA market
///
/// The selector function
/// The universe settings to use, will default to algorithms if not provided
/// A configured new universe instance
public static FundamentalUniverseFactory USA(PyObject selector, UniverseSettings universeSettings = null)
{
return new FundamentalUniverseFactory(QuantConnect.Market.USA, universeSettings, selector);
}
///
/// Creates a new fundamental universe for the USA market
///
/// The selector function
/// The universe settings to use, will default to algorithms if not provided
/// A configured new universe instance
public static FundamentalUniverseFactory USA(Func, object> selector, UniverseSettings universeSettings = null)
{
return new FundamentalUniverseFactory(QuantConnect.Market.USA, universeSettings, selector);
}
}
}