-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from joaquinbejar/fix/remove_warnings
Fix/remove warnings
- Loading branch information
Showing
15 changed files
with
270 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ Cargo.lock | |
**/._.DS_Store | ||
.vscode/* | ||
.vscode | ||
|
||
.idea | ||
## PYTHON | ||
.venv/ | ||
.env/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::data::TermStructure; | ||
use std::collections::BTreeMap; | ||
|
||
/// Surface data. | ||
#[allow(dead_code)] // never used | ||
pub struct Surface { | ||
/// Nodes of the surface. | ||
pub nodes: BTreeMap<u64, TermStructure>, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl Surface { | ||
/// Create a new surface. | ||
pub fn new() -> Self { | ||
Self { | ||
nodes: BTreeMap::new(), | ||
} | ||
} | ||
|
||
/// Add a term structure node to the surface. | ||
pub fn add_node(&mut self, time: u64, term_structure: TermStructure) { | ||
self.nodes.insert(time, term_structure); | ||
} | ||
|
||
/// Get a term structure for a specific time. | ||
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.