Skip to content

Commit

Permalink
chore: some small lints
Browse files Browse the repository at this point in the history
  • Loading branch information
avhz authored and avhz committed Oct 29, 2024
1 parent 5f83816 commit 8c12909
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion crates/RustQuant_autodiff/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'v> Ord for Variable<'v> {
mod tests_variable {
use super::*;

use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

#[test]
fn test_value() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl BlackScholesMerton {
mod tests_black_scholes_merton {
use super::*;
use time::Duration;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON};
use RustQuant_utils::assert_approx_equal;

#[test]
fn black_scholes_1973() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl FiniteDifferencePricer {
mod tests_finite_difference_pricer_at_the_money {
use super::*;
use time::macros::date;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON};
use RustQuant_utils::assert_approx_equal;

const EPS: f64 = 1e-4;
const EUROPEAN_CALL: FiniteDifferencePricer = FiniteDifferencePricer {
Expand Down Expand Up @@ -517,7 +517,7 @@ mod tests_finite_difference_pricer_at_the_money {
mod tests_finite_difference_pricer_in_the_money {
use super::*;
use time::macros::date;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON};
use RustQuant_utils::assert_approx_equal;

const EPS: f64 = 1e-5;
const EUROPEAN_CALL: FiniteDifferencePricer = FiniteDifferencePricer {
Expand Down Expand Up @@ -656,7 +656,7 @@ mod tests_finite_difference_pricer_in_the_money {
mod tests_finite_difference_pricer_out_of_the_money {
use super::*;
use time::macros::date;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON};
use RustQuant_utils::assert_approx_equal;

const EPS: f64 = 1e-5;
const EUROPEAN_CALL: FiniteDifferencePricer = FiniteDifferencePricer {
Expand Down
86 changes: 43 additions & 43 deletions crates/RustQuant_instruments/src/options/option_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,48 +266,48 @@ mod bsm {
use RustQuant_math::{Distribution, N};

#[inline]
pub(crate) fn d1(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
pub(crate) fn d1(s: f64, k: f64, t: f64, b: f64, v: f64) -> f64 {
((s / k).ln() + (b + 0.5 * v.powi(2)) * t) / (v * t.sqrt())
}

#[inline]
pub(crate) fn d2(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
d1(s, k, t, r, b, v) - v * t.sqrt()
pub(crate) fn d2(s: f64, k: f64, t: f64, b: f64, v: f64) -> f64 {
d1(s, k, t, b, v) - v * t.sqrt()
}

#[inline]
pub(crate) fn call_price(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

s * ((b - r) * t).exp() * N.cdf(d1) - k * (-r * t).exp() * N.cdf(d2)
}

#[inline]
pub(crate) fn put_price(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

-s * ((b - r) * t).exp() * N.cdf(-d1) + k * (-r * t).exp() * N.cdf(-d2)
}

#[inline]
pub(crate) fn call_delta(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

((b - r) * t).exp() * N.cdf(d1)
}

#[inline]
pub(crate) fn put_delta(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

((b - r) * t).exp() * (N.cdf(d1) - 1.0)
}

#[inline]
pub(crate) fn call_gamma(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

((b - r) * t).exp() * N.pdf(d1) / (s * v * t.sqrt())
}
Expand All @@ -319,8 +319,8 @@ mod bsm {

#[inline]
pub(crate) fn call_theta(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

-s * ((b - r) * t).exp() * N.pdf(d1) * v / (2.0 * t.sqrt())
- (b - r) * s * ((b - r) * t).exp() * N.cdf(d1)
Expand All @@ -329,8 +329,8 @@ mod bsm {

#[inline]
pub(crate) fn put_theta(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

-s * ((b - r) * t).exp() * N.pdf(d1) * v / (2.0 * t.sqrt())
+ (b - r) * s * ((b - r) * t).exp() * N.cdf(-d1)
Expand All @@ -339,7 +339,7 @@ mod bsm {

#[inline]
pub(crate) fn call_vega(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

s * ((b - r) * t).exp() * N.pdf(d1) * t.sqrt()
}
Expand All @@ -351,22 +351,22 @@ mod bsm {

#[inline]
pub(crate) fn call_rho(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d2 = d2(s, k, t, r, b, v);
let d2 = d2(s, k, t, b, v);

k * t * (-r * t).exp() * N.cdf(d2)
}

#[inline]
pub(crate) fn put_rho(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d2 = d2(s, k, t, r, b, v);
let d2 = d2(s, k, t, b, v);

-k * t * (-r * t).exp() * N.cdf(-d2)
}

#[inline]
pub(crate) fn call_vanna(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

-((b - r) * t).exp() * N.pdf(d1) * d2 / v
}
Expand All @@ -378,17 +378,17 @@ mod bsm {

#[inline]
pub(crate) fn call_charm(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

((b - r) * t).exp()
* (N.pdf(d1) * ((b / (v * t.sqrt())) - (d2 / (2.0 * t))) + (b - r) * N.cdf(d1))
}

#[inline]
pub(crate) fn put_charm(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

((b - r) * t).exp()
* (N.pdf(d1) * ((b / (v * t.sqrt())) - (d2 / (2.0 * t))) - (b - r) * N.cdf(-d1))
Expand All @@ -406,80 +406,80 @@ mod bsm {

#[inline]
pub(crate) fn call_zomma(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

call_gamma(s, k, t, r, b, v) * ((d1 * d2 - 1.0) / v)
}

#[inline]
pub(crate) fn put_zomma(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

put_gamma(s, k, t, r, b, v) * ((d1 * d2 - 1.0) / v)
}

#[inline]
pub(crate) fn call_speed(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

-call_gamma(s, k, t, r, b, v) * (1.0 + d1 / (v * t.sqrt())) / s
}

#[inline]
pub(crate) fn put_speed(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);

-put_gamma(s, k, t, r, b, v) * (1.0 + d1 / (v * t.sqrt())) / s
}

#[inline]
pub(crate) fn call_color(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

call_gamma(s, k, t, r, b, v)
* (r - b + b * d1 / (v * t.sqrt()) + (1.0 - d1 * d2) / (2.0 * t))
}

#[inline]
pub(crate) fn put_color(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

put_gamma(s, k, t, r, b, v)
* (r - b + b * d1 / (v * t.sqrt()) + (1.0 - d1 * d2) / (2.0 * t))
}

#[inline]
pub(crate) fn call_vomma(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

call_vega(s, k, t, r, b, v) * d1 * d2 / v
}

#[inline]
pub(crate) fn put_vomma(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

put_vega(s, k, t, r, b, v) * d1 * d2 / v
}

#[inline]
pub(crate) fn call_ultima(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

(call_vomma(s, k, t, r, b, v) / v) * (d1 * d2 - d1 / d2 + d2 / d1 - 1.0)
}

#[inline]
pub(crate) fn put_ultima(s: f64, k: f64, t: f64, r: f64, b: f64, v: f64) -> f64 {
let d1 = d1(s, k, t, r, b, v);
let d2 = d2(s, k, t, r, b, v);
let d1 = d1(s, k, t, b, v);
let d2 = d2(s, k, t, b, v);

(put_vomma(s, k, t, r, b, v) / v) * (d1 * d2 - d1 / d2 + d2 / d1 - 1.0)
}
Expand All @@ -497,11 +497,11 @@ macro_rules! impl_gbsm {
}

fn d1(&self, k: f64, t: f64) -> f64 {
bsm::d1(self.s(), k, t, self.r(), self.b(), self.v)
bsm::d1(self.s(), k, t, self.b(), self.v)
}

fn d2(&self, k: f64, t: f64) -> f64 {
bsm::d2(self.s(), k, t, self.r(), self.b(), self.v)
bsm::d2(self.s(), k, t, self.b(), self.v)
}

fn delta(&self, k: f64, t: f64, option_type: TypeFlag) -> f64 {
Expand Down
2 changes: 1 addition & 1 deletion crates/RustQuant_math/src/distributions/chi_squared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Distribution for ChiSquared {
#[cfg(test)]
mod tests {
use super::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

#[test]
fn test_chi_squared_characteristic_function() {
Expand Down
2 changes: 1 addition & 1 deletion crates/RustQuant_math/src/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
#[cfg(test)]
mod tests_sequences {
use super::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

#[test]
fn test_seq_f64() {
Expand Down
2 changes: 1 addition & 1 deletion crates/RustQuant_stochastics/src/brownian_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod sde_tests {
use super::*;
use crate::StochasticProcessConfig;
use RustQuant_math::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

#[test]
fn test_brownian_motion() {
Expand Down
2 changes: 1 addition & 1 deletion crates/RustQuant_stochastics/src/cox_ingersoll_ross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod tests_cir {
use super::*;
use crate::StochasticProcessConfig;
use RustQuant_math::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

#[test]
fn test_cox_ingersoll_ross() {
Expand Down
2 changes: 1 addition & 1 deletion crates/RustQuant_stochastics/src/extended_vasicek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests_extended_vasicek {
use super::*;
use crate::StochasticProcessConfig;
use RustQuant_math::*;
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

// fn alpha_t(_t: f64) -> f64 {
// 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use super::StochasticProcessConfig;
use crate::process::{StochasticProcess, Trajectories};
use nalgebra::{DMatrix, DVector, Dim, Dyn, RowDVector};
use ndarray::{concatenate, prelude::*};
use ndarray_rand::{rand::random, RandomExt};
// use ndarray_rand::{rand::random, RandomExt};
use ndarray_rand::RandomExt;
use ndrustfft::{ndfft_par, FftHandler};
use num::{complex::ComplexDistribution, Complex};
use rand::Rng;
Expand Down Expand Up @@ -267,7 +268,7 @@ mod test_fractional_brownian_motion {
use crate::StochasticProcessConfig;
use RustQuant_math::*;
use RustQuant_ml::{Decomposition, LinearRegressionInput};
use RustQuant_utils::{assert_approx_equal, RUSTQUANT_EPSILON as EPS};
use RustQuant_utils::assert_approx_equal;

fn higuchi_fd(x: &Vec<f64>, kmax: usize) -> f64 {
let n_times = x.len();
Expand Down
5 changes: 2 additions & 3 deletions examples/examples/curves_discount.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use polars::prelude::*;
use time::macros::date;
use time::Date;
use RustQuant::data::Curves;
use RustQuant::data::{Curve, DiscountCurve};
use RustQuant::time::oceania::australia::AustraliaCalendar;

fn main() {
let cal = AustraliaCalendar;
let curve = Curve::<Date>::new_from_slice(&DATES, &RATES);
let _cal = AustraliaCalendar;
let _curve = Curve::<Date>::new_from_slice(&DATES, &RATES);

let mut discount_curve = DiscountCurve::<Date, AustraliaCalendar>::new(&DATES, &RATES);

Expand Down

0 comments on commit 8c12909

Please sign in to comment.