QuantConnect/Lean · error · ValueError
Unexpected dividend count: {len(dividend)}
Error message
Unexpected dividend count: {len(dividend)} What it means
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.
Source
Thrown at Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py:47
# multi symbol request
spy = Symbol.create("SPY", SecurityType.EQUITY, Market.USA)
multi_symbol_request = self.history(Dividend, [ aapl, spy ], 360, Resolution.DAILY)
if len(multi_symbol_request) != 12:
raise ValueError(f"Unexpected multi symbol dividend count: {len(multi_symbol_request)}")
# continuous future mapping requests
sp500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)
continuous_future_open_interest_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.OPEN_INTEREST)
if len(continuous_future_open_interest_mapping) != 9:
raise ValueError(f"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}")
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)
if len(continuous_future_last_trading_day_mapping) != 9:
raise ValueError(f"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}")
dividend = self.history(Dividend, aapl, 360)
self.debug(str(dividend))
if len(dividend) != 6:
raise ValueError(f"Unexpected dividend count: {len(dividend)}")
for distribution in dividend.distribution:
if distribution == 0:
raise ValueError(f"Unexpected distribution: {distribution}")
split = self.history(Split, aapl, 360)
self.debug(str(split))
if len(split) != 2:
raise ValueError(f"Unexpected split count: {len(split)}")
for splitfactor in split.splitfactor:
if splitfactor == 0:
raise ValueError(f"Unexpected splitfactor: {splitfactor}")
symbol = Symbol.create("BTCUSD", SecurityType.CRYPTO_FUTURE, Market.BINANCE)
margin_interest = self.history(MarginInterestRate, symbol, 24 * 3, Resolution.HOUR)
self.debug(str(margin_interest))
if len(margin_interest) != 8:
raise ValueError(f"Unexpected margin interest count: {len(margin_interest)}")
for interestrate in margin_interest.interestrate:View on GitHub (pinned to d2c3659f87)
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.
Example fix
# before if len(dividend) != 6: # after if len(dividend) != 6: # verified AAPL dividends 2020-2021 window
Defensive patterns
Strategy: validation
Validate before calling
div = self.history(Dividend, aapl, 360)
if len(div) != 6:
self.debug(f"AAPL dividends: {len(div)}\n{div}") Prevention
- 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.
When it happens
Trigger: len(self.history(Dividend, aapl, 360)) != 6 during initialize.
Common situations: AAPL factor-files dividend rows changed in the lookback window; dividend history request resolution/period handling changed; regression date window shifted.
Related errors
- Unexpected multi symbol dividend count: {len(multi_symbol_re
- Unexpected distribution: {distribution}
- Unexpected continuous future mapping event count: {len(conti
- Unexpected continuous future mapping event count: {len(conti
- Unexpected split count: {len(split)}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/77a4543855f6ce6b.
Report an issue: GitHub.