# US Treasury Yield Curve to JSON (`subwaycheese/treasury-yield-curve`) Actor

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.

- **URL**: https://apify.com/subwaycheese/treasury-yield-curve.md
- **Developed by:** [Trevor Charles](https://apify.com/subwaycheese) (community)
- **Categories:** Agents, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 day returneds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## 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

```js
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>`:

```json
[{ "date": "2026-09-17", "rates": { "1M": 4.2, "2Y": 3.9, "10Y": 4.1, "30Y": 4.6 } }]
```

- `date` comes from `d:NEW_DATE` (time part dropped).
- `rates` holds every `d:BC_*` tag present, keyed `1M 2M 3M 4M 6M 1Y 2Y 3Y 5Y 7Y 10Y 20Y 30Y`, as numbers.
- Empty tags and tags marked `m:null="true"` are omitted (never `NaN`).

`curveSignals(rows)` looks at the last row and returns:

```json
{ "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 (`null` if either is missing).
- `inverted` = `spread2s10s < 0` (`false` when `null`).
- `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_DATE` are 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.round` on 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

# Actor input Schema

## `year` (type: `integer`):

Calendar year of curve data (defaults to the current year)

## `maxDays` (type: `integer`):

Most recent N trading days to return

## `contactEmail` (type: `string`):

Sent in the User-Agent header

## Actor input object example

```json
{
  "maxDays": 30
}
```

# Actor output Schema

## `results` (type: `string`):

Structured rows (open in the Overview table view)

## `summary` (type: `string`):

Aggregate summary and disclaimer

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("subwaycheese/treasury-yield-curve").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("subwaycheese/treasury-yield-curve").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call subwaycheese/treasury-yield-curve --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,subwaycheese/treasury-yield-curve"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Td5535ofE7fsnafMn/builds/Yf4XrQvRhOqTzYX0m/openapi.json
