HKUDS/Vibe-Trading · critical · ValueError

delay requires n >= 1 (lookahead ban)

Error message

delay requires n >= 1 (lookahead ban)

What it means

Identical lookahead guard in alpha_019's local _delay helper: n<1 would shift data forward in time (future leak), so a ValueError is raised before shift. All zoo modules duplicate this guard to stay self-contained.

Source

Thrown at agent/src/factors/zoo/alpha101/alpha_019.py:62

    'extras_required': [],
    'requires_sector': False,
    'universe': ['equity_us', 'equity_in', 'equity_kr'],
    'frequency': ['1D'],
    'decay_horizon': 5,
    'min_warmup_bars': 250,
    'notes': 'Very long lookback (>= ~100 bars); produces NaN warmup on short panels which may trigger the >95% NaN registry guard.',
}


def _rolling_sum(df: pd.DataFrame, n: int) -> pd.DataFrame:
    """Rolling window sum; warmup -> NaN."""
    return df.rolling(window=n, min_periods=n).sum()


def _delay(df: pd.DataFrame, n: int) -> pd.DataFrame:
    """Backward shift by n (lookahead-safe; n>=1 required)."""
    if n < 1:
        raise ValueError("delay requires n >= 1 (lookahead ban)")
    return df.shift(n)


def compute(panel: dict) -> pd.DataFrame:
    """Compute the alpha on the OHLCV+ panel and return a wide DataFrame."""
    close = panel["close"]


    returns = close.pct_change(fill_method=None)
    # Helper aliases (local closures keep the file standalone & purity-safe).
    rolling_sum = _rolling_sum
    delay = _delay
    out = (-1.0 * np.sign((close - delay(close, 7)) + delta(close, 7))) * (1.0 + rank(1.0 + rolling_sum(returns, 250)))
    return out

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Correct the delay argument to >=1
  2. Use the raw frame when zero-lag is truly intended

Example fix

# before
_delay(x, 0)
# after
x  # zero-lag means no shift needed
Defensive patterns

Strategy: validation

Validate before calling

assert delay_n >= 1, 'lookahead ban'

Type guard

def valid_delay(n: int) -> bool:
    return isinstance(n, int) and n >= 1

Prevention

When it happens

Trigger: alpha_019's compute invoking _delay with n<=0 via a mis-transcribed formula term.

Common situations: Formula porting errors where (-delay) signs get flipped; sweeping helper parameters down to 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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