HKUDS/Vibe-Trading · critical · ValueError

delay requires n >= 1 (lookahead ban)

Error message

delay requires n >= 1 (lookahead ban)

What it means

alpha_024's local _delay enforces the same n>=1 rule to prevent lookahead. The ValueError fires before shift, keeping any future-leaking computation from silently producing results.

Source

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

    'extras_required': [],
    'requires_sector': False,
    'universe': ['equity_us', 'equity_in', 'equity_kr'],
    'frequency': ['1D'],
    'decay_horizon': 5,
    'min_warmup_bars': 200,
    '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 _where_ternary(cond, a, b):
    """Vectorised ternary `(cond ? a : b)` returning a DataFrame.

    ``cond`` is a boolean DataFrame; ``a`` / ``b`` may be DataFrame or scalar.
    """
    if isinstance(a, (int, float)):
        a_arr = np.full_like(cond.to_numpy(dtype=np.float64), float(a))
    else:
        a_arr = a.to_numpy(dtype=np.float64, na_value=np.nan)
    if isinstance(b, (int, float)):
        b_arr = np.full_like(cond.to_numpy(dtype=np.float64), float(b))
    else:
        b_arr = b.to_numpy(dtype=np.float64, na_value=np.nan)
    cond_arr = cond.to_numpy(dtype=bool, na_value=False) if hasattr(cond, "to_numpy") else np.asarray(cond, dtype=bool)
    out = np.where(cond_arr, a_arr, b_arr)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Restore/verify the delay constant as a positive integer
  2. Bypass _delay for zero-lag semantics

Example fix

# before
_DELAY = 0
// after
_DELAY = 1
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: Calling alpha_024's compute when its internal delay expression evaluates to 0 or negative (bad constant or edited formula).

Common situations: Editing zoo constants (window/delay params) while experimenting; copy-pasting between factor files with changed signs.

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/836efe411647d916. Report an issue: GitHub.