Skip to content

Commit

Permalink
Merge pull request #229 from joaquinbejar/fix/remove_warnings
Browse files Browse the repository at this point in the history
Fix/remove warnings
  • Loading branch information
avhz committed Jun 27, 2024
2 parents 25f887c + d69b620 commit 343ad3d
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Cargo.lock
**/._.DS_Store
.vscode/*
.vscode

.idea
## PYTHON
.venv/
.env/
Expand Down
2 changes: 1 addition & 1 deletion examples/logistic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Run: cargo run --release --example logistic_regression

use nalgebra::{DMatrix, DVector};
use time::Instant;
use std::time::Instant;
use RustQuant::ml::*;

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/option_pricing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use time::macros::date;
use RustQuant::instruments::options::*;

fn main() -> Result<(), Box<dyn std::error::Error>>{
fn main() -> Result<(), Box<dyn std::error::Error>> {
let option = BlackScholesMertonBuilder::default()
.underlying_price(100.0)
.strike_price(100.0)
Expand All @@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>>{
.expiration_date(date!(2024 - 12 - 31))
.option_type(TypeFlag::Call)
.build()?;

// Print the option price and greeks.
// There are more greeks available, but these are the most common.
println!("Call price = \t {}", option.price());
Expand Down
6 changes: 0 additions & 6 deletions src/data/curves/term_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ use std::collections::BTreeMap;
use std::fmt::Display;
use time::Date;

/// Surface data.
pub struct Surface {
/// Nodes of the surface.
pub nodes: BTreeMap<f64, TermStructure>,
}

/// Term structure data.
pub struct TermStructure {
/// Nodes of the term structure.
Expand Down
2 changes: 2 additions & 0 deletions src/data/surfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// STRUCTS, ENUMS, AND TRAITS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mod surface;

use super::Curve;
use num::Float;
use std::collections::BTreeMap;
Expand Down
71 changes: 71 additions & 0 deletions src/data/surfaces/surface.rs
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)
);
}
}
2 changes: 1 addition & 1 deletion src/instruments/options/bachelier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ModifiedBachelier {
#[cfg(test)]
mod tests_bachelier {
use super::*;
use crate::{assert_approx_equal, RUSTQUANT_EPSILON};
use crate::assert_approx_equal;
use time::Duration;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/instruments/options/forward_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ForwardStartOption {
#[cfg(test)]
mod tests_forward_start {
use super::*;
use crate::{assert_approx_equal, RUSTQUANT_EPSILON};
use crate::assert_approx_equal;

#[test]
fn TEST_forward_start_option() {
Expand Down
1 change: 1 addition & 0 deletions src/instruments/options/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl OptionParameters {
}
}

#[allow(dead_code)]
trait Payoff<U, S> {
fn payoff(&self, underlying: U, strike: S) -> f64;
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/optimization/gradient_descent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
//! $$

use crate::autodiff::{variables::variable::Variable, Accumulate, Gradient, Graph};
use time::{Duration, Instant};
use std::time::{Duration, Instant};

// use ::log::{info, max_level, warn, Level};

/// Gradient descent optimizer.
Expand Down
2 changes: 1 addition & 1 deletion src/math/rootfinding/rootfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl RootfinderData {

diff <= tolerance * f64::abs(x) && diff <= tolerance * f64::abs(y)
}

#[allow(dead_code)]
pub(crate) fn close_enough(x: f64, y: f64) -> bool {
if x == y {
return true;
Expand Down
Loading

0 comments on commit 343ad3d

Please sign in to comment.