HKUDS/Vibe-Trading · error · ValueError

index level on {day} is {raw_level!r}; index levels must be

Error message

index level on {day} is {raw_level!r}; index levels must be finite and positive to serve as a growth-factor denominator

What it means

Each benchmark level serves as a growth-factor denominator (price ratios between dates), so it must be finite and strictly positive. NaN, inf, zero, or negative levels would produce undefined or explosive PME factors.

Source

Thrown at agent/src/quantlib/fundmath.py:1384

            f"date, got {type(index_levels).__name__}"
        )
    if index_levels.empty:
        raise ValueError(
            "index_levels is empty; a public market equivalent needs a "
            "benchmark to compare against"
        )
    lookup: dict[_dt.date, float] = {}
    for raw_date, raw_level in index_levels.items():
        day = normalize_date(raw_date, field_name="index_levels date")
        if day in lookup:
            raise ValueError(
                f"index_levels has more than one entry for {day}; resolve the "
                "duplicate before calling, rather than have this function "
                "guess which one is authoritative"
            )
        level = float(raw_level)
        if not math.isfinite(level) or level <= 0.0:
            raise ValueError(
                f"index level on {day} is {raw_level!r}; index levels must be "
                "finite and positive to serve as a growth-factor denominator"
            )
        lookup[day] = level
    return lookup


def _index_level_at(
    lookup: Mapping[_dt.date, float], day: _dt.date, *, flow_description: str
) -> float:
    """Look up one date in an index lookup table, or fail loudly.

    Args:
        lookup: Table built by :func:`_index_levels_by_date`.
        day: Date to look up.
        flow_description: Human-readable description of what needed this
            date, quoted in the error message.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Drop or interpolate bad values before calling: levels = levels.dropna(); assert (levels > 0).all()
  2. Fix the vendor placeholder convention (0 or -1 for missing) during ingest
  3. Validate positivity once at load time

Example fix

# before
ks_pme(series, raw_levels)  # contains NaN and 0.0

# after
clean = raw_levels.dropna()
clean = clean[clean > 0]
ks_pme(series, clean)
Defensive patterns

Strategy: validation

Validate before calling

levels = levels.dropna()
levels = levels[numpy.isfinite(levels) & (levels > 0)]
assert not levels.empty

Prevention

When it happens

Trigger: Passing an index_levels Series containing NaN (missing close), 0.0 (placeholder fill), inf, or a negative value from a bad adjust factor.

Common situations: Un-filled holidays left as NaN; adjusted-price series with a zero from a bad split adjustment; placeholder zeros from a data vendor; -1 sentinels for missing data.

Related errors


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