QuantConnect/Lean · error · ValueError

Unexpected splitfactor: {splitfactor}

Error message

Unexpected splitfactor: {splitfactor}

What it means

Per-row sanity check on the AAPL split history: every split factor must be non-zero. A zero split factor indicates malformed split data or a deserialization bug that zeroed the factor.

Source

Thrown at Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py:58

        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:
            raise ValueError(f"Unexpected delistings count: {len(delistings)}")
        if delistings.iloc[0].type != DelistingType.WARNING:
            raise ValueError(f"Unexpected delisting: {delistings.iloc[0]}")

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Inspect AAPL factor file rows in the window for zero or malformed split factor values.
  2. Trace Split.SplitFactor population in the split reader/factor provider.
  3. Correct the bad data row and re-run.

Example fix

# before: malformed factor row {time;1.0;0;0.0}
# after: corrected split factor
{20200831;0.25;0.25;0.0}
Defensive patterns

Strategy: validation

Validate before calling

splits = self.history(Split, aapl, 360)
bad = [s for s in splits.splitfactor if s == 0]
if bad:
    self.debug(f"zero split factors: {len(bad)}")

Type guard

def has_nonzero_split_factors(split_history) -> bool:
    return all(s != 0 for s in split_history.splitfactor)

Prevention

When it happens

Trigger: Iterating split.splitfactor, a value equals 0.0.

Common situations: A factor file row has a zero/blank split factor parsed as 0; a split refactor changed how SplitFactor is populated; data corruption.

Related errors


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