danielhstahl / black_scholes_rust

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

How big of a deal is a ~1.5% mismatch on calculated IV? #19

Closed brandonros closed 1 year ago

brandonros commented 1 year ago
fn parse_date(input: &str) -> DateTime<Tz> {
    let parsed_input = chrono::DateTime::parse_from_rfc3339(&input).unwrap();
    let eastern_input = parsed_input.with_timezone(&Eastern);
    return eastern_input;
}

fn main() {
    // calculate maturity
    let now = parse_date("2022-11-18T16:00:00-05:00");
    let expiration_date = parse_date("2022-12-16T16:00:00-05:00");
    let minutes_to_expiration = expiration_date.signed_duration_since(now).num_minutes();
    let minutes_per_day = 60.0 * 24.0;
    let days_to_expiration = (minutes_to_expiration as f64) / minutes_per_day;
    let maturity = days_to_expiration / 365.0;
    // prices
    let underlying_price = 396.15; // SPY
    let strike_price = 396.0; // at the money
    let call_option_price = 9.99;
    let put_option_price = 9.77;
    // risk free rate from 10 year (TNX)
    let risk_free_rate = 0.03819;
    // iv
    let actual_call_iv = 0.2166; // Robinhood
    let actual_put_iv = 0.2419; // Robinhood
    let calculated_call_iv = black_scholes::call_iv(
        call_option_price, 
        underlying_price, 
        strike_price, 
        risk_free_rate,
        maturity
    ).unwrap();
    let calculated_put_iv = black_scholes::put_iv(
        put_option_price, 
        underlying_price, 
        strike_price, 
        risk_free_rate,
        maturity
    ).unwrap();
    println!("actual_call_iv = {}", actual_call_iv);
    println!("actual_put_iv = {}", actual_put_iv);
    println!("calculated_call_iv = {}", calculated_call_iv);
    println!("calculated_put_iv = {}", calculated_put_iv);
}
actual_call_iv = 0.2166
actual_put_iv = 0.2419
calculated_call_iv = 0.21332873734186864
calculated_put_iv = 0.23828290707877298

not sure if it's becuase of dividend yield not being "supported" in the model/in this repo, different maturity value, different risk free rate

any suggestions? let me see what thinkorswim says

brandonros commented 1 year ago

image

danielhstahl commented 1 year ago

Lot of variables here...which rate do they use? How do they calculate time to maturity? I'm actually surprised its as close as 1.5% :).

brandonros commented 1 year ago

dumb question on my end, how much value does this library or any library have if you don't know time to maturity / risk free rate variables and always end up with slightly off results? obviously good for approximation. just asking, what is approximation worth? for example what is it worth calculating greeks by hand if they are always going to be off 1-2% compared to "the market"?