danielhstahl / black_scholes_rust

Rust for black scholes
https://danielhstahl.github.io/black_scholes_rust/dev/bench/
23 stars 8 forks source link

CDF function is not appropriate, can use statrs package for accurate values. #8

Closed dileepbapat closed 3 years ago

dileepbapat commented 3 years ago

https://github.com/danielhstahl/black_scholes_rust/blob/c5582fa71295b7411a872d0e3a8eaf069edff10e/src/lib.rs#L8

use statrs::distribution::{Normal, Univariate};

pub fn cum_norm(x: f64) -> f64 {
    // (x / SQRT_2) * 0.5 
    let n = Normal::new(0.0, 1.0).unwrap();
    return n.cdf(x);
}
danielhstahl commented 3 years ago

What is wrong with erf

dileepbapat commented 3 years ago

Please check the values near maturity = 0.25/365.0. Values are way off from standard call value. It turned out replacing CDF gave an appropriate call value.

for example price of an in-the-money call option with 2 hours to expiry should be closer to (spot - strike).

call(14341.0, 14000.0, 0.1, 0.2125, 0.25/365.0)
> 552.5131384979031
should be around 341 

right?

danielhstahl commented 3 years ago

Ok I'll take a look.

danielhstahl commented 3 years ago

Ok I added a PR for the statrs but its slower (as I expected).

I added a test specifically for your function and I get 342 as the call price, not 552....see the test assertion at https://github.com/danielhstahl/black_scholes_rust/pull/10/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R481

danielhstahl commented 3 years ago

Long story short: