HKUDS/Vibe-Trading · error · ValueError
delay requires n >= 1 (lookahead ban)
Error message
delay requires n >= 1 (lookahead ban)
What it means
In alpha_049.py, _delay enforces n >= 1 (lookahead ban) and raises ValueError on violation before df.shift runs. The neighboring _make_one helper shows the alpha builds conditional outputs, but the error always comes from the lag argument itself.
Source
Thrown at agent/src/factors/zoo/alpha101/alpha_049.py:57
'id': 'alpha101_049',
'nickname': 'Kakushadze Alpha #49',
'theme': ['momentum'],
'formula_latex': '(((delay(close,20)-delay(close,10))/10 - (delay(close,10)-close)/10) < -0.1) ? 1 : -1*(close-delay(close,1))',
'columns_required': ['close'],
'extras_required': [],
'requires_sector': False,
'universe': ['equity_us', 'equity_in', 'equity_kr'],
'frequency': ['1D'],
'decay_horizon': 5,
'min_warmup_bars': 21,
'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 _make_one(ref: pd.DataFrame) -> pd.DataFrame:
"""A DataFrame of 1.0 with the same shape/index/columns as ``ref``."""
return pd.DataFrame(1.0, index=ref.index, columns=ref.columns)
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)):View on GitHub (pinned to 80ffdda44c)
Solutions
- Check each _delay argument in alpha_049.py against the intended formula
- Use the unshifted operand for lag 0 semantics
- Validate external lag parameters before compute() and fail with context
- Smoke-test the factor after the fix
Example fix
// before term = _delay(close, 0) - _delay(close, 3) // after term = close - _delay(close, 3)
Defensive patterns
Strategy: validation
Validate before calling
cleaned = [int(l) for l in lag_list if int(l) >= 1]
if not cleaned:
raise ValueError('at least one valid lag (>= 1) required') Type guard
def is_valid_delay(n: int) -> bool:
return isinstance(n, int) and not isinstance(n, bool) and n >= 1 Prevention
- Never port 'delay(x, 0)' literally
- Validate sweep grids for n >= 1
- Use raw frame for identity lag
When it happens
Trigger: A _delay(df, n) call with n <= 0 inside alpha #49's compute path — commonly a 0 typed in place of 1, or a lag derived as `k - 1` when k == 1.
Common situations: Manual transcription of Alpha#49's formula; copy-paste between alpha files; parameter grids including degenerate lags.
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/f97d265ece397ba8.
Report an issue: GitHub.