US Treasury Yield Curve to JSON
Pricing
$2.00 / 1,000 day returneds
US Treasury Yield Curve to JSON
Daily US Treasury par yield curve rates as clean JSON with 2s10s spread, inversion flag and day-over-day changes. Public U.S. Treasury data for AI agents and macro research.
Pricing
$2.00 / 1,000 day returneds
Rating
0.0
(0)
Developer
Trevor Charles
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
17 hours ago
Last modified
Share
treasury-yield-curve
Parse the US Treasury daily par yield curve XML feed into plain JavaScript objects, and compute a few curve-shape signals. Zero dependencies, Node built-ins only.
Usage
const { parseYieldCurveXml, curveSignals } = require('./src/core');const { fetchYieldCurveXml } = require('./src/fetch');const xml = await fetchYieldCurveXml(2026);const rows = parseYieldCurveXml(xml);console.log(curveSignals(rows));
Input / output
parseYieldCurveXml(xmlString) takes the Treasury OData/Atom XML and returns an array sorted by date ascending, one item per <entry>:
[{ "date": "2026-09-17", "rates": { "1M": 4.2, "2Y": 3.9, "10Y": 4.1, "30Y": 4.6 } }]
datecomes fromd:NEW_DATE(time part dropped).ratesholds everyd:BC_*tag present, keyed1M 2M 3M 4M 6M 1Y 2Y 3Y 5Y 7Y 10Y 20Y 30Y, as numbers.- Empty tags and tags marked
m:null="true"are omitted (neverNaN).
curveSignals(rows) looks at the last row and returns:
{ "latestDate": "2026-09-18", "spread2s10s": -0.25, "inverted": true,"changeVsPrevious": { "1M": -0.02, "2Y": 0.4, "10Y": -0.05 } }
spread2s10s= 10Y minus 2Y, rounded to 2 decimals (nullif either is missing).inverted=spread2s10s < 0(falsewhennull).changeVsPrevious= last minus previous row for tenors present in both, rounded to 2 decimals ({}with a single row).
fetchYieldCurveXml(year, opts) (in src/fetch.js) downloads one calendar year of XML from home.treasury.gov only, with a descriptive User-Agent (override with opts.userAgent; opts.timeoutMs sets the timeout). It needs Node 18+ for global fetch and is not covered by the offline tests.
Limitations
- The XML is read with regular expressions, not a full XML parser. It is written for the Treasury feed's layout and is not a general XML parser.
- Entries without a valid
d:NEW_DATEare skipped. - Only the par yield curve tenors listed above are read; other tags (e.g.
BC_30YEARDISPLAY) are ignored. - The previous row is the previous entry in the data, which may be several calendar days earlier (weekends, holidays).
- Rounding uses
Math.roundon floating-point values; do not rely on exact half-way behaviour. - Signals cover only the 2s10s spread and day-over-day changes. Nothing is forecast.
Tests
npm test
Disclaimer
This tool reports public U.S. Treasury data as-is. It is not investment advice, makes no prediction, and may contain errors or omissions. Use at your own risk; verify against home.treasury.gov.
License
MIT