Esempio n. 1
0
        private IEnumerable <Slice> History(IEnumerable <HistoryRequest> requests, DateTimeZone timeZone)
        {
            var sentMessage = false;
            // filter out any universe securities that may have made it this far
            var reqs = requests.Where(hr => !UniverseManager.ContainsKey(hr.Symbol)).ToList();

            foreach (var request in reqs)
            {
                // prevent future requests
                if (request.EndTimeUtc > UtcTime)
                {
                    request.EndTimeUtc = UtcTime;
                    if (request.StartTimeUtc > request.EndTimeUtc)
                    {
                        request.StartTimeUtc = request.EndTimeUtc;
                    }
                    if (!sentMessage)
                    {
                        sentMessage = true;
                        Debug("Request for future history modified to end now.");
                    }
                }
            }

            // filter out future data to prevent look ahead bias
            return(((IAlgorithm)this).HistoryProvider.GetHistory(reqs, timeZone));
        }
Esempio n. 2
0
        private IEnumerable <Slice> History(IEnumerable <HistoryRequest> requests, DateTimeZone timeZone)
        {
            var sentMessage = false;
            // filter out any universe securities that may have made it this far
            var filteredRequests = requests.Where(hr => !UniverseManager.ContainsKey(hr.Symbol)).ToList();

            for (var i = 0; i < filteredRequests.Count; i++)
            {
                var request = filteredRequests[i];
                // prevent future requests
                if (request.EndTimeUtc > UtcTime)
                {
                    var endTimeUtc   = UtcTime;
                    var startTimeUtc = request.StartTimeUtc;
                    if (request.StartTimeUtc > request.EndTimeUtc)
                    {
                        startTimeUtc = request.EndTimeUtc;
                    }

                    filteredRequests[i] = new HistoryRequest(startTimeUtc, endTimeUtc,
                                                             request.DataType, request.Symbol, request.Resolution, request.ExchangeHours,
                                                             request.DataTimeZone, request.FillForwardResolution, request.IncludeExtendedMarketHours,
                                                             request.IsCustomData, request.DataNormalizationMode, request.TickType);

                    if (!sentMessage)
                    {
                        sentMessage = true;
                        Debug("Request for future history modified to end now.");
                    }
                }
            }

            // filter out future data to prevent look ahead bias
            return(((IAlgorithm)this).HistoryProvider.GetHistory(filteredRequests, timeZone));
        }
Esempio n. 3
0
 /// <summary>
 /// Validate a symbol for a history request.
 /// Universe and canonical symbols are only valid for future security types
 /// </summary>
 private bool HistoryRequestValid(Symbol symbol)
 {
     return(symbol.SecurityType == SecurityType.Future || !UniverseManager.ContainsKey(symbol) && !symbol.IsCanonical());
 }