{"record":{"id":"68a738ab79ede4b8","repo":"QuantConnect/Lean","slug":"the-total-number-of-insights-should-be-expected","errorCode":null,"errorMessage":"The total number of insights should be {expected}. Actual: {self.insights.total_count}","messagePattern":"The total number of insights should be (.+?)\\. Actual: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm.py","lineNumber":30,"sourceCode":"# limitations under the License.\n\nfrom AlgorithmImports import *\nfrom BaseFrameworkRegressionAlgorithm import BaseFrameworkRegressionAlgorithm\nfrom Alphas.HistoricalReturnsAlphaModel import HistoricalReturnsAlphaModel\n\n### <summary>\n### Regression algorithm to assert the behavior of <see cref=\"HistoricalReturnsAlphaModel\"/>.\n### </summary>\nclass HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm(BaseFrameworkRegressionAlgorithm):\n\n    def initialize(self):\n        super().initialize()\n        self.set_alpha(HistoricalReturnsAlphaModel())\n\n    def on_end_of_algorithm(self):\n        expected = 78\n        if self.insights.total_count != expected:\n            raise AssertionError(f\"The total number of insights should be {expected}. Actual: {self.insights.total_count}\")\n","sourceCodeStart":12,"sourceCodeEnd":31,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm.py#L12-L31","documentation":"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.","triggerScenarios":"self.insights.total_count != 78 at algorithm end. The alpha emitted more or fewer insights than expected over the regression period.","commonSituations":"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.","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."],"exampleFix":"# before: alpha emitted a different number after changing rebalance\nself.set_alpha(HistoricalReturnsAlphaModel(rebalance=Resolution.DAILY))\n# after: keep the default rebalance the regression was baselined against\nself.set_alpha(HistoricalReturnsAlphaModel())","handlingStrategy":"validation","validationCode":"# after setting the alpha, log expected insight cadence for review\nself.set_alpha(HistoricalReturnsAlphaModel())\n# at end, fail with context if counts drift\nif self.insights.total_count != 78:\n    self.debug(f\"insight count drift: {self.insights.total_count}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","lean","regression","alpha-model","framework","insights","historical-returns"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}