QuantConnect/Lean · error · AssertionError
The total number of insights should be {expected}. Actual: {
Error message
The total number of insights should be {expected}. Actual: {self.insights.total_count} What it means
on_end_of_algorithm assertion in a framework regression using HistoricalReturnsAlphaModel. It pins the alpha model's emitted insight count to exactly 78. A different count means the alpha's insight-emission logic, the universe selection, or the consolidation schedule changed. This is a behavioral contract test for HistoricalReturnsAlphaModel.
Source
Thrown at Algorithm.Python/HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm.py:30
# limitations under the License.
from AlgorithmImports import *
from BaseFrameworkRegressionAlgorithm import BaseFrameworkRegressionAlgorithm
from Alphas.HistoricalReturnsAlphaModel import HistoricalReturnsAlphaModel
### <summary>
### Regression algorithm to assert the behavior of <see cref="HistoricalReturnsAlphaModel"/>.
### </summary>
class HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm(BaseFrameworkRegressionAlgorithm):
def initialize(self):
super().initialize()
self.set_alpha(HistoricalReturnsAlphaModel())
def on_end_of_algorithm(self):
expected = 78
if self.insights.total_count != expected:
raise AssertionError(f"The total number of insights should be {expected}. Actual: {self.insights.total_count}")
View on GitHub (pinned to d2c3659f87)
Solutions
- Diff HistoricalReturnsAlphaModel (Algorithm.Framework/Alphas) and BaseFrameworkRegressionAlgorithm for changes to rebalance frequency, insight magnitude/threshold, or universe.
- Check the regression's set_universe / warm-up config; fewer data points yields fewer insights.
- Recompute the expected count against current code and, if the new behavior is correct, update expected = 78 with a justification and re-baseline other affected regression stats.
Example fix
# before: alpha emitted a different number after changing rebalance self.set_alpha(HistoricalReturnsAlphaModel(rebalance=Resolution.DAILY)) # after: keep the default rebalance the regression was baselined against self.set_alpha(HistoricalReturnsAlphaModel())
Defensive patterns
Strategy: validation
Validate before calling
# after setting the alpha, log expected insight cadence for review
self.set_alpha(HistoricalReturnsAlphaModel())
# at end, fail with context if counts drift
if self.insights.total_count != 78:
self.debug(f"insight count drift: {self.insights.total_count}") Prevention
- Pin alpha-model constructor arguments; do not silently change rebalance/resolution.
- When updating the framework, recompute and document insight-count baselines.
- Run the full framework regression suite after any Alpha/Universe change.
When it happens
Trigger: self.insights.total_count != 78 at algorithm end. The alpha emitted more or fewer insights than expected over the regression period.
Common situations: A change to HistoricalReturnsAlphaModel insight emission (frequency, threshold, rebalance); universe size change in BaseFrameworkRegressionAlgorithm; resolution/warm-up period change altering how many historical-return samples are available; consolidation or scheduled-event timing change.
Related errors
- Unexpected open order {order}
- Expected open order for emitted insight
- Unexpected open order for emitted insight: {order}
- Unexpected holdings
- Algorithm should have not run on extended hours for {self._g
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/68a738ab79ede4b8.
Report an issue: GitHub.