curvekit 1.0.1

Offline-first bundled-parquet risk-free rate library — Treasury yield curves + SOFR
Documentation

curvekit — US Treasury yield curve and SOFR overnight rate for Rust.

Fetches parquet files on demand from GitHub raw, caches them locally with ETag revalidation, and falls back to stale cache on network errors. No API keys. Offline after the first successful fetch of each year file.

Quick start — one-off scripts

use curvekit::Tenor;

#[tokio::main]
async fn main() -> curvekit::Result<()> {
    // Free functions — no client setup needed
    let curve = curvekit::treasury_curve_for("2020-03-20").await?;
    let r     = curvekit::treasury_rate_at("2020-03-20", Tenor::Y10).await?;
    let today = curvekit::treasury_today().await?;
    let sofr  = curvekit::sofr_today().await?;

    println!("10Y on 2020-03-20: {r:.6}");
    println!("Latest Treasury:   {}", today.date);
    println!("Latest SOFR:       {:.4}%", sofr.rate * 100.0);
    Ok(())
}

Client pattern — connection pool + cache reuse

use curvekit::{Curvekit, Date, Tenor};

#[tokio::main]
async fn main() -> curvekit::Result<()> {
    let client = Curvekit::new();   // infallible, no ?

    // Any date form — ISO string, compact u32, tuple, NaiveDate
    let curve = client.treasury_curve("2020-03-20").await?;
    let curve = client.treasury_curve(20200320u32).await?;
    let curve = client.treasury_curve((2020i32, 3u32, 20u32)).await?;
    let curve = client.treasury_curve(Date::today_et()).await?;

    let r = client.treasury_rate("2020-03-20", Tenor::Y10).await?;

    // Blocking from sync code — no async runtime needed
    let curve = client.treasury_curve_blocking(20200320u32)?;

    Ok(())
}

Major types

  • [Curvekit] — stateful client; create once, call many times.
  • [Date] — ergonomic date wrapper; accepts strings, integers, tuples.
  • [YieldCurve] — Treasury yield curve for a single date. All rates are continuously compounded.
  • [SofrDay] — a single SOFR overnight observation.
  • [TermStructure] — combined Treasury + SOFR view for a date.
  • [Tenor] — typed constants for standard maturity labels (Tenor::Y10, etc.).
  • [Error] — unified error type; match on this, never on sub-types.

Environment overrides

Variable Effect
CURVEKIT_BASE_URL Replace the GitHub raw origin URL
CURVEKIT_CACHE_DIR Override ~/.cache/curvekit/

Modules

  • [client] — [Curvekit] async client with blocking wrappers.
  • [date] — [Date] newtype for ergonomic date input.
  • [tenor] — [Tenor] semantic type for maturities.
  • [curve] — [YieldCurve], [SofrDay], [SofrRate], [TermStructure].
  • [sources::bundled] — synchronous reader from local parquet (CLI get).
  • [sources::parquet_io] — parquet writer (CLI backfill / append-today).
  • [sources::treasury] — Treasury CSV fetcher (used by CLI).
  • [sources::sofr] — NY Fed SOFR CSV fetcher (used by CLI).
  • [interpolation] — linear interpolation between tenor knots.
  • [error] — unified [Error] enum and [Result] alias.