HKUDS/Vibe-Trading · error · ValueError
Unhandled barrier type {b_type}
Error message
Unhandled barrier type {b_type} What it means
barrier_option_price dispatches the CALL pricing branch over the four canonical barrier types (down-and-out, down-and-in, up-and-out, up-and-in). Reaching the else clause means b_type is not one of them — in practice only possible if normalise_barrier_type's alias table is extended or bypassed, since the type was normalised earlier. It is a defensive internal invariant check for the call leg.
Source
Thrown at agent/src/quantlib/options.py:622
) * norm.cdf(eta * (y2 - sigma_sqrt_T))
# Cash rebate component
if rebate > 0.0:
E = rebate * df_r * (norm.cdf(eta * (x2 - sigma_sqrt_T)) - (hs_ratio ** (2.0 * mu)) * norm.cdf(eta * (y2 - sigma_sqrt_T)))
else:
E = 0.0
if opt_type == _CALL:
if b_type == "down-and-out":
price = (A - C + (rebate * df_r - E)) if K >= H else (B - D + (rebate * df_r - E))
elif b_type == "down-and-in":
price = (C + E) if K >= H else (A - B + D + E)
elif b_type == "up-and-out":
price = (rebate * df_r - E) if K >= H else (A - B + C - D + (rebate * df_r - E))
elif b_type == "up-and-in":
price = (A + E) if K >= H else (B - C + D + E)
else:
raise ValueError(f"Unhandled barrier type {b_type}")
else: # PUT
if b_type == "down-and-out":
price = (A - B + C - D + (rebate * df_r - E)) if K >= H else (rebate * df_r - E)
elif b_type == "down-and-in":
price = (B - C + D + E) if K >= H else (A + E)
elif b_type == "up-and-out":
price = (B - D + (rebate * df_r - E)) if K >= H else (A - C + (rebate * df_r - E))
elif b_type == "up-and-in":
price = (A - B + D + E) if K >= H else (C + E)
else:
raise ValueError(f"Unhandled barrier type {b_type}")
return float(max(0.0, price))
View on GitHub (pinned to 80ffdda44c)
Solutions
- If extending barrier types, add matching elif branches in both the CALL and PUT legs plus tests.
- Do not monkey-patch the alias tables; request the type upstream instead.
- As an end user hitting this, report it — your installed copy is patched or inconsistent; reinstall the package.
Defensive patterns
Strategy: try-catch
Try / catch
try:
px = barrier_option_price(...)
except ValueError as e:
if 'Unhandled barrier type' in str(e):
raise RuntimeError('inconsistent quantlib install: report upstream') from e
raise Prevention
- Do not monkey-patch alias tables; contribute new barrier types upstream with both call and put branches.
- Pin the package version in production.
- If forking, add dispatch-coverage tests for every alias.
When it happens
Trigger: Not reachable through the public API with stock aliases; triggered if the module's BARRIER_TYPES is monkey-patched, an unmapped alias slips through a patched _BARRIER_ALIASES, or internal code calls the branch with a raw string.
Common situations: Library maintainers adding a new barrier type (e.g. double-no-touch) and forgetting the call-leg dispatch; tests that patch the alias table; downstream forks that extend the enum.
Related errors
- unknown barrier type {barrier_type!r}; valid types: {BARRIER
- Spot, strike, and barrier must be strictly positive, got S={
- unrecognised option_type {option_type!r}. Accepted (any case
- T must be > 0 to imply a volatility, got {T}
- S and K must be > 0, got S={S}, K={K}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/de3502b440d1277d.
Report an issue: GitHub.