/// <summary> /// Initializes a new instance of the <see cref="UniverseSelectionEventArgs"/> class /// </summary> /// <param name="universe">The universe that raised this event</param> /// <param name="configuration">Theconfiguration for the data</param> /// <param name="dateTimeUtc">The date time this event was fired in UTC</param> /// <param name="data">The data contained within this event</param> public UniverseSelectionEventArgs(Universe universe, SubscriptionDataConfig configuration, DateTime dateTimeUtc, IReadOnlyList<BaseData> data) { Universe = universe; Configuration = configuration; DateTimeUtc = dateTimeUtc; Data = data; }
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { // this file is only a few seconds worth of data, so it's quick to download var remoteFileSource = @"http://www.quantconnect.com/live-test?type=file&symbols=" + config.Symbol.Value; remoteFileSource = @"http://beta.quantconnect.com/live-test?type=file&symbols=" + config.Symbol.Value; return new SubscriptionDataSource(remoteFileSource, SubscriptionTransportMedium.RemoteFile, FileFormat.Csv); }
/// <summary> /// Initializes a new instance of the <see cref="ZipEntryNameSubscriptionFactory"/> class /// </summary> /// <param name="config">The subscription's configuration</param> /// <param name="dateTime">The date this factory was produced to read data for</param> /// <param name="isLiveMode">True if we're in live mode, false for backtesting</param> public ZipEntryNameSubscriptionFactory(SubscriptionDataConfig config, DateTime dateTime, bool isLiveMode) { _config = config; _dateTime = dateTime; _isLiveMode = isLiveMode; _factory = (BaseData) Activator.CreateInstance(config.Type); }
public void PerformsLimitFillSell() { var model = new SecurityTransactionModel(); var order = new LimitOrder(Symbol, -100, 101.5m, DateTime.Now, type: SecurityType.Equity); var config = new SubscriptionDataConfig(typeof(TradeBar), SecurityType.Equity, Symbol, Resolution.Minute, true, true, true, true, false, 0); var security = new Security(config, 1); security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 101m)); var fill = model.LimitFill(security, order); Assert.AreEqual(0, fill.FillQuantity); Assert.AreEqual(0, fill.FillPrice); Assert.AreEqual(OrderStatus.None, fill.Status); Assert.AreEqual(OrderStatus.None, order.Status); security.SetMarketPrice(DateTime.Now, new TradeBar(DateTime.Now, Symbol, 102m, 103m, 101m, 102.3m, 100)); fill = model.LimitFill(security, order); // this fills worst case scenario, so it's at the limit price Assert.AreEqual(order.Quantity, fill.FillQuantity); Assert.AreEqual(Math.Max(order.LimitPrice, security.Low), fill.FillPrice); Assert.AreEqual(OrderStatus.Filled, fill.Status); Assert.AreEqual(OrderStatus.Filled, order.Status); }
/// <summary> /// Initializes a new instance of the <see cref="StreamStore"/> class /// </summary> /// <param name="config">The subscripton's configuration</param> /// <param name="security">The security object, used for exchange hours</param> public StreamStore(SubscriptionDataConfig config, Security security) { _security = security; _config = config; _increment = config.Increment; _queue = new ConcurrentQueue<BaseData>(); }
/// <summary> /// Initializes a new instance of the <see cref="FundamentalEventArgs"/> class /// </summary> /// <param name="fundamentalType">The type of fundamental data</param> /// <param name="configuration">Theconfiguration for the data</param> /// <param name="dateTimeUtc">The date time this event was fired in UTC</param> /// <param name="data">The data contained within this event</param> public FundamentalEventArgs(FundamentalType fundamentalType, SubscriptionDataConfig configuration, DateTime dateTimeUtc, IReadOnlyList<BaseData> data) { FundamentalType = fundamentalType; Configuration = configuration; DateTimeUtc = dateTimeUtc; Data = data; }
/// <summary> /// Creates an enumerator to read the specified request /// </summary> /// <param name="request">The subscription request to be read</param> /// <param name="dataFileProvider">Provider used to get data when it is not present on disk</param> /// <returns>An enumerator reading the subscription request</returns> public IEnumerator<BaseData> CreateEnumerator(SubscriptionRequest request, IDataFileProvider dataFileProvider) { var tradableDays = _tradableDaysProvider(request); var fineFundamental = new FineFundamental(); var fineFundamentalConfiguration = new SubscriptionDataConfig(request.Configuration, typeof(FineFundamental), request.Security.Symbol); return ( from date in tradableDays let fineFundamentalSource = GetSource(fineFundamental, fineFundamentalConfiguration, date) let fineFundamentalFactory = SubscriptionDataSourceReader.ForSource(fineFundamentalSource, dataFileProvider, fineFundamentalConfiguration, date, false) let fineFundamentalForDate = (FineFundamental)fineFundamentalFactory.Read(fineFundamentalSource).FirstOrDefault() select new FineFundamental { DataType = MarketDataType.Auxiliary, Symbol = request.Configuration.Symbol, Time = date, CompanyReference = fineFundamentalForDate != null ? fineFundamentalForDate.CompanyReference : new CompanyReference(), SecurityReference = fineFundamentalForDate != null ? fineFundamentalForDate.SecurityReference : new SecurityReference(), FinancialStatements = fineFundamentalForDate != null ? fineFundamentalForDate.FinancialStatements : new FinancialStatements(), EarningReports = fineFundamentalForDate != null ? fineFundamentalForDate.EarningReports : new EarningReports(), OperationRatios = fineFundamentalForDate != null ? fineFundamentalForDate.OperationRatios : new OperationRatios(), EarningRatios = fineFundamentalForDate != null ? fineFundamentalForDate.EarningRatios : new EarningRatios(), ValuationRatios = fineFundamentalForDate != null ? fineFundamentalForDate.ValuationRatios : new ValuationRatios() } ).GetEnumerator(); }
public void UpdatesAfterCorrectPeriodElapses() { const int periods = 3; var periodSpan = Time.OneMinute; var reference = new DateTime(2016, 04, 06, 12, 0, 0); var referenceUtc = reference.ConvertToUtc(TimeZones.NewYork); var timeKeeper = new TimeKeeper(referenceUtc); var config = new SubscriptionDataConfig(typeof (TradeBar), Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, false, false); var security = new Security(SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork), config, new Cash("USD", 0, 0), SymbolProperties.GetDefault("USD")); security.SetLocalTimeKeeper(timeKeeper.GetLocalTimeKeeper(TimeZones.NewYork)); var model = new RelativeStandardDeviationVolatilityModel(periodSpan, periods); security.VolatilityModel = model; var first = new IndicatorDataPoint(reference, 1); security.SetMarketPrice(first); Assert.AreEqual(0m, model.Volatility); const decimal value = 0.471404520791032M; // std of 1,2 is ~0.707 over a mean of 1.5 var second = new IndicatorDataPoint(reference.AddMinutes(1), 2); security.SetMarketPrice(second); Assert.AreEqual(value, model.Volatility); // update should not be applied since not enough time has passed var third = new IndicatorDataPoint(reference.AddMinutes(1.01), 1000); security.SetMarketPrice(third); Assert.AreEqual(value, model.Volatility); var fourth = new IndicatorDataPoint(reference.AddMinutes(2), 3m); security.SetMarketPrice(fourth); Assert.AreEqual(0.5m, model.Volatility); }
public void ConstructorDecomposesBaseAndQuoteCurrencies() { var config = new SubscriptionDataConfig(typeof(TradeBar), Symbols.EURUSD, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, true, true, true); var forex = new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours.AlwaysOpen(config.DataTimeZone), new Cash("usd", 0, 0), config, SymbolProperties.GetDefault("usd")); Assert.AreEqual("EUR", forex.BaseCurrencySymbol); Assert.AreEqual("USD", forex.QuoteCurrency.Symbol); }
/// <summary> /// Construct the Equity Object /// </summary> public Equity(SubscriptionDataConfig config, decimal leverage) : this(MarketHoursDatabase.FromDataFolder().GetExchangeHours(config), config, leverage) { // this constructor is provided for backward compatibility // should we even keep this? }
/// <summary> /// Construct the Equity Object /// </summary> public Equity(SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false) : this(SecurityExchangeHoursProvider.FromDataFolder().GetExchangeHours(config), config, leverage, isDynamicallyLoadedData) { // this constructor is provided for backward compatibility // should we even keep this? }
/// <summary> /// Initializes a new instance of the <see cref="TextSubscriptionDataSourceReader"/> class /// </summary> /// <param name="dataFileProvider">Attempts to fetch remote file provider</param> /// <param name="config">The subscription's configuration</param> /// <param name="date">The date this factory was produced to read data for</param> /// <param name="isLiveMode">True if we're in live mode, false for backtesting</param> public TextSubscriptionDataSourceReader(IDataFileProvider dataFileProvider, SubscriptionDataConfig config, DateTime date, bool isLiveMode) { _dataFileProvider = dataFileProvider; _date = date; _config = config; _isLiveMode = isLiveMode; _factory = (BaseData) ObjectActivator.GetActivator(config.Type).Invoke(new object[0]); }
public void ConstructorDecomposesBaseAndQuoteCurrencies() { string symbol = "EURUSD"; var config = new SubscriptionDataConfig(typeof(TradeBar), SecurityType.Forex, symbol, Resolution.Minute, "fxcm", TimeZones.NewYork, true, true, true); var forex = new QuantConnect.Securities.Forex.Forex(SecurityExchangeHours.AlwaysOpen(config.TimeZone), new Cash("abc", 0, 0), config, 1m); Assert.AreEqual("EUR", forex.BaseCurrencySymbol); Assert.AreEqual("USD", forex.QuoteCurrencySymbol); }
public void ConstructorDecomposesBaseAndQuoteCurrencies() { string symbol = "EURUSD"; var config = new SubscriptionDataConfig(typeof(TradeBar), SecurityType.Forex, symbol, Resolution.Minute, true, true, true, true, true, 0); var forex = new QuantConnect.Securities.Forex.Forex(new Cash("abc", 0, 0), config, 1m); Assert.AreEqual("EUR", forex.BaseCurrencySymbol); Assert.AreEqual("USD", forex.QuoteCurrencySymbol); }
public void ConstructorExtractsQuoteCurrency() { var symbol = Symbol.Create("DE30EUR", SecurityType.Cfd, Market.Oanda); var config = new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, TimeZones.Utc, TimeZones.NewYork, true, true, true); var symbolProperties = new SymbolProperties("Dax German index", "EUR", 1, 1, 1); var cfd = new QuantConnect.Securities.Cfd.Cfd(SecurityExchangeHours.AlwaysOpen(config.DataTimeZone), new Cash("EUR", 0, 0), config, symbolProperties); Assert.AreEqual("EUR", cfd.QuoteCurrency.Symbol); }
public void UsedAsDictionaryKey() { var set = new HashSet<SubscriptionDataConfig>(); var config1 = new SubscriptionDataConfig(typeof(TradeBar), Symbols.SPY, Resolution.Minute, TimeZones.NewYork, TimeZones.NewYork, false, false, false, false, TickType.Trade, false); Assert.IsTrue(set.Add(config1)); var config2 = new SubscriptionDataConfig(config1); Assert.IsFalse(set.Add(config2)); }
/// <summary> /// Initializes a new instance of the <see cref="ZipEntryNameSubscriptionDataSourceReader"/> class /// </summary> /// <param name="dataFileProvider">Attempts to fetch remote file</param> /// <param name="config">The subscription's configuration</param> /// <param name="date">The date this factory was produced to read data for</param> /// <param name="isLiveMode">True if we're in live mode, false for backtesting</param> public ZipEntryNameSubscriptionDataSourceReader(IDataFileProvider dataFileProvider, SubscriptionDataConfig config, DateTime date, bool isLiveMode) { _dataFileProvider = dataFileProvider; _config = config; _date = date; _isLiveMode = isLiveMode; _factory = (BaseData) Activator.CreateInstance(config.Type); }
/// <summary> /// Gets the <see cref="CoarseFundamental"/> data for the specified market/date /// </summary> public static IEnumerable<CoarseFundamental> GetCoarseFundamentals(string market, DateTimeZone timeZone, DateTime date, bool isLiveMode) { var factory = new CoarseFundamental(); var config = new SubscriptionDataConfig(typeof(CoarseFundamental), SecurityType.Equity, new Symbol(market + "-coarse"), Resolution.Daily, market, timeZone, true, false, true, false); var reader = new BaseDataSubscriptionFactory(config, date, isLiveMode); var source = factory.GetSource(config, date, isLiveMode); return reader.Read(source).OfType<CoarseFundamental>(); }
/******************************************************** * CLASS CONSTRUCTOR *********************************************************/ /// <summary> /// Create a new self updating, thread safe data updater. /// </summary> /// <param name="config">Configuration for subscription</param> public StreamStore(SubscriptionDataConfig config) { _type = config.Type; _data = null; _lock = new object(); _config = config; _increment = config.Increment; _queue = new ConcurrentQueue<BaseData>(); }
/// <summary> /// Creates a new coarse universe that contains the top count of stocks /// by daily dollar volume /// </summary> /// <param name="count">The number of stock to select</param> /// <param name="universeSettings">The settings for stocks added by this universe. /// Defaults to <see cref="QCAlgorithm.UniverseSettings"/></param> /// <returns>A new coarse universe for the top count of stocks by dollar volume</returns> public Universe Top(int count, UniverseSettings universeSettings = null) { universeSettings = universeSettings ?? _algorithm.UniverseSettings; var symbol = CoarseFundamental.CreateUniverseSymbol(Market.USA); var config = new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, true); return new FuncUniverse(config, universeSettings, selectionData => ( from c in selectionData.OfType<CoarseFundamental>() orderby c.DollarVolume descending select c.Symbol).Take(count) ); }
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { ReaderCount++; //[{"symbol":"SPY","time":1444271505,"alpha":1,"beta":2}] var array = JsonConvert.DeserializeObject<JsonSerialization[]>(line); if (array.Length > 0) { return array[0].ToBaseData(config.TimeZone, config.Increment); } return null; }
/// <summary> /// Createsa new <see cref="ISubscriptionFactory"/> capable of handling the specified <paramref name="source"/> /// </summary> /// <param name="source">The subscription data source to create a factory for</param> /// <param name="config">The configuration of the subscription</param> /// <param name="date">The date to be processed</param> /// <param name="isLiveMode">True for live mode, false otherwise</param> /// <returns>A new <see cref="ISubscriptionFactory"/> that can read the specified <paramref name="source"/></returns> public static ISubscriptionFactory ForSource(SubscriptionDataSource source, SubscriptionDataConfig config, DateTime date, bool isLiveMode) { switch (source.Format) { case FileFormat.Csv: return new TextSubscriptionFactory(config, date, isLiveMode); default: throw new NotImplementedException("SubscriptionFactory.ForSource(" + source + ") has not been implemented yet."); } }
/// <summary> /// Creates a new coarse universe that contains the bottom count of stocks /// by daily dollar volume /// </summary> /// <param name="count">The number of stock to select</param> /// <param name="universeSettings">The settings for stocks added by this universe. /// Defaults to <see cref="QCAlgorithm.UniverseSettings"/></param> /// <returns>A new coarse universe for the bottom count of stocks by dollar volume</returns> public Universe Bottom(int count, UniverseSettings universeSettings = null) { universeSettings = universeSettings ?? _algorithm.UniverseSettings; var symbol = Symbol.Create("us-equity-dollar-volume-bottom-" + count, SecurityType.Equity, Market.USA); var config = new SubscriptionDataConfig(typeof(CoarseFundamental), symbol, Resolution.Daily, TimeZones.NewYork, TimeZones.NewYork, false, false, true); return new FuncUniverse(config, universeSettings, _algorithm.SecurityInitializer, selectionData => ( from c in selectionData.OfType<CoarseFundamental>() orderby c.DollarVolume descending select c.Symbol).Take(count) ); }
/// <summary> /// Construct a new security vehicle based on the user options. /// </summary> public Security(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage) { _config = config; Cache = new SecurityCache(); Exchange = new SecurityExchange(exchangeHours); DataFilter = new SecurityDataFilter(); PortfolioModel = new SecurityPortfolioModel(); TransactionModel = new SecurityTransactionModel(); MarginModel = new SecurityMarginModel(leverage); Holdings = new SecurityHolding(this); }
/// <summary> /// Construct the Equity Object /// </summary> public Equity(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage) : base(exchangeHours, config, leverage) { //Holdings for new Vehicle: Cache = new EquityCache(); Exchange = new EquityExchange(exchangeHours); DataFilter = new EquityDataFilter(); //Set the Equity Transaction Model TransactionModel = new EquityTransactionModel(); PortfolioModel = new EquityPortfolioModel(); MarginModel = new EquityMarginModel(leverage); Holdings = new EquityHolding(this, TransactionModel, MarginModel); }
/// <summary> /// Create a new self updating, thread safe data updater. /// </summary> /// <param name="config">Configuration for subscription</param> /// <param name="security">Security for the subscription</param> public StreamStore(SubscriptionDataConfig config, Security security) { _type = config.Type; _data = null; _config = config; _security = security; _increment = config.Increment; _queue = new ConcurrentQueue<BaseData>(); if (config.Resolution == Resolution.Tick) { throw new ArgumentException("StreamStores are only for non-tick subscriptions"); } }
/// <summary> /// Construct the Equity Object /// </summary> public Equity(SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false) : base(config, leverage, isDynamicallyLoadedData) { //Holdings for new Vehicle: Cache = new EquityCache(); Exchange = new EquityExchange(); DataFilter = new EquityDataFilter(); //Set the Equity Transaction Model TransactionModel = new EquityTransactionModel(); PortfolioModel = new EquityPortfolioModel(); MarginModel = new EquityMarginModel(leverage); Holdings = new EquityHolding(this, TransactionModel, MarginModel); }
/// <summary> /// Construct a new security vehicle based on the user options. /// </summary> public Security(SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false) { _config = config; _symbol = config.Symbol; _isDynamicallyLoadedData = isDynamicallyLoadedData; Cache = new SecurityCache(); Exchange = new SecurityExchange(); DataFilter = new SecurityDataFilter(); PortfolioModel = new SecurityPortfolioModel(); TransactionModel = new SecurityTransactionModel(); MarginModel = new SecurityMarginModel(leverage); Holdings = new SecurityHolding(this); }
/// <summary> /// Return the URL string source of the file. This will be converted to a stream /// </summary> /// <param name="datafeed">Type of datafeed we're reqesting - backtest or live</param> /// <param name="config">Configuration object</param> /// <param name="date">Date of this source file</param> /// <returns>String URL of source file.</returns> public abstract string GetSource(SubscriptionDataConfig config, DateTime date, DataFeedEndpoint datafeed);
/// <summary> /// Will determine if mapping should be used for this subscription configuration /// </summary> /// <param name="config">The subscription data configuration we are processing</param> /// <remarks>One of the objectives of this method is to normalize the 'use mapping' /// check and void code duplication and related issues</remarks> /// <returns>True if ticker should be mapped</returns> public static bool TickerShouldBeMapped(this SubscriptionDataConfig config) { // we create an instance of the data type, if it is a custom type // it can override RequiresMapping else it will use security type\ return(config.GetBaseDataInstance().RequiresMapping()); }
/// <summary> /// Will determine if splits and dividends should be used for this subscription configuration /// </summary> /// <param name="config">The subscription data configuration we are processing</param> /// <remarks>Different than <see cref="PricesShouldBeScaled"/> because prices could be scale and no split and dividends /// really exist, like in the continuous futures case</remarks> /// <returns>True if this configuration requires split and divided handling</returns> public static bool EmitSplitsAndDividends(this SubscriptionDataConfig config) { return(!config.IsCustomData && !config.Symbol.Value.Contains("UNIVERSE") && config.SecurityType == SecurityType.Equity); }
/// <summary> /// Initializes a new instance of the <see cref="HistoryRequest"/> class from the specified config and exchange hours /// </summary> /// <param name="config">The subscription data config used to initialize this request</param> /// <param name="hours">The exchange hours used for fill forward processing</param> /// <param name="startTimeUtc">The start time for this request,</param> /// <param name="endTimeUtc">The start time for this request</param> public HistoryRequest(SubscriptionDataConfig config, SecurityExchangeHours hours, DateTime startTimeUtc, DateTime endTimeUtc) : this(startTimeUtc, endTimeUtc, config.Type, config.Symbol, config.Resolution, hours, config.DataTimeZone, config.FillDataForward ? config.Resolution : (Resolution?)null, config.ExtendedMarketHours, config.IsCustomData, config.DataNormalizationMode, config.TickType, config.DataMappingMode, config.ContractDepthOffset) { }
public virtual BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { throw new InvalidOperationException("Please implement Reader(SubscriptionDataConfig, string, DateTime, bool) on your custom data type: " + GetType().Name); }
/// <summary> /// 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 /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone. /// </summary> /// <param name="config">Subscription data config setup object</param> /// <param name="stream">The data stream</param> /// <param name="date">Date of the requested data</param> /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param> /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns> public virtual BaseData Reader(SubscriptionDataConfig config, StreamReader stream, DateTime date, bool isLiveMode) { throw new NotImplementedException("Each data types has to implement is own Stream reader"); }
public virtual string GetSource(SubscriptionDataConfig config, DateTime date, DataFeedEndpoint datafeed) { throw new InvalidOperationException( $"Please implement GetSource(SubscriptionDataConfig, DateTime, bool) on your custom data type: {GetType().Name}" ); }
/******************************************************** * CLASS PROPERTIES *********************************************************/ /******************************************************** * CLASS METHODS *********************************************************/ /// <summary> /// 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 /// each time it is called. /// </summary> /// <param name="config">Subscription data config setup object</param> /// <param name="line">Line of the source document</param> /// <param name="date">Date of the requested data</param> /// <param name="datafeed">Type of datafeed we're requesting - a live or backtest feed.</param> /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns> public abstract BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed);
/// <summary> /// Initializes a new instance of the <see cref="TextSubscriptionFactory"/> class /// </summary> /// <param name="config">The subscription's configuration</param> /// <param name="date">The date this factory was produced to read data for</param> /// <param name="isLiveMode">True if we're in live mode, false for backtesting</param> public TextSubscriptionFactory(SubscriptionDataConfig config, DateTime date, bool isLiveMode) { _date = date; _config = config; _isLiveMode = isLiveMode; _factory = (BaseData) ObjectActivator.GetActivator(config.Type).Invoke(new object[0]); }
/// <summary> /// Constructor for the forex security /// </summary> /// <param name="quoteCurrency">The cash object that represent the quote currency</param> /// <param name="config">The subscription configuration for this security</param> /// <param name="leverage">The leverage used for this security</param> public Forex(Cash quoteCurrency, SubscriptionDataConfig config, decimal leverage) : this(SecurityExchangeHoursProvider.FromDataFolder().GetExchangeHours(config), quoteCurrency, config, leverage) { // this constructor is provided for backward compatibility // should we even keep this? }