HKUDS/Vibe-Trading · error · ValueError

market returns are constant over the estimation window, so b

Error message

market returns are constant over the estimation window, so beta is not identified; use model='mean_adjusted'

What it means

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.

Source

Thrown at agent/src/quantlib/eventstudy.py:251

        raise ValueError(
            f"asset and market must be the same length, got {asset.size} and {market.size}"
        )

    keep = np.isfinite(asset) & np.isfinite(market)
    asset, market = asset[keep], market[keep]
    n = asset.size
    if n < MIN_ESTIMATION_OBSERVATIONS:
        raise ValueError(
            f"estimation window needs at least {MIN_ESTIMATION_OBSERVATIONS} "
            f"finite observations, got {n}"
        )

    market_mean = float(market.mean())
    market_sum_squares = float(np.sum((market - market_mean) ** 2))

    if model == "market":
        if market_sum_squares <= 0.0:
            raise ValueError(
                "market returns are constant over the estimation window, so beta "
                "is not identified; use model='mean_adjusted'"
            )
        beta = float(np.sum((market - market_mean) * (asset - asset.mean())) / market_sum_squares)
        alpha = float(asset.mean() - beta * market_mean)
        residuals = asset - (alpha + beta * market)
        dof = n - 2
    elif model == "market_adjusted":
        alpha, beta = 0.0, 1.0
        residuals = asset - market
        dof = n
    else:  # mean_adjusted
        alpha, beta = float(asset.mean()), 0.0
        residuals = asset - alpha
        dof = n - 1

    residual_std = float(np.sqrt(np.sum(residuals**2) / dof)) if dof > 0 else float("nan")

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check market_returns over the estimation window: float(market.std()); if it is ~0 the data is bad.
  2. Use model='mean_adjusted' as the message suggests when beta genuinely cannot be estimated.
  3. Fix the market data source (unforward-fill, use real index returns, increase price precision).

Example fix

# before
result = event_study(returns, market, events, model="market")
# after
result = event_study(returns, market, events, model="mean_adjusted")
Defensive patterns

Strategy: fallback

Validate before calling

if np.std(market_over_window) < 1e-12:
    model = "mean_adjusted"

Try / catch

try:
    res = event_study(..., model="market")
except ValueError:
    res = event_study(..., model="mean_adjusted")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/e21a26788f8460f8. Report an issue: GitHub.