Example #1
0
        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);
        }
 /// <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));
 }