Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(quantlib): support numpy array key_rates without ambiguous truth value error

santhrealb38f50522043
diff --git a/agent/src/quantlib/fixedincome.py b/agent/src/quantlib/fixedincome.py
index 3bf3fac1f..ef89284dc 100644
--- a/agent/src/quantlib/fixedincome.py
+++ b/agent/src/quantlib/fixedincome.py
@@ -448,9 +448,9 @@ def key_rate_duration(
Raises:
ValueError: If key_rates is empty or not strictly increasing, or schedule/compounding invalid.
"""
- if not key_rates:
- raise ValueError("key_rates must contain at least one tenor")
kr = np.asarray(key_rates, dtype=float)
+ if kr.size == 0:
+ raise ValueError("key_rates must contain at least one tenor")
if (np.diff(kr) <= 0.0).any():
raise ValueError(f"key_rates must be strictly increasing, got {key_rates}")