HKUDS/Vibe-Trading · error · ValueError

delay requires n >= 1 (lookahead ban)

Error message

delay requires n >= 1 (lookahead ban)

What it means

In alpha_083.py, _delay enforces the lookahead ban by raising ValueError when n < 1 before df.shift(n). Any lag of 0 or below in the alpha's chain aborts compute immediately with this message.

Source

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

    'extras_required': [],
    'requires_sector': False,
    'universe': ['equity_us', 'equity_in', 'equity_kr'],
    'frequency': ['1D'],
    'decay_horizon': 5,
    'min_warmup_bars': 7,
    '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 _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"]
    high = panel["high"]
    low = panel["low"]
    volume = panel["volume"]
    vwap = panel["vwap"]


    # Helper aliases (local closures keep the file standalone & purity-safe).
    rolling_sum = _rolling_sum
    delay = _delay
    rng_avg = safe_div((high - low), rolling_sum(close, 5) / 5.0)
    num = rank(delay(rng_avg, 2)) * rank(rank(volume))
    denom = safe_div(rng_avg, vwap - close)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Inspect all _delay calls in alpha_083.py; make each argument >= 1
  2. Substitute the raw frame where delay 0 was intended
  3. Constrain lag sweeps to start at 1 (range(1, max_lag + 1))
  4. Add a compute() smoke test

Example fix

// before
w = _delay(close, 0) * 0.5 + _delay(close, 1) * 0.5
// after
w = close * 0.5 + _delay(close, 1) * 0.5
Defensive patterns

Strategy: validation

Validate before calling

lags = range(1, max_lag + 1)  # sweeps start at 1, never 0
assert all(n >= 1 for n in lags)

Type guard

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

Prevention

When it happens

Trigger: compute() for alpha #83 passes a non-positive lag to _delay — e.g. `_delay(x, n)` where n was meant to be 1 but typed/configured as 0.

Common situations: Porting Alpha#83's weighted-delay formula and dropping a lag; tuning scripts iterating lags from 0; copy-paste from sibling alpha files.

Related errors


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