{"record":{"id":"c3df24d3e56bb062","repo":"HKUDS/Vibe-Trading","slug":"delay-requires-n-1-lookahead-ban-c3df24","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_020.py","lineNumber":57,"sourceCode":"    'id': 'alpha101_020',\n    'nickname': 'Kakushadze Alpha #20',\n    'theme': ['reversal'],\n    'formula_latex': '(((-1*rank(open-delay(high,1)))*rank(open-delay(close,1)))*rank(open-delay(low,1)))',\n    'columns_required': ['open', 'high', 'low', 'close'],\n    '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': 2,\n    'notes': '',\n}\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    open_ = panel[\"open\"]\n    high = panel[\"high\"]\n    low = panel[\"low\"]\n\n\n    # Helper aliases (local closures keep the file standalone & purity-safe).\n    delay = _delay\n    out = ((-1.0 * rank(open_ - delay(high, 1))) * rank(open_ - delay(close, 1))) * rank(open_ - delay(low, 1))\n    return out\n","sourceCodeStart":39,"sourceCodeEnd":73,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/zoo/alpha101/alpha_020.py#L39-L73","documentation":"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.","triggerScenarios":"alpha_020's formula calling _delay with a non-positive n during compute on the panel.","commonSituations":"Transcription of the published formula where a negative sign was meant as ranking direction, not delay; parameter sweeps hitting 0.","solutions":["Set the delay to a positive int matching the spec","Replace zero-lag calls with direct use of the frame"],"exampleFix":"# before\n_delay(close, -2)\n# after\n_delay(close, 2)","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":["Keep delay constants positive literals in zoo code","Review sign flips when editing formulas"],"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"}