use super::Curve;
use crate::data::TermStructure;
use num::Float;
use std::collections::BTreeMap;
use time::Date;
pub struct Surface<S, C>
where
S: CurveIndex,
C: CurveIndex,
{
pub nodes: BTreeMap<S, Curve<C>>,
}
#[allow(dead_code)] pub struct Surface {
pub nodes: BTreeMap<u64, TermStructure>,
}
#[allow(dead_code)]
impl Surface {
pub fn new() -> Self {
Self {
nodes: BTreeMap::new(),
}
}
pub fn add_node(&mut self, time: u64, term_structure: TermStructure) {
self.nodes.insert(time, term_structure);
}
pub fn get_term_structure(&self, time: u64) -> Option<&TermStructure> {
self.nodes.get(&time)
}
}
#[cfg(test)]
mod tests {
use super::*;
use time::{Date, Month};
#[test]
fn test_surface_creation() {
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];
let term_structure = TermStructure::new(&dates, &rates);
let mut surface = Surface::new();
surface.add_node(1, term_structure);
assert_eq!(surface.nodes.len(), 1);
assert!(surface.get_term_structure(1).is_some());
let ts = surface.get_term_structure(1).unwrap();
assert_eq!(ts.nodes.len(), 3);
assert_eq!(
ts.nodes
.get(&Date::from_calendar_date(2023, Month::January, 1).unwrap()),
Some(&0.05)
);
assert_eq!(
ts.nodes
.get(&Date::from_calendar_date(2023, Month::February, 1).unwrap()),
Some(&0.06)
);
assert_eq!(
ts.nodes
.get(&Date::from_calendar_date(2023, Month::March, 1).unwrap()),
Some(&0.07)
);
}
}