QuantConnect/Lean · error · RegressionTestException

Security Price error. Price should change every new hour

Error message

Security Price error. Price should change every new hour

What it means

This RegressionTestException is thrown in OnData when the universe is NOT selected (_universeSelected == false) and slice.Time.Minute == 0 (an hour boundary). It asserts that the security price changed from the previous slice, verifying that Hour-resolution data delivers a new price at each new hour. LEAN throws it because at hour boundaries the SPY subscription (Hour resolution) must reflect a genuinely new data point.

Source

Thrown at Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs:103

            {
                if (bar.IsFillForward
                    || bar.Period != TimeSpan.FromMinutes(1))
                {
                    // bar should always be the Minute resolution one here
                    throw new RegressionTestException("Unexpected Bar error");
                }
                if (_previousTime.Date == slice.Time.Date
                    && (slice.Time - _previousTime) != TimeSpan.FromMinutes(1))
                {
                    throw new RegressionTestException("For the same date expected data updates every 1 minute");
                }
            }
            else
            {
                if (slice.Time.Minute == 0
                    && _previousSecurityValue == security.Price)
                {
                    throw new RegressionTestException($"Security Price error. Price should change every new hour");
                }
                if (slice.Time.Minute != 0
                    && _previousSecurityValue != security.Price
                    && security.IsTradable)
                {
                    throw new RegressionTestException($"Security Price error. Price should not change every minute");
                }
            }
            _previousSecurityValue = security.Price;

            // assert benchmark updates only on date change
            var currentValue = Benchmark.Evaluate(slice.Time);
            if (_previousTime.Hour == slice.Time.Hour)
            {
                if (currentValue != _previousBenchmarkValue)
                {
                    throw new RegressionTestException($"Benchmark value error - expected: {_previousBenchmarkValue} {_previousTime}, actual: {currentValue} {slice.Time}. " +
                                        "Benchmark value should only change when there is a change in hours");

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Log security.Price and _previousSecurityValue at the throw to confirm the stale price.
  2. Inspect the hour-resolution data file to verify prices differ across consecutive hours.
  3. Check that the security's Price is derived from the latest bar's close, not a cached or fill-forward value.
  4. If testing engine changes, trace how hour-resolution bars update Security.Price to ensure it reflects the new bar.

Example fix

// before
if (slice.Time.Minute == 0 && _previousSecurityValue == security.Price)
{
    throw new RegressionTestException($"Security Price error. Price should change every new hour");
}

// after — diagnostic
if (slice.Time.Minute == 0 && _previousSecurityValue == security.Price)
{
    throw new RegressionTestException($"Price unchanged at hour boundary {slice.Time}: prev={_previousSecurityValue}, current={security.Price}");
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate price change at hour boundary
if (slice.Time.Minute == 0)
{
    if (_previousSecurityValue == security.Price)
        Log($"Price unchanged at hour boundary {slice.Time}: {security.Price}");
}

Prevention

When it happens

Trigger: At Minute == 0 (top of the hour), security.Price equals _previousSecurityValue — the price did not update when a new hour bar arrived. This means the hour-resolution data feed delivered a bar with the same price as the previous one, which should only happen for non-tradable or fill-forward data.

Common situations: Hour data files contain duplicate prices across consecutive hours, fill-forward logic generates bars with stale prices at hour boundaries, or the security's Price property is not being updated from the latest bar due to a data-feed or price-calculation regression.

Related errors


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