HKUDS/Vibe-Trading · error · ValueError
delay requires n >= 1 (lookahead ban)
Error message
delay requires n >= 1 (lookahead ban)
What it means
In alpha_036.py the _delay helper rejects n < 1 to keep the factor lookahead-safe; delay 0 would leak the current bar into a signal meant to use only past data. The ValueError fires before df.shift(n) is ever called.
Source
Thrown at agent/src/factors/zoo/alpha101/alpha_036.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 compute(panel: dict) -> pd.DataFrame:
"""Compute the alpha on the OHLCV+ panel and return a wide DataFrame."""
close = panel["close"]
open_ = panel["open"]
volume = panel["volume"]
vwap = panel["vwap"]
adv20 = ts_mean(volume, 20)
returns = close.pct_change(fill_method=None)
# Helper aliases (local closures keep the file standalone & purity-safe).
rolling_sum = _rolling_sum
delay = _delay
t1 = 2.21 * rank(ts_corr((close - open_), delay(volume, 1), 15))
t2 = 0.7 * rank(open_ - close)
t3 = 0.73 * rank(ts_rank(delay(-1.0 * returns, 6), 5))
t4 = rank(ts_corr(vwap, adv20, 6).abs())View on GitHub (pinned to 80ffdda44c)
Solutions
- Grep _delay( in alpha_036.py and verify every literal argument >= 1
- Substitute the raw frame where delay 0 was intended
- Validate externally supplied windows before compute(): `assert all(n >= 1 for n in windows)`
- Re-run the zoo test suite for alpha_036
Example fix
// before r = _delay(rank(volume), 0) * -1 // after r = rank(volume) * -1
Defensive patterns
Strategy: validation
Validate before calling
n = int(n)
if n < 1:
raise ValueError(f"delay window must be >= 1, got {n}")
result = _delay(close, n) Type guard
def is_valid_delay(n: int) -> bool:
return isinstance(n, int) and not isinstance(n, bool) and n >= 1 Prevention
- Use the unshifted frame when 'today' is intended
- Reject parameter sweeps containing lag 0 before compute
- Add fixture-panel smoke tests per alpha
When it happens
Trigger: Any _delay(df, n) invocation inside compute() for alpha #36 with n == 0 or negative — e.g. a window constant typo or a dynamic expression evaluating to 0 on edge inputs.
Common situations: Literal translation of the published alpha formula that includes delay(x, 0); global search-replace renaming variables and dropping a '1' to '0'; config files where delay defaults to 0 when unset.
Related errors
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/4732b928c552817a.
Report an issue: GitHub.