Implementation:Avhz RustQuant Surface
| Knowledge Sources | |
|---|---|
| Domains | Volatility_Surface, Quantitative_Finance |
| Last Updated | 2026-02-07 19:00 GMT |
Overview
Concrete tool for representing two-dimensional financial data surfaces provided by the RustQuant library.
Description
The Surface struct models a two-dimensional data surface composed of multiple TermStructure objects indexed by time. Internally, it uses a BTreeMap<u64, TermStructure> where each key represents a time point and each value is a term structure (a one-dimensional curve of date-rate pairs). This is suitable for representing data such as volatility surfaces, where one axis is expiry time and the other is strike/tenor. The struct provides new() for construction, add_node() to insert a term structure at a given time point, and get_term_structure() to retrieve the term structure for a specific time. The BTreeMap ensures term structures are stored in sorted order by their time key. Note: the source also contains a generic Surface<S, C> type parameterized by CurveIndex types, though the concrete implementation uses u64 keys and TermStructure values.
Usage
Use this struct when you need to represent multi-dimensional market data such as volatility surfaces (strike vs. expiry), forward rate surfaces, or any financial data that varies across two dimensions.
Code Reference
Source Location
- Repository: RustQuant
- File: crates/RustQuant_data/src/surfaces.rs
- Lines: 1-93
Signature
pub struct Surface {
pub nodes: BTreeMap<u64, TermStructure>,
}
impl Surface {
pub fn new() -> Self;
pub fn add_node(&mut self, time: u64, term_structure: TermStructure);
pub fn get_term_structure(&self, time: u64) -> Option<&TermStructure>;
}
Import
use RustQuant::data::Surface;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| time | u64 | Yes (for add_node/get) | Time index key for the term structure node |
| term_structure | TermStructure | Yes (for add_node()) | A term structure (date-rate curve) to store at the time point |
Outputs
| Name | Type | Description |
|---|---|---|
| Surface | struct | A collection of term structures indexed by time |
| Option<&TermStructure> | get_term_structure() | Reference to the term structure at the given time, or None |
Usage Examples
use RustQuant::data::{Surface, TermStructure};
use time::{Date, Month};
// Create dates for a term structure
let dates = vec![
Date::from_calendar_date(2023, Month::January, 1).unwrap(),
Date::from_calendar_date(2023, Month::February, 1).unwrap(),
Date::from_calendar_date(2023, Month::March, 1).unwrap(),
];
let rates = [0.05, 0.06, 0.07];
// Build a term structure
let term_structure = TermStructure::new(&dates, &rates);
// Create a surface and add the term structure
let mut surface = Surface::new();
surface.add_node(1, term_structure);
// Retrieve the term structure
assert!(surface.get_term_structure(1).is_some());
assert!(surface.get_term_structure(2).is_none());