HKUDS/Vibe-Trading · error · KeyError

vwap({market.value}) requires panel keys {required}; missing

Error message

vwap({market.value}) requires panel keys {required}; missing {missing}

What it means

For non-CN markets, vwap falls back to the typical price (open+high+low+close)/4. If any of those four OHLC columns is absent from the panel (and no precomputed 'vwap' exists), KeyError lists the missing keys.

Source

Thrown at agent/src/factors/base.py:354

    - ``crypto``: prefer ``panel["vwap"]`` if provided, else typical price.

    Any missing required column → NaN propagation; never silent zero.
    """
    if isinstance(market, str):
        market = Market(market)

    if "vwap" in panel:
        return panel["vwap"]

    if market is Market.EQUITY_CN:
        if "amount" not in panel or "volume" not in panel:
            raise KeyError("vwap(equity_cn) requires panel['amount'] and panel['volume']")
        return safe_div(panel["amount"] * 1000.0, panel["volume"] * 100.0 + 1.0)

    required = ("open", "high", "low", "close")
    missing = [k for k in required if k not in panel]
    if missing:
        raise KeyError(f"vwap({market.value}) requires panel keys {required}; missing {missing}")
    return (panel["open"] + panel["high"] + panel["low"] + panel["close"]) / 4.0

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Add the missing OHLC columns to the panel
  2. Or provide a precomputed panel['vwap'] column
  3. Check column naming/casing after data ingestion

Example fix

# before
panel = {'close': close_df}
vwap(panel, Market.EQUITY_US)  # KeyError
# after
panel = {'open': o, 'high': h, 'low': l, 'close': c}
vwap(panel, Market.EQUITY_US)
Defensive patterns

Strategy: validation

Validate before calling

required = ('open', 'high', 'low', 'close')
missing = [k for k in required if k not in panel]
assert not missing, f'missing OHLC: {missing}'

Type guard

def has_ohlc(panel: dict) -> bool:
    return all(k in panel for k in ('open', 'high', 'low', 'close')) or 'vwap' in panel

Try / catch

try:
    v = vwap(panel, market)
except KeyError as e:
    v = panel['close']  # degrade to close as proxy

Prevention

When it happens

Trigger: Calling vwap(panel, Market.EQUITY_US) (or any non-CN market) on a panel missing 'open', 'high', 'low', or 'close'.

Common situations: Panels built only from close prices, columns renamed during preprocessing (e.g. 'Open' capitalized), or a thin test fixture omitting OHLC fields.

Related errors


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