17 using System.Collections.Generic;
39 _securityManager = securityManager;
40 _marketHoursDatabase = marketHoursDatabase;
48 var today = _securityManager.UtcTime.
Date;
70 return PopulateTradingDays(start, end);
82 Func<TradingDay, bool> typeFilter = day =>
87 return day.BusinessDay;
89 return day.PublicHoliday;
93 return day.OptionExpirations.Any();
95 return day.FutureExpirations.Any();
97 return day.FutureRolls.Any();
99 return day.SymbolDelistings.Any();
101 return day.EquityDividends.Any();
109 private IEnumerable<TradingDay> PopulateTradingDays(DateTime start, DateTime end)
111 var symbols = _securityManager.Keys;
113 var holidays =
new HashSet<DateTime>();
114 foreach (var symbol
in symbols)
116 var entry = _marketHoursDatabase.GetEntry(symbol.ID.Market, symbol, symbol.ID.SecurityType);
118 foreach (var holiday
in entry.ExchangeHours.Holidays)
120 holidays.Add(holiday.Date);
124 var qlCalendar =
new UnitedStates();
125 var options = symbols.Where(x => x.ID.SecurityType.IsOption()).ToList();
126 var futures = symbols.Where(x => x.ID.SecurityType ==
SecurityType.Future).ToList();
128 var totalDays = (int)(end.Date.AddDays(1.0) - start.Date).TotalDays;
131 throw new ArgumentException($
"TradingCalendar.PopulateTradingDays(): {Messages.TradingCalendar.InvalidTotalDays(totalDays)}");
134 foreach (var dayIdx
in Enumerable.Range(0, totalDays))
136 var currentDate = start.Date.AddDays(dayIdx);
138 var publicHoliday = holidays.Contains(currentDate) || !qlCalendar.isBusinessDay(currentDate);
139 var weekend = currentDate.DayOfWeek == DayOfWeek.Sunday ||
140 currentDate.DayOfWeek == DayOfWeek.Saturday;
141 var businessDay = !publicHoliday && !weekend;
150 OptionExpirations = options.Where(x => x.ID.Date.Date == currentDate),
151 FutureExpirations = futures.Where(x => x.ID.Date.Date == currentDate)