Implementation:Avhz RustQuant Curve new
| Knowledge Sources | |
|---|---|
| Domains | Fixed_Income, Yield_Curves, Market_Data |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Concrete tool for constructing yield curves from market data provided by the RustQuant data crate.
Description
The Curve struct stores rate data as a BTreeMap<Date, f64> and supports multiple interpolation backends (Linear, Exponential). It optionally fits a Nelson-Siegel-Svensson parametric model via particle swarm optimization. The struct is PyO3-annotated for Python interop.
Construction is available via new() (from separate date and rate vectors) or from_nodes() (from a BTreeMap). The curve lazily fits the NSS model on first interpolation request for out-of-sample dates.
Usage
Import Curve when you need to build a yield curve from market data. Specify the curve type (Flat, Spot, Forward, Discount) and interpolation method (Linear, Exponential).
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_data/src/curves.rs
- Lines: L46-167 (Curve struct, CurveType, InterpolationMethod, new, from_nodes)
Signature
pub enum CurveType { Flat, Spot, Forward, Discount }
pub enum InterpolationMethod { Linear, Exponential, CubicSpline, Lagrange }
#[pyclass]
pub struct Curve {
nodes: BTreeMap<Date, f64>,
curve_type: CurveType,
interpolation_method: InterpolationMethod,
interpolator: Arc<dyn Interpolator<Date, f64>>,
nss: Option<NelsonSiegelSvensson>,
}
impl Curve {
pub fn new(
dates: Vec<Date>,
rates: Vec<f64>,
curve_type: CurveType,
interpolation_method: InterpolationMethod,
) -> PyResult<Self>
pub fn from_nodes(
nodes: BTreeMap<Date, f64>,
curve_type: CurveType,
interpolation_method: InterpolationMethod,
) -> PyResult<Self>
}
Import
use RustQuant::data::{Curve, CurveType, InterpolationMethod};
use time::Date;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| dates | Vec<Date> | Yes (for new()) | Vector of observation dates |
| rates | Vec<f64> | Yes (for new()) | Vector of observed rates corresponding to dates |
| nodes | BTreeMap<Date, f64> | Yes (for from_nodes()) | Pre-built date-rate mapping |
| curve_type | CurveType | Yes | Flat, Spot, Forward, or Discount |
| interpolation_method | InterpolationMethod | Yes | Linear or Exponential (CubicSpline/Lagrange are TODO) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | PyResult<Curve> | Constructed curve ready for rate queries and interpolation |
Usage Examples
Basic Spot Curve
use RustQuant::data::{Curve, CurveType, InterpolationMethod};
use time::macros::date;
let dates = vec![
date!(2024 - 01 - 01),
date!(2024 - 07 - 01),
date!(2025 - 01 - 01),
date!(2026 - 01 - 01),
date!(2029 - 01 - 01),
];
let rates = vec![0.04, 0.042, 0.045, 0.048, 0.05];
let curve = Curve::new(
dates,
rates,
CurveType::Spot,
InterpolationMethod::Linear,
).unwrap();
Query Rates
// Get an exact rate
let rate = curve.get_rate(date!(2025 - 01 - 01)); // Some(0.045)
// Get an interpolated rate
let rate = curve.get_rate(date!(2024 - 10 - 01)); // Interpolated
// Get rate and add to curve nodes
let mut curve = curve;
let rate = curve.get_rate_and_insert(date!(2024 - 10 - 01));