public void CreatedSubscriptionDoesNotRoundDownForPeriodLessData() { var data = new MyCustomData { Time = new DateTime(2020, 5, 21, 8, 9, 0), Symbol = Symbols.SPY }; var config = new SubscriptionDataConfig( typeof(TradeBar), Symbols.SPY, Resolution.Hour, TimeZones.Utc, TimeZones.Utc, false, false, false ); var exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.Utc); var offsetProvider = new TimeZoneOffsetProvider(TimeZones.Utc, new DateTime(2020, 5, 21), new DateTime(2020, 5, 22)); var subscription = SubscriptionData.Create(config, exchangeHours, offsetProvider, data); Assert.AreEqual(new DateTime(2020, 5, 21, 8, 9, 0), subscription.Data.Time); Assert.AreEqual(new DateTime(2020, 5, 21, 8, 9, 0), subscription.Data.EndTime); }
public void CreatedSubscriptionRoundsTimeDownForDataWithPeriod() { var tb = new TradeBar { Time = new DateTime(2020, 5, 21, 8, 9, 0), Period = TimeSpan.FromHours(1), Symbol = Symbols.SPY }; var config = new SubscriptionDataConfig( typeof(TradeBar), Symbols.SPY, Resolution.Hour, TimeZones.Utc, TimeZones.Utc, false, false, false ); var exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.Utc); var offsetProvider = new TimeZoneOffsetProvider(TimeZones.Utc, new DateTime(2020, 5, 21), new DateTime(2020, 5, 22)); var subscription = SubscriptionData.Create(config, exchangeHours, offsetProvider, tb); Assert.AreEqual(new DateTime(2020, 5, 21, 8, 0, 0), subscription.Data.Time); Assert.AreEqual(new DateTime(2020, 5, 21, 9, 0, 0), subscription.Data.EndTime); }
private Subscription CreateSubscription(QCAlgorithm algorithm, Security security, DateTime startTimeUtc, DateTime endTimeUtc, out int dataPointCount) { var universe = algorithm.UniverseManager.Values.OfType <UserDefinedUniverse>() .Single(u => u.SelectSymbols(default(DateTime), null).Contains(security.Symbol)); var config = security.Subscriptions.First(); var offsetProvider = new TimeZoneOffsetProvider(TimeZones.NewYork, startTimeUtc, endTimeUtc); var data = LinqExtensions.Range(algorithm.StartDate, algorithm.EndDate, c => c + config.Increment).Select(time => new DataPoint { Time = time, EndTime = time + config.Increment }) .Select(d => SubscriptionData.Create(config, security.Exchange.Hours, offsetProvider, d)) .ToList(); dataPointCount = data.Count; return(new Subscription(universe, security, config, data.GetEnumerator(), offsetProvider, endTimeUtc, endTimeUtc, false)); }
public void CreateTotalNotZeroDividends(Type type, decimal?scale) { var config = new SubscriptionDataConfig( typeof(TradeBar), Symbols.SPY, Resolution.Hour, TimeZones.Utc, TimeZones.Utc, false, false, false ); config.SumOfDividends = 100; config.DataNormalizationMode = DataNormalizationMode.TotalReturn; var tb = new TradeBar { Time = new DateTime(2020, 5, 21, 8, 9, 0), Period = TimeSpan.FromHours(1), Symbol = Symbols.SPY, Open = 100, High = 200, Low = 300, Close = 400 }; var data = SubscriptionData.Create( config, SecurityExchangeHours.AlwaysOpen(TimeZones.Utc), new TimeZoneOffsetProvider(TimeZones.NewYork, new DateTime(2015, 1, 1), new DateTime(2016, 1, 1)), tb, config.DataNormalizationMode, scale); Assert.True(data.GetType() == type); Assert.AreEqual(tb.Open * scale + config.SumOfDividends, (data.Data as TradeBar).Open); Assert.AreEqual(tb.High * scale + config.SumOfDividends, (data.Data as TradeBar).High); Assert.AreEqual(tb.Low * scale + config.SumOfDividends, (data.Data as TradeBar).Low); Assert.AreEqual(tb.Close * scale + config.SumOfDividends, (data.Data as TradeBar).Close); }
public void FillForwardFlagIsCorrectlySet(bool isFillForward, Type type) { var config = new SubscriptionDataConfig( typeof(TradeBar), Symbols.SPY, Resolution.Hour, TimeZones.Utc, TimeZones.Utc, false, false, false ); var scale = 0.5m; config.DataNormalizationMode = DataNormalizationMode.Adjusted; var data = (BaseData)Activator.CreateInstance(type); if (isFillForward) { data = data.Clone(isFillForward); } var subscriptionData = (PrecalculatedSubscriptionData)SubscriptionData.Create(config, SecurityExchangeHours.AlwaysOpen(TimeZones.Utc), new TimeZoneOffsetProvider(TimeZones.NewYork, new DateTime(2015, 1, 1), new DateTime(2016, 1, 1)), data, config.DataNormalizationMode, scale); config.DataNormalizationMode = DataNormalizationMode.Raw; Assert.AreEqual(isFillForward, subscriptionData.Data.IsFillForward); config.DataNormalizationMode = DataNormalizationMode.Adjusted; Assert.AreEqual(isFillForward, subscriptionData.Data.IsFillForward); }