QuantConnect/Lean · error · RegressionTestException

Benchmark value error - expected a new value, current {curre

Error message

Benchmark value error - expected a new value, current {currentValue} {slice.Time}Benchmark value should change when there is a change in hours

What it means

This RegressionTestException is thrown in OnData when the hour changes (_previousTime.Hour != slice.Time.Hour), Minute == 0 (top of new hour), and the benchmark value did NOT change after allowing one tolerance window (_benchmarkPriceDidNotChange > 1). LEAN throws it because at each new hour boundary the daily-resolution benchmark should eventually deliver a new value; two consecutive unchanged values indicate a stale benchmark.

Source

Thrown at Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs:134

            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");
                }
            }
            else
            {
                if (slice.Time.Minute == 0)
                {
                    if (currentValue == _previousBenchmarkValue)
                    {
                        _benchmarkPriceDidNotChange++;
                        // there are two consecutive equal data points so we give it some room
                        if (_benchmarkPriceDidNotChange > 1)
                        {
                            throw new RegressionTestException($"Benchmark value error - expected a new value, current {currentValue} {slice.Time}" +
                                                "Benchmark value should change when there is a change in hours");
                        }
                    }
                    else
                    {
                        _benchmarkPriceDidNotChange = 0;
                    }
                }
            }
            _previousBenchmarkValue = currentValue;
            _previousTime = slice.Time;

            // assert algorithm security is the correct one - not the internal one
            if (security.Leverage != ExpectedLeverage)
            {
                throw new RegressionTestException($"Leverage error - expected: {ExpectedLeverage}, actual: {security.Leverage}");
            }
        }

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Log _benchmarkPriceDidNotChange, currentValue, _previousBenchmarkValue, and slice.Time at the throw point.
  2. Verify the benchmark security's daily data file covers the full test date range with changing values.
  3. Check that Benchmark.Evaluate advances through daily bars as time progresses, not stuck on one bar.
  4. If testing engine changes, trace the benchmark subscription data feed to confirm new daily bars are delivered.

Example fix

// before
if (currentValue == _previousBenchmarkValue)
{
    _benchmarkPriceDidNotChange++;
    if (_benchmarkPriceDidNotChange > 1)
    {
        throw new RegressionTestException($"Benchmark value error - expected a new value, current {currentValue} {slice.Time}" +
                            "Benchmark value should change when there is a change in hours");
    }
}

// after — clearer message
if (currentValue == _previousBenchmarkValue)
{
    _benchmarkPriceDidNotChange++;
    if (_benchmarkPriceDidNotChange > 1)
    {
        throw new RegressionTestException($"Benchmark stale for {_benchmarkPriceDidNotChange} evaluations at {slice.Time}: value={currentValue} unchanged");
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Track benchmark staleness before the threshold
if (currentValue == _previousBenchmarkValue)
{
    _benchmarkPriceDidNotChange++;
    if (_benchmarkPriceDidNotChange >= 1)
        Log($"Benchmark stale ({_benchmarkPriceDidNotChange}x) at {slice.Time}: {currentValue}");
}

Prevention

When it happens

Trigger: At a new hour boundary, Benchmark.Evaluate returns the same value as _previousBenchmarkValue for more than two consecutive evaluations. The algorithm allows one stale data point (_benchmarkPriceDidNotChange <= 1) but fails on the second, indicating the benchmark data feed is stuck.

Common situations: Benchmark daily data file is missing or truncated so no new daily bar arrives, Benchmark.Evaluate always returns a cached value regardless of time, or a LEAN version change broke benchmark data delivery. Also occurs if the benchmark security data feed stops updating.

Related errors


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