{"record":{"id":"43fbacb6035473af","repo":"HKUDS/Vibe-Trading","slug":"delay-requires-n-1-lookahead-ban-43fbac","errorCode":null,"errorMessage":"delay requires n >= 1 (lookahead ban)","messagePattern":"delay requires n >= 1 \\(lookahead ban\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"agent/src/factors/zoo/alpha101/alpha_019.py","lineNumber":62,"sourceCode":"    'extras_required': [],\n    'requires_sector': False,\n    'universe': ['equity_us', 'equity_in', 'equity_kr'],\n    'frequency': ['1D'],\n    'decay_horizon': 5,\n    'min_warmup_bars': 250,\n    'notes': 'Very long lookback (>= ~100 bars); produces NaN warmup on short panels which may trigger the >95% NaN registry guard.',\n}\n\n\ndef _rolling_sum(df: pd.DataFrame, n: int) -> pd.DataFrame:\n    \"\"\"Rolling window sum; warmup -> NaN.\"\"\"\n    return df.rolling(window=n, min_periods=n).sum()\n\n\ndef _delay(df: pd.DataFrame, n: int) -> pd.DataFrame:\n    \"\"\"Backward shift by n (lookahead-safe; n>=1 required).\"\"\"\n    if n < 1:\n        raise ValueError(\"delay requires n >= 1 (lookahead ban)\")\n    return df.shift(n)\n\n\ndef compute(panel: dict) -> pd.DataFrame:\n    \"\"\"Compute the alpha on the OHLCV+ panel and return a wide DataFrame.\"\"\"\n    close = panel[\"close\"]\n\n\n    returns = close.pct_change(fill_method=None)\n    # Helper aliases (local closures keep the file standalone & purity-safe).\n    rolling_sum = _rolling_sum\n    delay = _delay\n    out = (-1.0 * np.sign((close - delay(close, 7)) + delta(close, 7))) * (1.0 + rank(1.0 + rolling_sum(returns, 250)))\n    return out\n","sourceCodeStart":44,"sourceCodeEnd":77,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/zoo/alpha101/alpha_019.py#L44-L77","documentation":"Identical lookahead guard in alpha_019's local _delay helper: n<1 would shift data forward in time (future leak), so a ValueError is raised before shift. All zoo modules duplicate this guard to stay self-contained.","triggerScenarios":"alpha_019's compute invoking _delay with n<=0 via a mis-transcribed formula term.","commonSituations":"Formula porting errors where (-delay) signs get flipped; sweeping helper parameters down to 0.","solutions":["Correct the delay argument to >=1","Use the raw frame when zero-lag is truly intended"],"exampleFix":"# before\n_delay(x, 0)\n# after\nx  # zero-lag means no shift needed","handlingStrategy":"validation","validationCode":"assert delay_n >= 1, 'lookahead ban'","typeGuard":"def valid_delay(n: int) -> bool:\n    return isinstance(n, int) and n >= 1","tryCatchPattern":null,"preventionTips":["Cross-check ports against the published formula table","Never parameterize delay below 1"],"tags":["lookahead-bias","validation","alpha101"],"backgroundTag":"invalid-argument-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}