HKUDS/Vibe-Trading · error · ValueError

estimation_gap must be >= 0, got {estimation_gap}

Error message

estimation_gap must be >= 0, got {estimation_gap}

What it means

event_study requires estimation_gap — the number of trading days kept between the estimation window and the event window to avoid contamination — to be non-negative. A negative gap would make the estimation window overlap or run past the event, biasing normal-return estimates.

Source

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

            window so the model cannot see the event.
        model: One of :data:`NORMAL_RETURN_MODELS`.

    Returns:
        An :class:`EventStudyResult`. Events that cannot be measured -- unknown
        symbol, event date before the frame starts, not enough estimation rows,
        an all-NaN window -- appear in ``dropped`` with a reason instead of
        being silently skipped.

    Raises:
        ValueError: If the window bounds are inconsistent, ``estimation_gap`` is
            negative, ``model`` is unknown, the market series does not cover the
            frame's index, or no event at all could be measured.
    """
    start, end = event_window
    if start > end:
        raise ValueError(f"event_window start must be <= end, got {event_window}")
    if estimation_gap < 0:
        raise ValueError(f"estimation_gap must be >= 0, got {estimation_gap}")
    if estimation_window < MIN_ESTIMATION_OBSERVATIONS:
        raise ValueError(
            f"estimation_window must be at least {MIN_ESTIMATION_OBSERVATIONS}, "
            f"got {estimation_window}"
        )
    if model not in NORMAL_RETURN_MODELS:
        raise ValueError(f"model must be one of {NORMAL_RETURN_MODELS}, got {model!r}")
    if not events:
        raise ValueError("events is empty")

    index = returns.index
    missing_market = index.difference(market_returns.index)
    if len(missing_market):
        raise ValueError(
            f"market_returns is missing {len(missing_market)} label(s) present in "
            "returns; align them before calling"
        )
    market_aligned = market_returns.reindex(index)

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Clamp or correct the gap: estimation_gap = max(0, computed_gap).
  2. Re-check the convention: gap counts days strictly between the estimation window end and the event window start.

Example fix

# before
result = event_study(..., estimation_gap=event_start - est_end)  # can be negative
# after
result = event_study(..., estimation_gap=max(0, event_start - est_end))
Defensive patterns

Strategy: validation

Validate before calling

assert estimation_gap >= 0

Prevention

When it happens

Trigger: Passing estimation_gap=-5 or any negative value, typically when computing the gap as a difference that can go negative for event windows extending far back.

Common situations: Parameter arithmetic (e.g. estimation_gap = pre_event_len - window_len) yielding negatives, config typos, or a copy-paste from code using the opposite sign convention.

Related errors


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