HKUDS/Vibe-Trading · error · ValueError
delay requires n >= 1 (lookahead ban)
Error message
delay requires n >= 1 (lookahead ban)
What it means
The _delay guard in alpha_052.py rejects n < 1 to keep the alpha lookahead-safe: df.shift(0) would expose the current bar, so ValueError is raised before shifting. The rolling helper directly above shows this file mixes windows and lags; only the lag argument can trigger it.
Source
Thrown at agent/src/factors/zoo/alpha101/alpha_052.py:62
'extras_required': [],
'requires_sector': False,
'universe': ['equity_us', 'equity_in', 'equity_kr'],
'frequency': ['1D'],
'decay_horizon': 5,
'min_warmup_bars': 240,
'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"]
low = panel["low"]
volume = panel["volume"]
returns = close.pct_change(fill_method=None)
# Helper aliases (local closures keep the file standalone & purity-safe).
rolling_sum = _rolling_sum
delay = _delay
out = ((-1.0 * ts_min(low, 5)) + delay(ts_min(low, 5), 5)) * rank((rolling_sum(returns, 240) - rolling_sum(returns, 20)) / 220.0) * ts_rank(volume, 5)
return out
View on GitHub (pinned to 80ffdda44c)
Solutions
- Verify every _delay argument in alpha_052.py is an int >= 1
- Use the operand directly if current-bar access is intended
- Validate lag configs at ingestion; reject < 1 early with a descriptive error
- Re-run compute against a fixture panel
Example fix
// before val = _delay(_sum(close, 5), 0) // after val = _sum(close, 5)
Defensive patterns
Strategy: validation
Validate before calling
if window < 1 or lag < 1:
raise ValueError(f'window and lag must be >= 1, got window={window}, lag={lag}')
out = _delay(_sum(close, window), lag) Type guard
def is_valid_delay(n: int) -> bool:
return isinstance(n, int) and not isinstance(n, bool) and n >= 1 Prevention
- Don't confuse window args with lag args when editing
- Use the unshifted value for lag 0 intent
- Validate combined window/lag configs upfront
When it happens
Trigger: A _delay(df, n) call with n <= 0 inside alpha #52's compute(), e.g. from a lag constant typo or computed window collapsing to 0.
Common situations: Transcribing Alpha#52 (which pairs rolling sums with delays) and swapping a window/lag value; refactors of the shared helper block; config-driven lag lists containing 0.
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/3cb9b4e9be42fc59.
Report an issue: GitHub.