{"record":{"id":"77a4543855f6ce6b","repo":"QuantConnect/Lean","slug":"unexpected-dividend-count-len-dividend","errorCode":null,"errorMessage":"Unexpected dividend count: {len(dividend)}","messagePattern":"Unexpected dividend count: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py","lineNumber":47,"sourceCode":"        # multi symbol request\n        spy = Symbol.create(\"SPY\", SecurityType.EQUITY, Market.USA)\n        multi_symbol_request = self.history(Dividend, [ aapl, spy ], 360, Resolution.DAILY)\n        if len(multi_symbol_request) != 12:\n                raise ValueError(f\"Unexpected multi symbol dividend count: {len(multi_symbol_request)}\")\n\n        # continuous future mapping requests\n        sp500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)\n        continuous_future_open_interest_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.OPEN_INTEREST)\n        if len(continuous_future_open_interest_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}\")\n        continuous_future_last_trading_day_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.LAST_TRADING_DAY)\n        if len(continuous_future_last_trading_day_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}\")\n\n        dividend = self.history(Dividend, aapl, 360)\n        self.debug(str(dividend))\n        if len(dividend) != 6:\n            raise ValueError(f\"Unexpected dividend count: {len(dividend)}\")\n        for distribution in dividend.distribution:\n            if distribution == 0:\n                raise ValueError(f\"Unexpected distribution: {distribution}\")\n\n        split = self.history(Split, aapl, 360)\n        self.debug(str(split))\n        if len(split) != 2:\n            raise ValueError(f\"Unexpected split count: {len(split)}\")\n        for splitfactor in split.splitfactor:\n            if splitfactor == 0:\n                raise ValueError(f\"Unexpected splitfactor: {splitfactor}\")\n\n        symbol = Symbol.create(\"BTCUSD\", SecurityType.CRYPTO_FUTURE, Market.BINANCE)\n        margin_interest = self.history(MarginInterestRate, symbol, 24 * 3, Resolution.HOUR)\n        self.debug(str(margin_interest))\n        if len(margin_interest) != 8:\n            raise ValueError(f\"Unexpected margin interest count: {len(margin_interest)}\")\n        for interestrate in margin_interest.interestrate:","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py#L29-L65","documentation":"Asserts a single-symbol Dividend history request for AAPL over 360 bars returns exactly 6 dividend rows. Divergence means AAPL dividend data coverage or the dividend history request changed.","triggerScenarios":"len(self.history(Dividend, aapl, 360)) != 6 during initialize.","commonSituations":"AAPL factor-files dividend rows changed in the lookback window; dividend history request resolution/period handling changed; regression date window shifted.","solutions":["Reconcile AAPL dividend rows in equity/usa/factorfiles across the 360-day window to 6.","Inspect the dividend auxiliary-data history path for filtering/sorting changes.","Confirm the regression start date is unchanged.","Rebaseline 6 if data was legitimately corrected."],"exampleFix":"# before\nif len(dividend) != 6:\n# after\nif len(dividend) != 6:  # verified AAPL dividends 2020-2021 window","handlingStrategy":"validation","validationCode":"div = self.history(Dividend, aapl, 360)\nif len(div) != 6:\n    self.debug(f\"AAPL dividends: {len(div)}\\n{div}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the regression start date so the 360-bar lookback is stable.","Reconcile dividend counts against the factor file after any data refresh.","Log the rows on mismatch."],"tags":["quantconnect","lean","regression","history","auxiliary-data","dividends"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}