public SettlementSession(IInstrument instrument, DateStamp sessionDate) { if (instrument is null) { throw new ArgumentNullException(nameof(instrument)); } if (instrument.SettlementTime.TimeOfDay.TotalHours <= 0) { throw new ArgumentException("Settlement time of day with zero or negative time is not supported."); } if (instrument.SettlementTime.TimeOfDay.TotalHours > 24) { throw new ArgumentException("Settlement time of day in early morning of following day is not yet supported."); } if (!instrument.IsTradingDay(sessionDate)) { throw new ArgumentException($"Unexpected sessionDate '{sessionDate}'. It should not be a valid trading day."); } Instrument = instrument; SessionDate = sessionDate; SessionEnd = new TimeStamp(SessionDate, instrument.SettlementTime.TimeOfDay, TimeZone); var sessionStartDate = Instrument.ThisOrPreviousTradingDay(SessionDate.AddDays(-1)); SessionStart = new TimeStamp(sessionStartDate, instrument.SettlementTime.TimeOfDay, TimeZone); }
public static DateStamp AddMarketDays(this IInstrument instrument, DateStamp date, int numMarketDays) { if (numMarketDays == 0) { return(date); } for (var i = 1; i <= numMarketDays; i++) { do { date = date.AddDays(1); } while (!instrument.IsMarketDay(date)); } for (var i = -1; i >= numMarketDays; i--) { do { date = date.AddDays(-1); } while (!instrument.IsMarketDay(date)); } return(date); }
/// <param name="approximateFirstMoveUntilDate"> /// Provide the approximate date of the first <see /// cref="MoveUntil(TimeStamp)"/> method call so that we can initialize the /// iterator so that the first <see cref="MoveUntil(TimeStamp)"/> call will /// result in the conditions specified in the commenting for <see /// cref="ISessionIterator"/>. /// </param> public TradingSessionIterator(TradingSessions tradingHours, DateStamp approximateFirstMoveUntilDate) { _tradingHours = tradingHours; var at = new TimeStamp(approximateFirstMoveUntilDate.AddDays(-12).DateTime.Ticks); Current = _tradingHours.GetActualSessionAt(at); Next = _tradingHours.GetActualSessionAt(Current.SessionEnd.AddTicks(1)); MoveNext(); MoveNext(); CurrentTime = Current.SessionStart.AddTicks(1); IsInSession = true; IsFirstTickOfSession = true; IsNewSession = true; }
/// <param name="approximateFirstMoveUntilDate"> /// Provide the approximate date of the first <see cref="MoveUntil(TimeStamp)"/> method call /// so that we can initialize the iterator so that the first <see cref="MoveUntil(TimeStamp)"/> call will /// result in the conditions specified in the commenting for <see cref="ISessionIterator"/>. /// </param> public SettlementSessionIterator(IInstrument instrument, DateStamp approximateFirstMoveUntilDate) { TimeZone = instrument.SettlementTime.TimeZone; Current = new SettlementSession(instrument, instrument.ThisOrPreviousTradingDay(approximateFirstMoveUntilDate.AddDays(-10))); Previous = Current.GetPrevious(); Next = Current.GetNext(); MoveUntil(Current.SessionStart.AddTicks(1)); }