{"record":{"id":"302d0971ac6e6a92","repo":"HKUDS/Vibe-Trading","slug":"spot-strike-and-barrier-must-be-strictly-positiv","errorCode":null,"errorMessage":"Spot, strike, and barrier must be strictly positive, got S={S}, K={K}, H={H}","messagePattern":"Spot, strike, and barrier must be strictly positive, got S=(.+?), K=(.+?), H=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/options.py","lineNumber":548,"sourceCode":"        S: Current spot price, strictly positive.\n        K: Strike price, strictly positive.\n        H: Barrier price level, strictly positive.\n        T: Time to expiration in years.\n        r: Continuously compounded risk-free rate.\n        sigma: Annualised volatility.\n        barrier_type: One of :data:`BARRIER_TYPES` (or aliases e.g. ``'down-and-out'``, ``'ui'``).\n        option_type: ``'call'`` or ``'put'``.\n        q: Continuously compounded dividend yield.\n        rebate: Fixed cash rebate paid at expiration if knocked out (or never knocked in).\n\n    Returns:\n        Option price as a non-negative float.\n\n    Raises:\n        ValueError: If S, K, or H <= 0, or barrier_type is unknown.\n    \"\"\"\n    if S <= 0.0 or K <= 0.0 or H <= 0.0:\n        raise ValueError(f\"Spot, strike, and barrier must be strictly positive, got S={S}, K={K}, H={H}\")\n\n    b_type = normalise_barrier_type(barrier_type)\n    opt_type = normalise_option_type(option_type)\n\n    # Degenerate expiry or zero/negative volatility\n    if T <= 0.0 or sigma <= 0.0:\n        vanilla = bs_price(S, K, T, r, sigma, opt_type, q)\n        rebate_pv = rebate * float(np.exp(-r * T))\n        is_down = \"down\" in b_type\n        if T > 0.0 and sigma <= 0.0:\n            F = S * float(np.exp((r - q) * T))\n            breached = (min(S, F) <= H) if is_down else (max(S, F) >= H)\n        else:\n            breached = (S <= H) if is_down else (S >= H)\n        if \"out\" in b_type:\n            return rebate_pv if breached else vanilla\n        else:  # \"in\"\n            return vanilla if breached else rebate_pv","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/options.py#L530-L566","documentation":"barrier_option_price requires spot S, strike K, and barrier H all strictly positive because the closed-form Reiner-Rubinstein-style solution relies on log-normal dynamics in all three levels. A non-positive value would make the log ratios (log(S/H), log(K/H)) undefined, so validation happens before any pricing branch.","triggerScenarios":"Calling barrier_option_price(S=0, ...) or with K=-100 or H=0; a barrier level of 0 from an unset config field defaulting to 0.0.","commonSituations":"Config omission where barrier: H is forgotten and YAML gives 0; delisted/crashed underlying feeding a 0 spot; test fixtures built without setting all three levels.","solutions":["Set an explicit positive barrier H consistent with the barrier type (below spot for down-*, above spot for up-*).","Validate the config schema with required positive fields before pricing.","Quarantine market data rows with non-positive spot."],"exampleFix":"# before\nprice = barrier_option_price(S=100, K=90, H=0, T=1, r=0.05, sigma=0.2, barrier_type='down-and-out')\n\n# after\nprice = barrier_option_price(100, 90, H=85, T=1, r=0.05, sigma=0.2, barrier_type='down-and-out')","handlingStrategy":"validation","validationCode":"assert S > 0 and K > 0 and H > 0, f'need positive S={S}, K={K}, H={H}'","typeGuard":"def valid_barrier_levels(S: float, K: float, H: float) -> bool:\n    return all(isinstance(v, (int, float)) and v > 0 for v in (S, K, H))","tryCatchPattern":"try:\n    px = barrier_option_price(S, K, T, r, sigma, H, barrier_type, option_type)\nexcept ValueError as e:\n    if 'strictly positive' in str(e):\n        raise ConfigError('barrier config missing H or bad levels') from e\n    raise","preventionTips":["Make H a required field in trade/config schemas (no 0.0 default).","Check barrier placement vs spot (down-* needs H < S, up-* needs H > S) as a second validation.","Test fixtures must set all three levels explicitly."],"tags":["options","barrier-option","input-validation","positive-values"],"backgroundTag":"non-positive-argument","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}