QuantConnect/Lean · error · RegressionTestException

Unexpected universe data count {historicalSelectionData.Coun

Error message

Unexpected universe data count {historicalSelectionData.Count}

What it means

In Initialize, History(universe, 3) fetches 3 bars of the custom StockDataSource universe and asserts the result count is exactly 3. A mismatch means the universe history request returned fewer or more selections than requested — typically because the Dropbox remote CSV was unreachable, empty, or returned a different number of dated rows.

Source

Thrown at Algorithm.CSharp/DropboxBaseDataUniverseSelectionAlgorithm.cs:63

        {
            UniverseSettings.Resolution = Resolution.Daily;

            // Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
            // Commented so regression algorithm is more sensitive
            //Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;

            SetStartDate(2017, 07, 06);
            SetEndDate(2018, 07, 04);

            var universe = AddUniverse<StockDataSource>(stockDataSource =>
            {
                return stockDataSource.OfType<StockDataSource>().SelectMany(x => x.Symbols);
            });

            var historicalSelectionData = History(universe, 3).ToList();
            if (historicalSelectionData.Count != 3)
            {
                throw new RegressionTestException($"Unexpected universe data count {historicalSelectionData.Count}");
            }

            foreach (var universeData in historicalSelectionData)
            {
                var stockDataSource = (StockDataSource)universeData.Single();
                if (stockDataSource.Symbols.Count != 5)
                {
                    throw new RegressionTestException($"Unexpected universe data receieved");
                }
            }
        }

        /// <summary>
        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
        /// </summary>
        /// <code>
        /// TradeBars bars = slice.Bars;
        /// Ticks ticks = slice.Ticks;

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify the Dropbox BacktestUrl is reachable and returns the expected CSV format (date,symbol1,symbol2,...).
  2. Confirm the algorithm start date (2017-07-06) has at least 3 prior trading days of universe data.
  3. Log inside StockDataSource.Reader to catch null returns from parse errors.
  4. If the data source is volatile, cache the CSV locally or vendor it into the repo for deterministic regression.
Defensive patterns

Strategy: validation

Validate before calling

var historicalSelectionData = History(universe, 3).ToList();
if (historicalSelectionData.Count != 3)
{
    Debug($"Universe history returned {historicalSelectionData.Count}; check Dropbox CSV reachability");
}

Prevention

When it happens

Trigger: The Dropbox backtest CSV (daily-stock-picker-backtest.csv) is unreachable or returns fewer than 3 dated rows for the 3-bar lookback, or Reader returns null for some rows so they are dropped from the history result.

Common situations: Network/Dropbox URL change or rate-limiting in CI, the CSV having fewer rows than the lookback period near the algorithm start (2017-07-06), or a Reader parse error returning null.

Related errors


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