public void TestBasicFeaturesWithOptionsFutures() { var securities = new SecurityManager(TimeKeeper); var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); securities.Add(Symbols.SPY, new Security(SecurityExchangeHours, CreateTradeBarDataConfig(SecurityType.Equity, Symbols.SPY), new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency))); securities[Symbols.SPY].SetMarketPrice(new TradeBar { Time = securities.UtcTime, Symbol = Symbols.SPY, Close = 195 }); var option1 = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 192m, new DateTime(2016, 02, 16)); securities.Add(option1, new Option(SecurityExchangeHours, CreateTradeBarDataConfig(SecurityType.Option, option1), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)))); var option2 = Symbol.CreateOption("SPY", Market.USA, OptionStyle.American, OptionRight.Call, 193m, new DateTime(2016, 03, 19)); securities.Add(option2, new Option(SecurityExchangeHours, CreateTradeBarDataConfig(SecurityType.Option, option2), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)))); var future1 = Symbol.CreateFuture("ES", Market.USA, new DateTime(2016, 02, 16)); securities.Add(future1, new Future(SecurityExchangeHours, CreateTradeBarDataConfig(SecurityType.Future, future1), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)))); var future2 = Symbol.CreateFuture("ES", Market.USA, new DateTime(2016, 02, 19)); securities.Add(future2, new Future(SecurityExchangeHours, CreateTradeBarDataConfig(SecurityType.Future, future2), new Cash(CashBook.AccountCurrency, 0, 1m), new OptionSymbolProperties(SymbolProperties.GetDefault(CashBook.AccountCurrency)))); var cal = new TradingCalendar(securities, marketHoursDatabase); var optionDays = cal.GetDaysByType(TradingDayType.OptionExpiration, new DateTime(2016, 02, 16), new DateTime(2016, 03, 19)).Count(); Assert.AreEqual(2, optionDays); var futureDays = cal.GetDaysByType(TradingDayType.OptionExpiration, new DateTime(2016, 02, 16), new DateTime(2016, 03, 19)).Count(); Assert.AreEqual(2, futureDays); var days = cal.GetTradingDays(new DateTime(2016, 02, 16), new DateTime(2016, 03, 19)); var optionAndfutureDays = days.Where(x => x.FutureExpirations.Any() || x.OptionExpirations.Any()).Count(); Assert.AreEqual(3, optionAndfutureDays); // why? because option1 and future1 expire in one day 2016-02-16. Lets have a look. var day = cal.GetTradingDay(new DateTime(2016, 02, 16)); Assert.AreEqual(1, day.OptionExpirations.Count()); Assert.AreEqual(1, day.FutureExpirations.Count()); var businessDays = days.Where(x => x.BusinessDay).Count(); Assert.AreEqual(24, businessDays); var weekends = days.Where(x => x.Weekend).Count(); Assert.AreEqual(9, weekends); Assert.AreEqual(24 + 9, (new DateTime(2016, 03, 19) - new DateTime(2016, 02, 16)).TotalDays + 1 /*inclusive*/); }
public void ReversedDateRequestThrows() { var securities = new SecurityManager(TimeKeeper); var marketHoursDatabase = MarketHoursDatabase.FromDataFolder(); var calendar = new TradingCalendar(securities, marketHoursDatabase); Assert.Throws <ArgumentException>(() => calendar.GetTradingDays(new DateTime(2010, 2, 28), new DateTime(2010, 2, 10)).ToList()); }