Expand description
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—Curvekitasync client with blocking wrappers.date—Datenewtype for ergonomic date input.tenor—Tenorsemantic type for maturities.curve—YieldCurve,SofrDay,SofrRate,TermStructure.sources::bundled— synchronous reader from local parquet (CLIget).sources::parquet_io— parquet writer (CLIbackfill/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— unifiedErrorenum andResultalias.
Re-exports§
pub use client::Curvekit;pub use curve::SofrDay;pub use curve::SofrRate;pub use curve::TermStructure;pub use curve::YieldCurve;pub use curve::YieldCurveDay;pub use curve::YieldType;pub use date::Date;pub use date::DateError;pub use date::IntoDate;pub use daycount::DayCount;pub use error::CurvekitError;pub use error::Error;pub use error::Result;pub use sources::effr::EffrDay;pub use sources::effr::EffrFetcher;pub use sources::effr::HttpEffrFetcher;pub use sources::obfr::HttpObfrFetcher;pub use sources::obfr::ObfrDay;pub use sources::obfr::ObfrFetcher;pub use sources::sofr::parse_sofr_csv;pub use sources::sofr::HttpSofrFetcher;pub use sources::sofr::SofrFetcher;pub use sources::treasury::parse_treasury_csv;pub use sources::treasury::HttpTreasuryFetcher;pub use sources::treasury::TreasuryFetcher;pub use tenor::Tenor;pub use sources::bundled::rate_for;pub use sources::bundled::rate_for_days;Deprecated pub use sources::bundled::sofr;pub use sources::bundled::sofr_latest_date;pub use sources::bundled::treasury_curve;pub use sources::bundled::treasury_latest_date;
Modules§
- client
- Stateful
Curvekitclient — flat async endpoint methods. - curve
- date
Date— ergonomic date input for curvekit’s public API.- daycount
- Day-count conventions for yield calculations.
- error
- Unified error type for curvekit.
- interpolation
- Yield curve interpolation methods.
- sources
- tenor
Tenor— semantic type for yield-curve maturities.
Functions§
- sofr_
today - Latest available SOFR overnight observation (uses shared global client).
- treasury_
curve_ for - Full Treasury yield curve for a specific date (uses shared global client).
- treasury_
rate_ at - Interpolated Treasury rate at a specific tenor for a date (uses shared global client).
- treasury_
today - Latest available Treasury yield curve (uses shared global client).