{"record":{"id":"387a2c6b77f1ec72","repo":"QuantConnect/Lean","slug":"benchmark-value-error-expected-a-new-value-curr","errorCode":null,"errorMessage":"Benchmark value error - expected a new value, current {currentValue} {slice.Time}Benchmark value should change when there is a change in hours","messagePattern":"Benchmark value error - expected a new value, current (.+?) (.+?)Benchmark value should change when there is a change in hours","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs","lineNumber":134,"sourceCode":"            if (_previousTime.Hour == slice.Time.Hour)\n            {\n                if (currentValue != _previousBenchmarkValue)\n                {\n                    throw new RegressionTestException($\"Benchmark value error - expected: {_previousBenchmarkValue} {_previousTime}, actual: {currentValue} {slice.Time}. \" +\n                                        \"Benchmark value should only change when there is a change in hours\");\n                }\n            }\n            else\n            {\n                if (slice.Time.Minute == 0)\n                {\n                    if (currentValue == _previousBenchmarkValue)\n                    {\n                        _benchmarkPriceDidNotChange++;\n                        // there are two consecutive equal data points so we give it some room\n                        if (_benchmarkPriceDidNotChange > 1)\n                        {\n                            throw new RegressionTestException($\"Benchmark value error - expected a new value, current {currentValue} {slice.Time}\" +\n                                                \"Benchmark value should change when there is a change in hours\");\n                        }\n                    }\n                    else\n                    {\n                        _benchmarkPriceDidNotChange = 0;\n                    }\n                }\n            }\n            _previousBenchmarkValue = currentValue;\n            _previousTime = slice.Time;\n\n            // assert algorithm security is the correct one - not the internal one\n            if (security.Leverage != ExpectedLeverage)\n            {\n                throw new RegressionTestException($\"Leverage error - expected: {ExpectedLeverage}, actual: {security.Leverage}\");\n            }\n        }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomUniverseWithBenchmarkRegressionAlgorithm.cs#L116-L152","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log _benchmarkPriceDidNotChange, currentValue, _previousBenchmarkValue, and slice.Time at the throw point.","Verify the benchmark security's daily data file covers the full test date range with changing values.","Check that Benchmark.Evaluate advances through daily bars as time progresses, not stuck on one bar.","If testing engine changes, trace the benchmark subscription data feed to confirm new daily bars are delivered."],"exampleFix":"// before\nif (currentValue == _previousBenchmarkValue)\n{\n    _benchmarkPriceDidNotChange++;\n    if (_benchmarkPriceDidNotChange > 1)\n    {\n        throw new RegressionTestException($\"Benchmark value error - expected a new value, current {currentValue} {slice.Time}\" +\n                            \"Benchmark value should change when there is a change in hours\");\n    }\n}\n\n// after — clearer message\nif (currentValue == _previousBenchmarkValue)\n{\n    _benchmarkPriceDidNotChange++;\n    if (_benchmarkPriceDidNotChange > 1)\n    {\n        throw new RegressionTestException($\"Benchmark stale for {_benchmarkPriceDidNotChange} evaluations at {slice.Time}: value={currentValue} unchanged\");\n    }\n}","handlingStrategy":"validation","validationCode":"// Track benchmark staleness before the threshold\nif (currentValue == _previousBenchmarkValue)\n{\n    _benchmarkPriceDidNotChange++;\n    if (_benchmarkPriceDidNotChange >= 1)\n        Log($\"Benchmark stale ({_benchmarkPriceDidNotChange}x) at {slice.Time}: {currentValue}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the benchmark security's daily data file covers the full date range with changing values.","Understand the tolerance: one stale data point is allowed, two consecutive is a failure.","Log _benchmarkPriceDidNotChange to detect staleness before it hits the threshold."],"tags":["quantconnect","lean","benchmark","hour-change","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}