QuantConnect/Lean · error · RegressionTestException

Unexpected history data end time

Error message

Unexpected history data end time

What it means

Thrown when any of the 10 history bars for SpxOption or Spx has an EndTime.TimeOfDay that is not 15:15:00. Daily SPX bars should end at 15:15 US Eastern (market close). A mismatch signals the bar EndTime (close timestamp) was computed incorrectly by the data pipeline.

Source

Thrown at Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs:91

            if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 15, 15, 0))
            {
                throw new ArgumentException($"Unexpected open interest time: {openInterest.Single().EndTime}");
            }

            foreach (var symbol in new[] { SpxOption, Spx })
            {
                var history = History(symbol, 10).ToList();
                if (history.Count != 10)
                {
                    throw new RegressionTestException($"Unexpected history count: {history.Count}");
                }
                if (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))
                {
                    throw new RegressionTestException($"Unexpected history data start time");
                }
                if (history.Any(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0)))
                {
                    throw new RegressionTestException($"Unexpected history data end time");
                }
            }
        }

        /// <summary>
        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
        /// </summary>
        public override bool CanRunLocally { get; } = true;

        /// <summary>
        /// This is used by the regression test system to indicate which languages this algorithm is written in.
        /// </summary>
        public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };

        /// <summary>
        /// Data Points count of all timeslices of algorithm
        /// </summary>
        public override long DataPoints => 122;

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm Settings.DailyPreciseEndTime = true is set in Initialize and that the engine honors it.
  2. Check MarketHoursDatabase for the SPX market-close time to ensure it is 15:15.
  3. Inspect raw data file EndTime fields and compare with what the history provider returns.
  4. Log bad.EndTime with its .Kind to distinguish UTC from local time issues.

Example fix

// before
if (history.Any(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0)))
{
    throw new RegressionTestException($"Unexpected history data end time");
}

// after — identify the specific bar
var bad = history.FirstOrDefault(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0));
if (bad != null)
{
    throw new RegressionTestException($"Unexpected history end time: {bad.EndTime} (Kind={bad.EndTime.Kind})");
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate history bar end times with diagnostics
var history = History(symbol, 10).ToList();
var expectedEnd = new TimeSpan(15, 15, 0);
var badBar = history.FirstOrDefault(x => x.EndTime.TimeOfDay != expectedEnd);
if (badBar != null)
{
    Log($"Bad end time: {badBar.EndTime} (kind={badBar.EndTime.Kind}) for {symbol}");
}

Prevention

When it happens

Trigger: DailyPreciseEndTime setting is not applied or was changed, the bar EndTime falls back to midnight-plus-one-day instead of exchange close, MarketHoursDatabase changed the SPX close time, or the data file stores the wrong close timestamp.

Common situations: Changes to Settings.DailyPreciseEndTime behavior in the engine, data normalization that defaults EndTime to the next midnight, timezone confusion between data storage and algorithm time, or modifications to how Lean derives EndTime from Time plus bar span.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/c7930e5617caf74a. Report an issue: GitHub.