QuantConnect/Lean · error · ValueError

Unexpected split count: {len(split)}

Error message

Unexpected split count: {len(split)}

What it means

Asserts a Split history request for AAPL over 360 bars returns exactly 2 split rows. Divergence means AAPL split data or the split history request changed.

Source

Thrown at Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py:55

        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:
            if interestrate == 0:
                raise ValueError(f"Unexpected interestrate: {interestrate}")

        # last trading date on 2007-05-18
        delisted_symbol = Symbol.create("AAA.1", SecurityType.EQUITY, Market.USA)
        delistings = self.history(Delisting, delisted_symbol, datetime(2007, 5, 15), datetime(2007, 5, 21))
        self.debug(str(delistings))
        if len(delistings) != 2:

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Reconcile AAPL split rows in equity/usa/factorfiles across the 360-day window to 2.
  2. Inspect the split auxiliary-data history path for filtering/sorting changes.
  3. Confirm the regression start date is unchanged.
  4. Rebaseline 2 if data was legitimately corrected.

Example fix

# before
if len(split) != 2:
# after
if len(split) != 2:  # verified AAPL splits in window
Defensive patterns

Strategy: validation

Validate before calling

splits = self.history(Split, aapl, 360)
if len(splits) != 2:
    self.debug(f"AAPL splits: {len(splits)}\n{splits}")

Prevention

When it happens

Trigger: len(self.history(Split, aapl, 360)) != 2.

Common situations: AAPL factor-files split rows changed (e.g. the 2020 4-for-1 split added/removed); split history request handling changed; regression date window shifted.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/ced2ef9093e9e5eb. Report an issue: GitHub.