"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: Reject non-finite Heston inputs and invalid integration bounds before an invalid integral can become a zero option price.
Rudy Celekli9111a981451b
diff --git a/README.md b/README.mdindex b359b3ac8..829d84604 100644--- a/README.md+++ b/README.md@@ -856,7 +856,7 @@ that is a bug, not a pattern.| `factormodel` · `eventstudy` | Factor regressions, event studies || `multipletesting` · `crossvalidation` | Deflated significance, purged CV || `impact` | Market-impact models |-| `volatility` | Heston (1993) stochastic-volatility pricing |+| `volatility` | Heston (1993) stochastic-volatility pricing; Heston pricing requires finite inputs and a positive integration limit; invalid inputs return a domain error. || `portfolio` | Hierarchical Risk Parity allocation || `copula` | Gaussian and Archimedean copulas || `microstructure` | VPIN, Roll spread, Amihud illiquidity, Kyle's lambda |diff --git a/agent/src/quantlib/volatility.py b/agent/src/quantlib/volatility.pyindex 030959fe8..0c1e3cfba 100644--- a/agent/src/quantlib/volatility.py+++ b/agent/src/quantlib/volatility.py@@ -51,6 +51,9 @@ def heston_feller_condition(kappa: float, theta: float, sigma_v: float) -> dict[* ``feller_ratio`` (float): 2 * kappa * theta / (sigma_v**2)* ``is_satisfied`` (bool): True if feller_ratio > 1.0."""+ for name, value in (("kappa", kappa), ("theta", theta), ("sigma_v", sigma_v)):+ if not math.isfinite(value):+ raise ValueError(f"{name} must be finite, got {value}")if sigma_v <= 0.0:raise ValueError(f"sigma_v must be strictly positive, got {sigma_v}")if kappa <= 0.0 or theta <= 0.0:@@ -135,6 +138,23 @@ def heston_price(Returns:Option price as a non-negative float."""+ for name, value in (+ ("S0", S0),+ ("K", K),+ ("T", T),+ ("r", r),+ ("q", q),+ ("v0", v0),+ ("kappa", kappa),+ ("theta", theta),+ ("sigma_v", sigma_v),+ ("rho", rho),+ ("integration_limit", integration_limit),+ ):+ if not math.isfinite(value):+ raise ValueError(f"{name} must be finite, got {value}")+ if integration_limit <= 0.0:+ raise ValueError("integration_limit must be strictly positive")if S0 <= 0.0 or K <= 0.0:raise ValueError(f"Spot S0 and strike K must be positive, got S0={S0}, K={K}")if T <= 0.0:diff --git a/agent/tests/test_heston_finite_inputs_regressions.py b/agent/tests/test_heston_finite_inputs_regressions.pynew file mode 100644index 000000000..4ecdb35c1--- /dev/null+++ b/agent/tests/test_heston_finite_inputs_regressions.py@@ -0,0 +1,81 @@+import pytest+from src.quantlib.volatility import heston_price, heston_feller_condition+++ "field",+ [+ "S0",+ "K",+ "T",+ "r",+ "q",+ "v0",+ "kappa",+ "theta",+ "sigma_v",+ "rho",+ "integration_limit",+ ],+)[email protected]("value", [float("nan"), float("inf"), -float("inf")])+def test_heston_rejects_nonfinite_inputs_before_pricing(field, value):+ args = dict(+ S0=100.0,+ K=100.0,+ T=1.0,+ r=0.03,+ q=0.0,+ v0=0.04,+ kappa=2.0,+ theta=0.04,+ sigma_v=0.3,+ rho=-0.7,+ integration_limit=200.0,+ )+ args[field] = value+ with pytest.raises(ValueError, match="finite"):+ heston_price(**args)++[email protected]("limit", [0.0, -1.0])+def test_heston_rejects_empty_or_reversed_integration_domain(limit):+ with pytest.raises(ValueError, match="integration_limit"):+ heston_price(+ 100.0, 100.0, 1.0, 0.03, 0.04, 2.0, 0.04, 0.3, -0.7, integration_limit=limit+ )++[email protected]("field", ["kappa", "theta", "sigma_v"])+def test_feller_rejects_nonfinite_inputs(field):+ args = dict(kappa=2.0, theta=0.04, sigma_v=0.3)+ args[field] = float("nan")+ with pytest.raises(ValueError, match="finite"):+ heston_feller_condition(**args)+++def test_quantlib_tool_rejects_zero_integration_domain():+ import json+ from src.tools.quantlib_tool import QuantlibCallTool++ result = json.loads(+ QuantlibCallTool().execute(+ action="call",+ module="volatility",+ function="heston_price",+ kwargs={+ "S0": 100.0,+ "K": 100.0,+ "T": 1.0,+ "r": 0.03,+ "v0": 0.04,+ "kappa": 2.0,+ "theta": 0.04,+ "sigma_v": 0.3,+ "rho": -0.7,+ "integration_limit": 0.0,+ },+ )+ )+ assert result["ok"] is False+ assert "integration_limit" in result["error"]