1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//! `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
//!
//! ```no_run
//! 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
//!
//! ```no_run
//! 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.
pub
// ── Top-level re-exports ──────────────────────────────────────────────────────
pub use Curvekit;
pub use ;
pub use ;
pub use DayCount;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Tenor;
// Legacy bundled API re-exports (kept for backward compat, deprecated at source).
pub use ;
// ── Free-function shortcuts ───────────────────────────────────────────────────
//
// Each function internally uses a process-wide `Curvekit` instance so that
// multiple calls share one HTTP client and cache.
use OnceLock;
/// Latest available Treasury yield curve (uses shared global client).
///
/// # Example
///
/// ```no_run
/// #[tokio::main]
/// async fn main() -> curvekit::Result<()> {
/// let curve = curvekit::treasury_today().await?;
/// println!("Latest Treasury: {}", curve.date);
/// Ok(())
/// }
/// ```
pub async
/// Full Treasury yield curve for a specific date (uses shared global client).
///
/// Accepts any date form: ISO string, compact u32, tuple, or `NaiveDate`.
///
/// # Example
///
/// ```no_run
/// #[tokio::main]
/// async fn main() -> curvekit::Result<()> {
/// let curve = curvekit::treasury_curve_for("2020-03-20").await?;
/// println!("3M: {:.4}%", curve.get(curvekit::Tenor::M3).unwrap_or(0.0) * 100.0);
/// Ok(())
/// }
/// ```
pub async
/// Interpolated Treasury rate at a specific tenor for a date (uses shared global client).
///
/// # Example
///
/// ```no_run
/// use curvekit::Tenor;
///
/// #[tokio::main]
/// async fn main() -> curvekit::Result<()> {
/// let r = curvekit::treasury_rate_at("2020-03-20", Tenor::Y10).await?;
/// println!("10Y on 2020-03-20: {r:.6}");
/// Ok(())
/// }
/// ```
pub async
/// Latest available SOFR overnight observation (uses shared global client).
///
/// # Example
///
/// ```no_run
/// #[tokio::main]
/// async fn main() -> curvekit::Result<()> {
/// let sofr = curvekit::sofr_today().await?;
/// println!("SOFR {}: {:.4}%", sofr.date, sofr.rate * 100.0);
/// Ok(())
/// }
/// ```
pub async