示例#1
0
 /// <summary>
 /// Invoked for each piece of data from the source file
 /// </summary>
 /// <param name="data">The data to be processed</param>
 public void Process(BaseData data)
 {
     foreach (var processor in _processors)
     {
         processor.Process(data);
     }
 }
 /// <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);
 }
 /// <summary>
 /// Invoked for each piece of data from the source file
 /// </summary>
 /// <param name="data">The data to be processed</param>
 public void Process(BaseData data)
 {
     if (_predicate(data))
     {
         _processor.Process(data);
     }
 }
示例#4
0
        /// <summary>
        /// Determines whether or not fill forward is required, and if true, will produce the new fill forward data
        /// </summary>
        /// <param name="fillForwardResolution"></param>
        /// <param name="previous">The last piece of data emitted by this enumerator</param>
        /// <param name="next">The next piece of data on the source enumerator, this may be null</param>
        /// <param name="fillForward">When this function returns true, this will have a non-null value, null when the function returns false</param>
        /// <returns>True when a new fill forward piece of data was produced and should be emitted by this enumerator</returns>
        protected override bool RequiresFillForwardData(TimeSpan fillForwardResolution, BaseData previous, BaseData next, out BaseData fillForward)
        {
            fillForward = null;
            var nextExpectedDataPointTime = (previous.EndTime + fillForwardResolution);
            if (next != null)
            {
                // if not future data, just return the 'next'
                if (next.EndTime <= nextExpectedDataPointTime)
                {
                    return false;
                }
                // next is future data, fill forward in between
                var clone = previous.Clone(true);
                clone.Time = previous.Time + fillForwardResolution;
                fillForward = clone;
                return true;
            }

            // the underlying enumerator returned null, check to see if time has passed for fill fowarding
            var currentLocalTime = _timeProvider.GetUtcNow().ConvertFromUtc(Exchange.TimeZone);
            if (nextExpectedDataPointTime <= currentLocalTime)
            {
                var clone = previous.Clone(true);
                clone.Time = previous.Time + fillForwardResolution;
                fillForward = clone;
                return true;
            }

            return false;
        }
        /// <summary>
        /// Filters the input set of symbols using the underlying price data
        /// </summary>
        /// <param name="symbols">The derivative symbols to be filtered</param>
        /// <param name="underlying">The underlying price data</param>
        /// <returns>The filtered set of symbols</returns>
        public IEnumerable<Symbol> Filter(IEnumerable<Symbol> symbols, BaseData underlying)
        {
            // we can't properly apply this filter without knowing the underlying price
            // so in the event we're missing the underlying, just skip the filtering step
            if (underlying == null)
            {
                return symbols;
            }

            if (underlying.Time.Date != _strikeSizeResolveDate)
            {
                // each day we need to recompute the strike size
                symbols = symbols.ToList();
                var uniqueStrikes = symbols.DistinctBy(x => x.ID.StrikePrice).OrderBy(x => x.ID.StrikePrice).ToList();
                _strikeSize = uniqueStrikes.Zip(uniqueStrikes.Skip(1), (l, r) => r.ID.StrikePrice - l.ID.StrikePrice).DefaultIfEmpty(5m).Min();
                _strikeSizeResolveDate = underlying.Time.Date;
            }

            // compute the bounds, no need to worry about rounding and such
            var minPrice = underlying.Price + _minStrike*_strikeSize;
            var maxPrice = underlying.Price + _maxStrike*_strikeSize;
            var minExpiry = underlying.Time.Date + _minExpiry;
            var maxExpiry = underlying.Time.Date + _maxExpiry;

            // ReSharper disable once PossibleMultipleEnumeration - ReSharper is wrong here due to the ToList call
            return from symbol in symbols
                   let contract = symbol.ID
                   where contract.StrikePrice >= minPrice
                      && contract.StrikePrice <= maxPrice
                      && contract.Date >= minExpiry
                      && contract.Date <= maxExpiry
                   select symbol;
        }
 /// <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>
 /// 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]);
 }
示例#8
0
 /// <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>();
 }
示例#9
0
 /********************************************************
 * 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>();
 }
示例#10
0
文件: Cash.cs 项目: iorixyz/Lean
 /// <summary>
 /// Updates this cash object with the specified data
 /// </summary>
 /// <param name="data">The new data for this cash object</param>
 public void Update(BaseData data)
 {
     if (_isBaseCurrency) return;
     
     var rate = data.Value;
     if (_invertRealTimePrice)
     {
         rate = 1/rate;
     }
     ConversionRate = rate;
 }
示例#11
0
 /// <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>
        /// Invoked for each piece of data from the source file
        /// </summary>
        /// <param name="data">The data to be processed</param>
        public void Process(BaseData data)
        {
            // grab the correct consolidator for this symbol
            IDataConsolidator consolidator;
            if (!_consolidators.TryGetValue(data.Symbol, out consolidator))
            {
                consolidator = _createConsolidator(data);
                consolidator.DataConsolidated += OnDataConsolidated;
                _consolidators[data.Symbol] = consolidator;
            }

            consolidator.Update(data);
        }
        /// <summary>
        /// Handles the <see cref="IDataConsolidator.DataConsolidated"/> event
        /// </summary>
        private void OnDataConsolidated(object sender, BaseData args)
        {
            _destination.Process(args);

            // we've already checked this frontier time, so don't scan the consolidators
            if (_frontier >= args.EndTime) return;
            _frontier = args.EndTime;

            // check the other consolidators to see if they also need to emit
            foreach (var consolidator in _consolidators.Values)
            {
                // back up the time a single instance, this allows data at exact same
                // time to still come through
                consolidator.Scan(args.EndTime.AddTicks(-1));
            }
        }
 /// <summary>
 /// Updates this model using the new price information in
 /// the specified security instance
 /// </summary>
 /// <param name="security">The security to calculate volatility for</param>
 /// <param name="data"></param>
 public void Update(Security security, BaseData data)
 {
     var timeSinceLastUpdate = data.EndTime - _lastUpdate;
     if (timeSinceLastUpdate >= _periodSpan)
     {
         lock (_sync)
         {
             _needsUpdate = true;
             // we purposefully use security.Price for consistency in our reporting
             // some streams of data will have trade/quote data, so if we just use
             // data.Value we could be mixing and matching data streams
             _window.Add((double) security.Price);
         }
         _lastUpdate = data.EndTime;
     }
 }
示例#15
0
        /// <summary>
        /// Filter out a tick from this vehicle, with this new data:
        /// </summary>
        /// <param name="data">New data packet:</param>
        /// <param name="asset">Vehicle of this filter.</param>
        public bool Filter(Security asset, BaseData data)
        {
            // TRUE -->  Accept Tick
            // FALSE --> Reject Tick
            var tick = data as Tick;

            // This is a tick bar
            if (tick != null)
            {
                if (tick.Exchange == "P") //MarketCodesFilter.AllowedExchanges.Contains()
                {
                    return true;
                }
            }

            //Only allow those exchanges through.
            return false;
        }
示例#16
0
        /// <summary>
        /// Invoked for each piece of data from the source file
        /// </summary>
        /// <param name="data">The data to be processed</param>
        public void Process(BaseData data)
        {
            Writer writer;
            if (!_writers.TryGetValue(data.Symbol, out writer))
            {
                writer = CreateTextWriter(data);
                _writers[data.Symbol] = writer;
            }

            // flush every so often
            if (++writer.ProcessCount%TicksPerFlush == 0)
            {
                writer.TextWriter.Flush();
            }

            var line = LeanData.GenerateLine(data, data.Symbol.ID.SecurityType, _resolution);
            writer.TextWriter.WriteLine(line);
        }
        public void FillForwardHoursAtEndOfDayByHalfHour()
        {
            var dataResolution = Time.OneHour;
            var reference = new DateTime(2015, 6, 25, 14, 0, 0);
            var data = new BaseData[]
            {
                // thurs 6/25
                new TradeBar{Value = 0, Time = reference, Period = dataResolution},
                // fri 6/26
                new TradeBar{Value = 1, Time = reference.Date.AddDays(1), Period = dataResolution},
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var ffResolution = TimeSpan.FromMinutes(30);
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);

            // 3:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);

            // 3:30
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(1.5), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);

            // 4:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(2), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);

            // 12:00am
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(data.Last().EndTime, fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);

            Assert.IsFalse(fillForwardEnumerator.MoveNext());
        }
示例#18
0
 /// <summary>
 /// Adds the specified data to this packet
 /// </summary>
 /// <param name="data">The data to be added to this packet</param>
 public void Add(BaseData data)
 {
     _data.Add(data);
 }
        public void FillsForwardDailyMissingDays()
        {
            var dataResolution = Time.OneDay;
            var reference = new DateTime(2015, 6, 25);
            var data = new BaseData[]
            {
                // thurs 6/25
                new TradeBar{Value = 0, Time = reference, Period = Time.OneDay},
                // fri 6/26
                new TradeBar{Value = 1, Time = reference.AddDays(5), Period = Time.OneDay},
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromDays(1), isExtendedMarketHours, data.Last().EndTime.AddDays(1), dataResolution);

            // 6/25
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);

            // 6/26
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(2), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);

            // 6/29
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(5), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);

            // 6/30
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(6), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);

            // 7/1
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(7), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.IsTrue(((TradeBar)fillForwardEnumerator.Current).Period == dataResolution);

            Assert.IsFalse(fillForwardEnumerator.MoveNext());
        }
        public void SkipsAfterMarketData()
        {
            var dataResolution = Time.OneHour;
            var reference = new DateTime(2015, 6, 25, 14, 0, 0);
            var end = reference.Date.AddDays(1).AddHours(10);
            var data = new BaseData[]
            {
                new TradeBar
                {
                    Time = reference,
                    Value = 0,
                    Period = dataResolution
                },
                new TradeBar
                {
                    Time = reference.AddHours(3),
                    Value = 1,
                    Period = dataResolution
                },
                new TradeBar
                {
                    Time = reference.Date.AddDays(1).AddHours(10) - dataResolution,
                    Value = 2,
                    Period = dataResolution
                }
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromHours(1), isExtendedMarketHours, end, dataResolution);

            // 3:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 4:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(2), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 6:00 - this is raw data, the FF enumerator doesn't try to perform filtering per se, just filtering on when to FF
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(4), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 10:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(end, fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(2, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            Assert.IsFalse(fillForwardEnumerator.MoveNext());
        }
        public void FillsForwardMissingDaysOnFillForwardResolutionOfAnHour()
        {
            var dataResolution = Time.OneDay;
            var reference = new DateTime(2015, 6, 23);
            var data = new BaseData[]
            {
                // tues 6/23
                new TradeBar{Value = 0, Time = reference, Period = dataResolution},
                // wed 7/1
                new TradeBar{Value = 1, Time = reference.AddDays(8), Period = dataResolution},
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var ffResolution = TimeSpan.FromHours(1);
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);

            int dailyBars = 0;
            int hourlyBars = 0;
            while (fillForwardEnumerator.MoveNext())
            {
                Console.WriteLine(fillForwardEnumerator.Current.EndTime);
                if (fillForwardEnumerator.Current.Time.TimeOfDay == TimeSpan.Zero)
                {
                    dailyBars++;
                }
                else
                {
                    hourlyBars++;
                }
            }

            // we expect 7 daily bars here, beginning tues, wed, thurs, fri, mon, tues, wed
            Assert.AreEqual(7, dailyBars);

            // we expect 6 days worth of ff hourly bars at 7 bars a day
            Assert.AreEqual(42, hourlyBars);
        }
        public void FillsForwardHourlyOnMinutesBeginningOfDay()
        {
            var dataResolution = Time.OneHour;
            var reference = new DateTime(2015, 6, 25);
            var data = new BaseData[]
            {
                // thurs 6/25
                new TradeBar{Value = 0, Time = reference, Period = dataResolution},
                // fri 6/26
                new TradeBar{Value = 1, Time = reference.Date.AddHours(9), Period = dataResolution},
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var ffResolution = TimeSpan.FromMinutes(15);
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, ffResolution, isExtendedMarketHours, data.Last().EndTime, dataResolution);

            // 12:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(1), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);

            // 9:45 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(9.75), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);

            // 10:00
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddHours(10), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);

            Assert.IsFalse(fillForwardEnumerator.MoveNext());
        }
        public void FillsForwardDailyOnHoursInMarketHours()
        {
            var dataResolution = Time.OneDay;
            var reference = new DateTime(2015, 6, 25);
            var data = new BaseData[]
            {
                // thurs 6/25
                new TradeBar{Value = 0, Time = reference, Period = Time.OneDay},
                // fri 6/26
                new TradeBar{Value = 1, Time = reference.AddDays(1), Period = Time.OneDay},
            }.ToList();
            var enumerator = data.GetEnumerator();

            var exchange = new EquityExchange();
            bool isExtendedMarketHours = false;
            var fillForwardEnumerator = new FillForwardEnumerator(enumerator, exchange, TimeSpan.FromHours(1), isExtendedMarketHours, data.Last().EndTime, dataResolution);

            // 12:00am
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 10:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(10), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 11:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(11), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 12:00pm (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(12), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 1:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(13), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 2:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(14), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 3:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(15), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 4:00 (ff)
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(1).AddHours(16), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(0, fillForwardEnumerator.Current.Value);
            Assert.IsTrue(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            // 12:00am
            Assert.IsTrue(fillForwardEnumerator.MoveNext());
            Assert.AreEqual(reference.AddDays(2), fillForwardEnumerator.Current.EndTime);
            Assert.AreEqual(1, fillForwardEnumerator.Current.Value);
            Assert.IsFalse(fillForwardEnumerator.Current.IsFillForward);
            Assert.AreEqual(dataResolution, fillForwardEnumerator.Current.EndTime - fillForwardEnumerator.Current.Time);

            Assert.IsFalse(fillForwardEnumerator.MoveNext());
        }
示例#24
0
 /// <summary>
 /// Handles the specified data.
 /// </summary>
 /// <param name="data">The data to be handled</param>
 public virtual void HandleData(BaseData data)
 {
     _handleData(data);
 }
示例#25
0
 /// <summary>
 /// Event invocator for the <see cref="DataEmitted"/> event
 /// </summary>
 /// <param name="data">The data being emitted</param>
 public void OnDataEmitted(BaseData data)
 {
     var handler = DataEmitted;
     if (handler != null) handler(this, data);
 }
示例#26
0
文件: Security.cs 项目: neosb/Lean
 /// <summary>
 /// Update any security properties based on the lastest market data and time
 /// </summary>
 /// <param name="data">New data packet from LEAN</param>
 public void SetMarketPrice(BaseData data) 
 {
     //Add new point to cache:
     if (data == null) return;
     Cache.AddData(data);
     Holdings.UpdateMarketPrice(data.Value);
 }
示例#27
0
 public void Update(Security security, BaseData data) { }
示例#28
0
 /// <summary>
 /// Enqueues the data
 /// </summary>
 /// <param name="data">The data to be handled</param>
 public override void HandleData(BaseData data)
 {
     _enqueueable.Enqueue(data);
 }
示例#29
0
 /********************************************************
 * CLASS METHODS
 *********************************************************/
 /// <summary>
 /// Filter the data packet passing through this method by returning true to accept, or false to fail/reject the data point.
 /// </summary>
 /// <param name="data">BasData data object we're filtering</param>
 /// <param name="vehicle">Security vehicle for filter</param>
 public virtual bool Filter(Security vehicle, BaseData data)
 {
     //By default the filter does not change data.
     return true;
 }
示例#30
-1
 /// <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]);
 }