{"record":{"id":"4190ec48f5059fc6","repo":"HKUDS/Vibe-Trading","slug":"estimation-window-needs-at-least-min-estimation-o","errorCode":null,"errorMessage":"estimation window needs at least {MIN_ESTIMATION_OBSERVATIONS} finite observations, got {n}","messagePattern":"estimation window needs at least (.+?) finite observations, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/eventstudy.py","lineNumber":241,"sourceCode":"            model (beta would be undefined).\n    \"\"\"\n    if model not in NORMAL_RETURN_MODELS:\n        raise ValueError(\n            f\"model must be one of {NORMAL_RETURN_MODELS}, got {model!r}\"\n        )\n\n    asset = np.asarray(asset_returns, dtype=float).ravel()\n    market = np.asarray(market_returns, dtype=float).ravel()\n    if asset.size != market.size:\n        raise ValueError(\n            f\"asset and market must be the same length, got {asset.size} and {market.size}\"\n        )\n\n    keep = np.isfinite(asset) & np.isfinite(market)\n    asset, market = asset[keep], market[keep]\n    n = asset.size\n    if n < MIN_ESTIMATION_OBSERVATIONS:\n        raise ValueError(\n            f\"estimation window needs at least {MIN_ESTIMATION_OBSERVATIONS} \"\n            f\"finite observations, got {n}\"\n        )\n\n    market_mean = float(market.mean())\n    market_sum_squares = float(np.sum((market - market_mean) ** 2))\n\n    if model == \"market\":\n        if market_sum_squares <= 0.0:\n            raise ValueError(\n                \"market returns are constant over the estimation window, so beta \"\n                \"is not identified; use model='mean_adjusted'\"\n            )\n        beta = float(np.sum((market - market_mean) * (asset - asset.mean())) / market_sum_squares)\n        alpha = float(asset.mean() - beta * market_mean)\n        residuals = asset - (alpha + beta * market)\n        dof = n - 2\n    elif model == \"market_adjusted\":","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/eventstudy.py#L223-L259","documentation":"Raised by estimate_market_model when, after dropping non-finite observations, the estimation window contains fewer than MIN_ESTIMATION_OBSERVATIONS usable (asset, market) return pairs. The market model needs a minimum sample to produce meaningful alpha/beta estimates, so the library refuses rather than returning noisy parameters.","triggerScenarios":"Calling event_study (or estimate_market_model directly) with an estimation_window shorter than the minimum, NaN/inf values in either return series over the estimation window, or market_returns missing labels so the intersection shrinks below the threshold.","commonSituations":"Short back-history for a newly listed asset, holidays/missing dates in the market index alignment, early sample periods where the rolling window runs off the start of the data, or a data pipeline leaking NaNs.","solutions":["Inspect the estimation window slice for NaN/inf: asset[start:end].dropna() and count the rows.","Increase estimation_window or shift the event date so at least MIN_ESTIMATION_OBSERVATIONS finite overlapping observations exist.","Align market_returns to returns.index (fill or reindex) before calling event_study."],"exampleFix":"# before\ncar = event_study(returns, market, events, estimation_window=20)\n# after\ncar = event_study(returns.dropna(), market.reindex(returns.index).ffill(), events, estimation_window=120)","handlingStrategy":"validation","validationCode":"finite = np.isfinite(asset[est_slice]) & np.isfinite(market[est_slice])\nassert finite.sum() >= MIN_ESTIMATION_OBSERVATIONS, finite.sum()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Drop NaN returns before calling event_study.","Reindex market_returns onto returns.index and forward-fill gaps.","Keep estimation_window >= MIN_ESTIMATION_OBSERVATIONS."],"tags":["event-study","numpy","validation","minimum-sample"],"backgroundTag":"insufficient-data-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}