HKUDS/Vibe-Trading · error · ValueError

a cross-section needs at least {MIN_CROSS_SECTION} finite va

Error message

a cross-section needs at least {MIN_CROSS_SECTION} finite values to standardise, got {finite.size}

What it means

standardise_exposures needs at least MIN_CROSS_SECTION finite values in the cross-section to compute a meaningful dispersion for z-scoring; with fewer names the standard deviation estimate is too noisy to be a useful exposure.

Source

Thrown at agent/src/quantlib/factormodel.py:273

        market_caps: Market capitalisation on the same index, used for the mean.
            When None, the mean is equal-weighted.
        winsorise: Fraction trimmed from each tail, in ``[0, 0.5)``.

    Returns:
        Standardised exposures on the input index.

    Raises:
        ValueError: If ``winsorise`` is outside ``[0, 0.5)``, if fewer than
            :data:`MIN_CROSS_SECTION` finite values are present, or if
            ``market_caps`` does not cover the same index.
    """
    if not 0.0 <= winsorise < 0.5:
        raise ValueError(f"winsorise must be in [0, 0.5), got {winsorise}")

    series = pd.Series(values, dtype=float)
    finite = series.dropna()
    if finite.size < MIN_CROSS_SECTION:
        raise ValueError(
            f"a cross-section needs at least {MIN_CROSS_SECTION} finite values to "
            f"standardise, got {finite.size}"
        )

    if winsorise > 0:
        lower, upper = finite.quantile(winsorise), finite.quantile(1.0 - winsorise)
        clipped = series.clip(lower=lower, upper=upper)
    else:
        clipped = series

    if market_caps is None:
        centre = float(clipped.dropna().mean())
    else:
        caps = pd.Series(market_caps, dtype=float)
        missing = series.index.difference(caps.index)
        if len(missing):
            raise ValueError(
                f"market_caps is missing {len(missing)} asset(s) present in values"

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Count finite values first: s = pd.Series(values); s.notna().sum().
  2. Widen the universe or use a characteristic with better coverage; drop the factor for dates where coverage is below the floor.

Example fix

# before
z = standardise_exposures(char_values)  # only 8 finite
# after
if char_values.dropna().size >= MIN_CROSS_SECTION:
    z = standardise_exposures(char_values)
else:
    z = None  # skip factor for this date
Defensive patterns

Strategy: validation

Validate before calling

from quantlib.factormodel import MIN_CROSS_SECTION
assert pd.Series(values).dropna().size >= MIN_CROSS_SECTION

Prevention

When it happens

Trigger: Calling with a values array/Series containing fewer than MIN_CROSS_SECTION non-NaN entries — e.g. a universe of 5 stocks, or heavy NaN coverage from a sparse characteristic.

Common situations: Small pilot universes, point-in-time data where a characteristic only covers large caps, or filtering steps that shrink the cross-section below the floor.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/92ef3299ecf0112f. Report an issue: GitHub.