Skip to content

160-tool MCP server for real-time global intelligence from free public APIs: markets, liquidity, prediction markets, SEC filings, conflict, military, aircraft-cohort early warning, migration and border flows, cyber, climate, news and more. Dated observation history, 29 research prompts, cited briefs, geofences, SSE dashboard. MIT, no paid API keys.

Yield curve: no inversion reading when no spread could be computed

Phoenix Agent (mac-studio)1eb0978e2dd7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f817103..da88c66 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -267,6 +267,13 @@ source here, and no proxy is substituted for any of these measures.
`ACLED_ACCESS_TOKEN`, which no code reads; added `UCDP_ACCESS_TOKEN`,
`TOMTOM_API_KEY`, `WINDY_API_KEY`, `OPENSKY_USERNAME` and
`OPENSKY_PASSWORD`.
+- `intel_yield_curve`: `inverted` is null, not `false`, when neither
+ spread could be computed, so an outage or one lost maturity no longer
+ reads as "not inverted". New `inversion_basis` names the spreads the
+ flag rests on (without `FRED_API_KEY` that is `spread_3m10y` alone) and
+ `yields_source` says whether the maturities came from FRED or Yahoo. A
+ maturity with no rate is listed in `data_gaps` with `degraded: true`, and
+ no rate at all is an `error`.
### Added: tropical cyclone forecast tracks
- `intel_cyclones` and `intel_jtwc_cyclones` take `include_forecast`
diff --git a/src/world_intel_mcp/sources/bonds.py b/src/world_intel_mcp/sources/bonds.py
index 306a975..298c516 100644
--- a/src/world_intel_mcp/sources/bonds.py
+++ b/src/world_intel_mcp/sources/bonds.py
@@ -121,7 +121,11 @@ async def fetch_yield_curve(fetcher: Fetcher) -> dict:
10Y, 30Y).
Returns a dict with ``yields`` list, ``spread_2s10s``, ``spread_3m10y``,
- ``inverted`` flag, and metadata.
+ ``inverted`` flag, and metadata. ``inverted`` is None when neither
+ spread could be computed (a maturity it needs was not read), so an
+ outage never reads as "not inverted"; ``inversion_basis`` names the
+ spreads the flag rests on. A maturity with no rate is listed in
+ ``data_gaps`` (with ``degraded``), and no rate at all is an ``error``.
"""
# --- Treasury Fiscal Data API (always attempted) -------------------------
treasury_data = await fetcher.get_json(
@@ -155,17 +159,19 @@ async def fetch_yield_curve(fetcher: Fetcher) -> dict:
spread_2s10s: float | None = None
spread_3m10y: float | None = None
- inverted = False
if rate_2y is not None and rate_10y is not None:
spread_2s10s = round(rate_10y - rate_2y, 4)
if rate_3m is not None and rate_10y is not None:
spread_3m10y = round(rate_10y - rate_3m, 4)
- if spread_2s10s is not None and spread_2s10s < 0:
- inverted = True
- elif spread_3m10y is not None and spread_3m10y < 0:
- inverted = True
+ spreads = {"spread_2s10s": spread_2s10s, "spread_3m10y": spread_3m10y}
+ inversion_basis = [name for name, value in spreads.items() if value is not None]
+ inverted: bool | None = (
+ any(spreads[name] < 0 for name in inversion_basis) if inversion_basis else None
+ )
+ provider = "fred" if fred_key else "yahoo-finance"
+ missing = [y["maturity"] for y in yields if y["rate"] is None]
# --- Parse Treasury Fiscal Data for supplementary info -------------------
treasury_records: list[dict] = []
@@ -175,15 +181,28 @@ async def fetch_yield_curve(fetcher: Fetcher) -> dict:
except (AttributeError, TypeError):
pass
- return {
+ result = {
"yields": yields,
"spread_2s10s": spread_2s10s,
"spread_3m10y": spread_3m10y,
"inverted": inverted,
+ "inversion_basis": inversion_basis,
+ "yields_source": provider,
"treasury_records": len(treasury_records),
"fetched_at": _utc_now_iso(),
"source": "treasury",
}
+ if missing:
+ result["degraded"] = True
+ result["data_gaps"] = [f"No {m} yield from {provider}" for m in missing]
+ if inverted is None:
+ result["data_gaps"].append(
+ "inverted is null: no spread could be computed, so the curve's "
+ "shape is unknown, not normal"
+ )
+ if yields and len(missing) == len(yields):
+ result["error"] = f"No Treasury yield could be read from {provider}"
+ return result
async def _fetch_yields_from_fred(
diff --git a/src/world_intel_mcp/tests/test_bonds.py b/src/world_intel_mcp/tests/test_bonds.py
index ba854b3..7c2979e 100644
--- a/src/world_intel_mcp/tests/test_bonds.py
+++ b/src/world_intel_mcp/tests/test_bonds.py
@@ -274,3 +274,98 @@ async def test_fetch_bond_indices_partial_failure(fetcher: Fetcher) -> None:
# Only AGG should survive
assert len(result["indices"]) >= 1
assert result["indices"][0]["symbol"] == "AGG"
+
+
+# ---------------------------------------------------------------------------
+# Yield Curve — outages never read as "not inverted"
+# ---------------------------------------------------------------------------
+
+
+def _quick_fetcher(cache: Cache, monkeypatch) -> Fetcher:
+ """No retries and no Yahoo spacing, so an outage test runs at once."""
+ from world_intel_mcp import fetcher as fetcher_module
+
+ monkeypatch.setattr(fetcher_module, "_YAHOO_MIN_INTERVAL", 0.0)
+ return Fetcher(cache=cache, breaker=CircuitBreaker(failure_threshold=1000), max_retries=0)
+
+
+def _chart(price: float) -> dict:
+ return {"chart": {"result": [{"meta": {"regularMarketPrice": price, "currency": "USD"}}]}}
+
+
+async def test_yield_curve_total_outage_has_no_inversion_reading(cache: Cache, monkeypatch) -> None:
+ from world_intel_mcp.sources.bonds import fetch_yield_curve
+
+ monkeypatch.delenv("FRED_API_KEY", raising=False)
+ respx.get(url__regex=r".*").mock(return_value=httpx.Response(503))
+ fetcher = _quick_fetcher(cache, monkeypatch)
+ try:
+ result = await fetch_yield_curve(fetcher)
+ finally:
+ await fetcher.close()
+
+ assert [y["rate"] for y in result["yields"]] == [None, None, None, None]
+ assert (result["spread_2s10s"], result["spread_3m10y"]) == (None, None)
+ assert result["inverted"] is None
+ assert result["inversion_basis"] == []
+ assert result["error"] == "No Treasury yield could be read from yahoo-finance"
+ assert result["degraded"] is True
+ assert result["data_gaps"][:4] == [f"No {m} yield from yahoo-finance" for m in ("3M", "5Y", "10Y", "30Y")]
+ assert result["data_gaps"][4].startswith("inverted is null")
+
+
+async def test_yield_curve_one_missing_maturity_is_named_not_read_as_normal(cache: Cache, monkeypatch) -> None:
+ """3M above 10Y is inverted; with the 3M quote lost, the flag must not
+ say otherwise, and no breaker opens to hint at it."""
+ from world_intel_mcp.sources.bonds import fetch_yield_curve
+
+ monkeypatch.delenv("FRED_API_KEY", raising=False)
+ respx.get(url__regex=r".*fiscaldata.*").mock(return_value=httpx.Response(200, json={"data": []}))
+ respx.get(url__regex=r".*chart/(\^|%5E)IRX.*").mock(return_value=httpx.Response(429))
+ prices = {"FVX": 4.0, "TNX": 4.2, "TYX": 4.5}
+ for symbol, price in prices.items():
+ respx.get(url__regex=rf".*chart/(\^|%5E){symbol}.*").mock(return_value=httpx.Response(200, json=_chart(price)))
+ fetcher = _quick_fetcher(cache, monkeypatch)
+ try:
+ result = await fetch_yield_curve(fetcher)
+ finally:
+ await fetcher.close()
+
+ assert {y["maturity"]: y["rate"] for y in result["yields"]} == {"3M": None, "5Y": 4.0, "10Y": 4.2, "30Y": 4.5}
+ assert result["inverted"] is None and result["inversion_basis"] == []
+ assert "error" not in result
+ assert result["data_gaps"][0] == "No 3M yield from yahoo-finance"
+
+
+async def test_yield_curve_flag_names_the_spread_it_rests_on(cache: Cache, monkeypatch) -> None:
+ """With FRED, a lost 2Y leaves the flag resting on 3m10y alone."""
+ from world_intel_mcp.sources.bonds import fetch_yield_curve
+
+ monkeypatch.setenv("FRED_API_KEY", "test-fred-key")
+ values = {"DGS3MO": "5.10", "DGS10": "4.20"}
+
+ def _fred(request: httpx.Request) -> httpx.Response:
+ series = dict(request.url.params).get("series_id", "")
+ if series == "DGS2":
+ return httpx.Response(503)
+ return httpx.Response(200, json={"observations": [{"date": "2026-10-16", "value": values.get(series, "4.0")}]})
+
+ respx.get(url__regex=r".*fiscaldata.*").mock(return_value=httpx.Response(200, json={"data": []}))
+ respx.get("https://api.stlouisfed.org/fred/series/observations").mock(side_effect=_fred)
+ fetcher = _quick_fetcher(cache, monkeypatch)
+ try:
+ result = await fetch_yield_curve(fetcher)
+ finally:
+ await fetcher.close()
+
+ assert result["spread_2s10s"] is None and result["spread_3m10y"] == -0.9
+ assert result["inverted"] is True
+ assert result["inversion_basis"] == ["spread_3m10y"]
+ assert result["yields_source"] == "fred"
+ assert result["data_gaps"] == ["No 2Y yield from fred"]