HKUDS/Vibe-Trading · error · ValueError

market_caps is missing {len(missing)} asset(s) present in va

Error message

market_caps is missing {len(missing)} asset(s) present in values

What it means

When market_caps is supplied for cap-weighted centring, standardise_exposures requires caps for every asset present in values; missing tickers would force a silent fallback or NaN centre, so the mismatch is raised up front.

Source

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

    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"
            )
        aligned_caps = caps.reindex(clipped.index)
        usable = clipped.notna() & aligned_caps.notna() & (aligned_caps > 0)
        if not usable.any():
            raise ValueError("no asset has both a finite value and a positive market cap")
        weights = aligned_caps[usable]
        centre = float((clipped[usable] * weights).sum() / weights.sum())

    spread = float(clipped.dropna().std(ddof=1))
    if not np.isfinite(spread) or spread <= 0.0:
        raise ValueError(
            "the characteristic has no cross-sectional variation, so a z-score "
            "would divide by zero"
        )
    return (clipped - centre) / spread

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Reindex/merge caps onto the values index: caps = caps.reindex(values.index) and investigate the NaNs.
  2. Fix ticker normalisation so both sides use the same symbols; drop assets without caps from values if cap-weighting must proceed.

Example fix

# before
z = standardise_exposures(values, market_caps=caps)
# after
missing = values.index.difference(caps.index)
z = standardise_exposures(values.drop(index=missing), market_caps=caps)
Defensive patterns

Strategy: validation

Validate before calling

missing = values.index.difference(market_caps.index)
assert not len(missing), missing[:5]

Prevention

When it happens

Trigger: Passing a market_caps Series whose index lacks some tickers present in the characteristic values — e.g. caps snapshot taken on a different date or from a different vendor with ticker-naming differences.

Common situations: Ticker convention mismatches (BRK.B vs BRK-B), caps file lagging the universe file, or new listings not yet in the caps data.

Related errors


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