17 using System.Collections.Generic;
44 private static readonly IReadOnlyDictionary<Symbol, Func<DateTime, DateTime>> _futuresOptionExpiryFunctions =
new Dictionary<Symbol, Func<DateTime,DateTime>>
47 {_lo, expiryMonth => {
48 var twentySixthDayOfPreviousMonthFromContractMonth = expiryMonth.AddMonths(-1).AddDays(-(expiryMonth.Day - 1)).AddDays(25);
49 var holidays = _mhdb.GetEntry(_lo.ID.Market, _lo.Underlying,
SecurityType.Future)
58 { _on, expiryMonth => FourthLastBusinessDayInPrecedingMonthFromContractMonth(_on.Underlying, expiryMonth, 0, 0, noFridays:
false) },
59 { _ozb, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozb.Underlying, expiryMonth) },
60 { _ozc, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozc.Underlying, expiryMonth) },
61 { _ozn, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozn.Underlying, expiryMonth) },
62 { _ozs, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozs.Underlying, expiryMonth) },
63 { _ozt, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozt.Underlying, expiryMonth) },
64 { _ozw, expiryMonth => FridayBeforeTwoBusinessDaysBeforeEndOfMonth(_ozw.Underlying, expiryMonth) },
65 { _hxe, expiryMonth => FourthLastBusinessDayInPrecedingMonthFromContractMonth(_hxe.Underlying, expiryMonth, 12, 0) },
66 { _og, expiryMonth => FourthLastBusinessDayInPrecedingMonthFromContractMonth(_og.Underlying, expiryMonth, 12, 30) },
67 { _so, expiryMonth => FourthLastBusinessDayInPrecedingMonthFromContractMonth(_so.Underlying, expiryMonth, 12, 25) },
82 canonicalFutureOptionSymbol.
ID.
Market,
89 Func<DateTime, DateTime> expiryFunction;
90 if (!_futuresOptionExpiryFunctions.TryGetValue(canonicalFutureOptionSymbol, out expiryFunction))
96 return expiryFunction(futureContractMonth);
108 var futureContractMonth =
new DateTime(
109 futureSymbol.
ID.
Date.Year,
110 futureSymbol.
ID.
Date.Month,
112 .AddMonths(futureContractMonthDelta);
114 if (canonicalFutureOption ==
null)
135 private static DateTime FridayBeforeTwoBusinessDaysBeforeEndOfMonth(
Symbol underlyingFuture, DateTime expiryMonth)
137 var holidays = _mhdb.GetEntry(underlyingFuture.
ID.
Market, underlyingFuture,
SecurityType.Future)
141 var expiryMonthPreceding = expiryMonth.AddMonths(-1).AddDays(-(expiryMonth.Day - 1));
143 expiryMonthPreceding,
145 holidayList: holidays).AddDays(-1);
147 while (fridayBeforeSecondLastBusinessDay.DayOfWeek != DayOfWeek.Friday)
152 return fridayBeforeSecondLastBusinessDay;
166 private static DateTime FourthLastBusinessDayInPrecedingMonthFromContractMonth(
Symbol underlyingFuture, DateTime expiryMonth,
int hour,
int minutes,
bool noFridays =
true)
168 var holidays = _mhdb.GetEntry(underlyingFuture.
ID.
Market, underlyingFuture,
SecurityType.Future)
172 var expiryMonthPreceding = expiryMonth.AddMonths(-1);
177 while (fourthLastBusinessDay.DayOfWeek == DayOfWeek.Friday || holidays.Contains(fourthLastBusinessDay.AddDays(1)))
183 return fourthLastBusinessDay.AddHours(hour).AddMinutes(minutes);