QuantConnect/Lean · error · RegressionTestException

Unexpected history data start time

Error message

Unexpected history data start time

What it means

Thrown when any of the 10 history bars returned for SpxOption or Spx has a Time.TimeOfDay that is not 08:30:00. For daily-resolution SPX bars, the bar start time should be 8:30 AM US Eastern (market open). A mismatch indicates a timezone, market-hours, or bar-construction problem in the data pipeline.

Source

Thrown at Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs:87

                return;
            }

            var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>();
            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 };

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify the algorithm's time zone matches the data's exchange timezone (SetTimeZone should reflect SPX exchange hours).
  2. Check MarketHoursDatabase for the SPX/USA index entry to confirm market open is 8:30.
  3. Inspect the raw data file timestamps and compare against what the history provider returns.
  4. Log each history bar's Time and EndTime with .Kind to identify UTC/local confusion.

Example fix

// before
if (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))
{
    throw new RegressionTestException($"Unexpected history data start time");
}

// after — show which bar is wrong
var bad = history.FirstOrDefault(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0));
if (bad != null)
{
    throw new RegressionTestException($"Unexpected history start time: {bad.Time} (Kind={bad.Time.Kind})");
}
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: The algorithm's SetTimeZone is configured differently than the data's native timezone, MarketHoursDatabase changed the SPX market-open time, the daily bar Time field was set to midnight instead of market open, or a data normalization change altered the bar start timestamp.

Common situations: Engine-wide timezone refactoring, changes to MarketHoursEntry for SecurityType.Index, switching from exchange-local to UTC timestamps, or data re-ingestion that stamped bars at midnight.

Related errors


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