HKUDS/Vibe-Trading · error · ValueError

event_window start must be <= end, got {event_window}

Error message

event_window start must be <= end, got {event_window}

What it means

event_study validates that the (start, end) tuple defining the event window in relative days is internally consistent: start must not exceed end. A reversed tuple would silently produce an empty window, so it is rejected up front.

Source

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

        estimation_window: Rows used to fit the normal-return model.
        estimation_gap: Rows left between the estimation window and the event
            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"

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Swap the tuple so the earlier relative day comes first: event_window=(start, end) with start <= end.
  2. If bounds come from configuration, normalise them: lo, hi = sorted(event_window).

Example fix

# before
result = event_study(returns, market, events, event_window=(5, -5))
# after
lo, hi = sorted(event_window)
result = event_study(returns, market, events, event_window=(lo, hi))
Defensive patterns

Strategy: validation

Validate before calling

start, end = event_window
assert start <= end

Type guard

def is_valid_event_window(w: tuple[int, int]) -> bool:
    return len(w) == 2 and w[0] <= w[1]

Prevention

When it happens

Trigger: Passing event_window=(5, -5) or any tuple where the first element is larger than the second, e.g. mixing up the order of pre-event and post-event bounds.

Common situations: Refactoring that swaps tuple elements, computing bounds from user input without ordering them, off-by-one confusion between inclusive/exclusive conventions.

Related errors


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