"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(quantlib): reject non-finite yield curve inputs
Lanre Shittu7c5b129574fe
diff --git a/agent/src/quantlib/fixedincome.py b/agent/src/quantlib/fixedincome.pyindex 94e2a730f..08c79835a 100644--- a/agent/src/quantlib/fixedincome.py+++ b/agent/src/quantlib/fixedincome.py@@ -722,6 +722,8 @@ def fit_yield_curve(obs = np.asarray(yields, dtype=float)if tau.shape != obs.shape or tau.ndim != 1:raise ValueError("maturities and yields must be 1-D and the same length")+ if not np.isfinite(tau).all() or not np.isfinite(obs).all():+ raise ValueError("maturities and yields must contain only finite values")if np.any(tau <= 0):raise ValueError("maturities must be strictly positive")@@ -733,6 +735,8 @@ def fit_yield_curve()low, high = decay_bounds+ if not np.isfinite(low) or not np.isfinite(high):+ raise ValueError("decay_bounds must contain only finite values")if not 0 < low < high:raise ValueError(f"decay_bounds must satisfy 0 < low < high, got {decay_bounds}")grid = np.geomspace(low, high, grid_points)diff --git a/agent/tests/quantlib/test_fixedincome.py b/agent/tests/quantlib/test_fixedincome.pyindex 79254a45f..063c8f9db 100644--- a/agent/tests/quantlib/test_fixedincome.py+++ b/agent/tests/quantlib/test_fixedincome.py@@ -546,3 +546,18 @@ def test_key_rate_duration_input_validation():key_rate_duration(100.0, 0.05, 0.05, 10, key_rates=[])with pytest.raises(ValueError, match="strictly increasing"):key_rate_duration(100.0, 0.05, 0.05, 10, key_rates=[5.0, 2.0, 10.0])++[email protected]("bad", [np.nan, np.inf, -np.inf])+def test_fit_yield_curve_rejects_nonfinite_observations(bad):+ maturities = TENORS.copy()+ yields = nelson_siegel(TENORS, 0.04, -0.01, 0.01, 2.0)+ maturities[3] = bad+ with pytest.raises(ValueError, match="finite"):+ fit_yield_curve(maturities, yields, model="nelson_siegel")++ maturities = TENORS.copy()+ yields = yields.copy()+ yields[3] = bad+ with pytest.raises(ValueError, match="finite"):+ fit_yield_curve(maturities, yields, model="nelson_siegel")