HKUDS/Vibe-Trading · error · ValueError

unknown day_count {day_count!r}; expected one of {DAY_COUNT_

Error message

unknown day_count {day_count!r}; expected one of {DAY_COUNT_CONVENTIONS}

What it means

year_fraction implements a fixed set of accrual day-count conventions (DAY_COUNT_CONVENTIONS) and rejects anything outside that whitelist, printing the accepted values in the message.

Source

Thrown at agent/src/quantlib/fixedincome.py:84

    day_count: str = DEFAULT_DAY_COUNT,
) -> float:
    """Accrual factor between two dates under a named day-count convention.

    Args:
        start: Period start (accrual runs from this date, inclusive).
        end: Period end (accrual runs to this date, exclusive).
        day_count: One of :data:`DAY_COUNT_CONVENTIONS`. ``ACT/ACT`` is the
            ISDA variant: each calendar year contributes
            ``days_in_that_year / (365 or 366)``.

    Returns:
        Year fraction as a float. Negative if ``end`` precedes ``start``.

    Raises:
        ValueError: If ``day_count`` is not a recognised convention.
    """
    if day_count not in DAY_COUNT_CONVENTIONS:
        raise ValueError(
            f"unknown day_count {day_count!r}; expected one of {DAY_COUNT_CONVENTIONS}"
        )

    if end < start:
        return -year_fraction(end, start, day_count)

    if day_count == "ACT/365F":
        return (end - start).days / 365.0
    if day_count == "ACT/360":
        return (end - start).days / 360.0
    if day_count in ("30/360", "30E/360"):
        d1, d2 = start.day, end.day
        if day_count == "30/360":
            # US bond basis: clip D1 to 30, then clip D2 when adjusted D1 is 30.
            if d1 == 31:
                d1 = 30
            if d2 == 31 and d1 == 30:
                d2 = 30

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Print DAY_COUNT_CONVENTIONS (imported from fixedincome) and match the string exactly
  2. Normalize incoming strings (lowercase, strip separators) via a mapping before calling
  3. If the convention is truly unsupported, implement/fallback outside the API

Example fix

# before
yf = year_fraction(d1, d2, 'ACT/360')
# after
yf = year_fraction(d1, d2, 'act360')  # exact whitelist spelling
Defensive patterns

Strategy: validation

Validate before calling

from agent.src.quantlib.fixedincome import DAY_COUNT_CONVENTIONS
assert day_count in DAY_COUNT_CONVENTIONS, DAY_COUNT_CONVENTIONS

Type guard

def is_known_day_count(dc: str, known) -> bool:
    return dc in known

Prevention

When it happens

Trigger: year_fraction(d1, d2, 'act/360') with a slash instead of 'act360', or a value like 'ACT365' with wrong case, or an unsupported convention like 'nl/365'.

Common situations: Convention strings parsed from term sheets or config with inconsistent formatting ('30E/360' vs '30e360'); case differences; a convention simply not implemented.

Related errors


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