{"record":{"id":"e21a26788f8460f8","repo":"HKUDS/Vibe-Trading","slug":"market-returns-are-constant-over-the-estimation-wi","errorCode":null,"errorMessage":"market returns are constant over the estimation window, so beta is not identified; use model='mean_adjusted'","messagePattern":"market returns are constant over the estimation window, so beta is not identified; use model='mean_adjusted'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/eventstudy.py","lineNumber":251,"sourceCode":"        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\":\n        alpha, beta = 0.0, 1.0\n        residuals = asset - market\n        dof = n\n    else:  # mean_adjusted\n        alpha, beta = float(asset.mean()), 0.0\n        residuals = asset - alpha\n        dof = n - 1\n\n    residual_std = float(np.sqrt(np.sum(residuals**2) / dof)) if dof > 0 else float(\"nan\")\n","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/eventstudy.py#L233-L269","documentation":"estimate_market_model raises this when the market return series is constant over the estimation window (zero variance), making OLS beta unidentified — any beta fits equally well. The library detects this via zero sum of squared deviations of market returns and suggests the mean_adjusted model which does not use beta.","triggerScenarios":"Passing model='market' (or market_adjusted) to event_study where the market series is flat: a dummy/simulated constant market, a stale feed repeating the same price, or a market proxy that resolves to a constant over the window.","commonSituations":"Unit tests with synthetic flat data, sandbox/paper feeds that return a constant quote, weekend gaps filled with forward-fill producing constant returns, or an index with too few decimal places so daily returns round to zero.","solutions":["Check market_returns over the estimation window: float(market.std()); if it is ~0 the data is bad.","Use model='mean_adjusted' as the message suggests when beta genuinely cannot be estimated.","Fix the market data source (unforward-fill, use real index returns, increase price precision)."],"exampleFix":"# before\nresult = event_study(returns, market, events, model=\"market\")\n# after\nresult = event_study(returns, market, events, model=\"mean_adjusted\")","handlingStrategy":"fallback","validationCode":"if np.std(market_over_window) < 1e-12:\n    model = \"mean_adjusted\"","typeGuard":null,"tryCatchPattern":"try:\n    res = event_study(..., model=\"market\")\nexcept ValueError:\n    res = event_study(..., model=\"mean_adjusted\")","preventionTips":["Sanity-check market volatility per window in data-validation jobs.","Avoid forward-filled synthetic prices in market series."],"tags":["event-study","ols","unidentified-parameter"],"backgroundTag":"singular-matrix-unidentified-regression","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}