HKUDS/Vibe-Trading · critical · ValueError
delay requires n >= 1 (lookahead ban)
Error message
delay requires n >= 1 (lookahead ban)
What it means
alpha_020's copy of the shared _delay lookahead guard; n<1 is rejected because shift(0) returns present values (no lag) and negative n would use future rows — both violate the no-lookahead contract.
Source
Thrown at agent/src/factors/zoo/alpha101/alpha_020.py:57
'id': 'alpha101_020',
'nickname': 'Kakushadze Alpha #20',
'theme': ['reversal'],
'formula_latex': '(((-1*rank(open-delay(high,1)))*rank(open-delay(close,1)))*rank(open-delay(low,1)))',
'columns_required': ['open', 'high', 'low', 'close'],
'extras_required': [],
'requires_sector': False,
'universe': ['equity_us', 'equity_in', 'equity_kr'],
'frequency': ['1D'],
'decay_horizon': 5,
'min_warmup_bars': 2,
'notes': '',
}
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"]
high = panel["high"]
low = panel["low"]
# Helper aliases (local closures keep the file standalone & purity-safe).
delay = _delay
out = ((-1.0 * rank(open_ - delay(high, 1))) * rank(open_ - delay(close, 1))) * rank(open_ - delay(low, 1))
return out
View on GitHub (pinned to 80ffdda44c)
Solutions
- Set the delay to a positive int matching the spec
- Replace zero-lag calls with direct use of the frame
Example fix
# before _delay(close, -2) # after _delay(close, 2)
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
- Keep delay constants positive literals in zoo code
- Review sign flips when editing formulas
When it happens
Trigger: alpha_020's formula calling _delay with a non-positive n during compute on the panel.
Common situations: Transcription of the published formula where a negative sign was meant as ranking direction, not delay; parameter sweeps hitting 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
- 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/c3df24d3e56bb062.
Report an issue: GitHub.