{"record":{"id":"e7f2e4558a25b1bf","repo":"HKUDS/Vibe-Trading","slug":"s-and-k-must-be-0-got-s-s-k-k","errorCode":null,"errorMessage":"S and K must be > 0, got S={S}, K={K}","messagePattern":"S and K must be > 0, got S=(.+?), K=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/options.py","lineNumber":445,"sourceCode":"        from 0.05 to 0.60, so a solver that answers there is reporting the\n        arbitrary endpoint of its own search, not a market volatility. This\n        function refuses that: it checks vega at the candidate solution and\n        returns ``nan`` when the price carries no volatility information. That\n        is a property of the quote rather than a solver failure, and no\n        price-tolerance method can do better -- but a confident wrong number is\n        worse than an admitted absence.\n\n    Raises:\n        ValueError: If ``option_type`` is invalid, if ``T``, ``S`` or ``K`` is\n            non-positive, or if ``market_price`` lies outside the no-arbitrage\n            interval, which includes the intrinsic-value violation\n            ``market_price < discounted intrinsic``.\n    \"\"\"\n    option_type = normalise_option_type(option_type)\n    if T <= 0:\n        raise ValueError(f\"T must be > 0 to imply a volatility, got {T}\")\n    if S <= 0 or K <= 0:\n        raise ValueError(f\"S and K must be > 0, got S={S}, K={K}\")\n\n    lower, upper = _no_arbitrage_bounds(S, K, T, r, option_type, q)\n    if market_price < lower - tol:\n        raise ValueError(\n            f\"market price {market_price} is below intrinsic value {lower}\"\n        )\n    if market_price >= upper:\n        raise ValueError(\n            f\"market price {market_price} is at or above the no-arbitrage \"\n            f\"ceiling {upper}; no implied volatility exists\"\n        )\n\n    def identified(candidate: float) -> float:\n        \"\"\"Return the candidate only if the quote actually pins it down.\n\n        The test is whether one volatility point of movement shifts the price by\n        more than the tolerance the solve was run to. If it does not, then a\n        whole band of volatilities reprices within ``tol`` and whichever one the","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/options.py#L427-L463","documentation":"The Black-Scholes formula requires a strictly positive spot S and strike K (log-normal dynamics need log(S/K)). implied_volatility enforces this before building no-arbitrage bounds, because a non-positive S or K makes both the pricing formula and the intrinsic-value interval mathematically meaningless.","triggerScenarios":"Calling implied_volatility with S=0 or K=0 (or negatives); passing a null/NaN spot from a failed market-data lookup that was coerced to 0.0.","commonSituations":"Missing prices defaulting to 0 in a feed join; strike loaded as 0 for a forward or a contract row that is not a vanilla option; DataFrame columns misordered so a volume or bid column lands in K.","solutions":["Audit the argument order and the source columns feeding S and K.","Drop or quarantine rows with S <= 0 or K <= 0 before the vol solve.","Assert positivity at data ingestion with a clear error message including the contract ID."],"exampleFix":"# before\niv = implied_volatility(px, row['close'], row['volume'], T, r, 'put')  # volume in K!\n\n# after\nassert row['close'] > 0 and row['strike'] > 0\niv = implied_volatility(px, row['close'], row['strike'], T, r, 'put')","handlingStrategy":"validation","validationCode":"assert S > 0 and K > 0, f'need positive S={S}, K={K}'","typeGuard":"def are_positive_levels(*vals) -> bool:\n    return all(isinstance(v, (int, float)) and v > 0 for v in vals)","tryCatchPattern":"try:\n    iv = implied_volatility(px, S, K, T, r, option_type)\nexcept ValueError as e:\n    if 'S and K must be > 0' in str(e):\n        quarantine(contract_id, reason='bad levels')\n    else:\n        raise","preventionTips":["Name keyword args explicitly: implied_volatility(price=..., S=..., K=...).","Drop rows with non-positive spot/strike in ingestion.","Beware DataFrame column order when unpacking."],"tags":["options","implied-volatility","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"}