HKUDS/Vibe-Trading · critical · ValueError

delay requires n >= 1 (lookahead ban)

Error message

delay requires n >= 1 (lookahead ban)

What it means

alpha_029's _delay guard: delay counts must be >=1 to be lookahead-safe; n<1 raises ValueError before df.shift(n). Consistent with all Alpha101 zoo modules.

Source

Thrown at agent/src/factors/zoo/alpha101/alpha_029.py:67

    'min_warmup_bars': 12,
    'notes': '',
}


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 _rolling_prod(df: pd.DataFrame, n: int) -> pd.DataFrame:
    """Rolling window product; warmup -> NaN."""
    return df.rolling(window=n, min_periods=n).apply(np.prod, raw=True)


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
    rolling_prod = _rolling_prod
    delay = _delay
    inner = rank(rank(-1.0 * rank(delta(close - 1.0, 5))))
    inner = ts_min(inner, 2)
    inner = rolling_sum(inner, 1)
    inner = np.log(inner.where(inner > 0))
    inner = scale(inner)
    inner = rank(rank(inner))
    inner = rolling_prod(inner, 1)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Correct the argument to >=1
  2. Use the unshifted frame for zero-lag intent

Example fix

# before
_delay(rank_ret, 0)
# after
rank_ret
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_029 compute hitting a _delay call with n<=0 due to a transcription/parameter error in the formula.

Common situations: Formula ports misreading (-d) terms; programmatic parameterization allowing 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/34e8d9b9054e0a37. Report an issue: GitHub.