danielhstahl / black_scholes_rust

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

outline vanna + vomma + charm #16

Closed brandonros closed 1 year ago

brandonros commented 1 year ago

yeah i'm not going to kid myself and pretend i can do math at this level lol

could you help me get this across the finish line? not sure how to implement it while matching the pattern you have going in

brandonros commented 1 year ago
use crate::math::{standard_normal_cdf, standard_normal_probability_density};

pub fn charm(
    sigma: f64,
    expiration_time: f64,
    current_time: f64,
    current_price: f64,
    strike: f64,
) -> f64 {
    let t = expiration_time - current_time;
    let d1 = d1(sigma, expiration_time, current_time, current_price, strike);
    let d2 = d2(d1, sigma, expiration_time, current_time);

    let numerator = (2.0 * R * t) - (d2 * sigma * t.sqrt());
    let denominator = 2.0 * t * sigma * t.sqrt();
    -standard_normal_probability_density(d1) * (numerator / denominator)
}

fn d1(sigma: f64, expiration_time: f64, current_time: f64, current_price: f64, strike: f64) -> f64 {
    let t = expiration_time - current_time;
    ((current_price / strike).ln() + (R + (sigma.powi(2) / 2.0)) * t) / (sigma * t.sqrt())
}

fn d2(d1: f64, sigma: f64, expiration_time: f64, current_time: f64) -> f64 {
    let t = expiration_time - current_time;
    d1 - (sigma * t.sqrt())
}

got this from here https://github.com/picklenerd/market_analyzer/blob/main/src/math/bs.rs

brandonros commented 1 year ago

vomma: https://github.com/valoox/qrust/blob/0bc5b48d0160454cc702da5a7864e56408924acd/src/pricing/european.rs

let vomma = vega * d1 * d2 / sigma;
brandonros commented 1 year ago

sorry i didn't realize i "missed" other second order greeks... not sure if they are wortwhile

greeks

first order

* Delta measures how option price will change if underlying price increases by $1.
* Theta measures how much an option's price will change in one day.
* Vega measures how option price will change if implied volatility rises by one percentage point.
* Rho measures how option premium will change if the risk-free interest rate increases by one percentage point.

second order

* Gamma measures how much delta will change if underlying price increases by $1.
* [Vanna](https://www.macroption.com/option-vanna/) = Also DvegaDspot or DdeltaDvol. Sensitivity of option price to small changes in [underlying price](https://www.macroption.com/underlying-price/) and [volatility](https://www.macroption.com/volatility/), sensitivity of [vega](https://www.macroption.com/option-vega/) to small changes in [underlying price](https://www.macroption.com/underlying-price/), or sensitivity of [delta](https://www.macroption.com/option-delta/) to small changes in [volatility](https://www.macroption.com/volatility/).
* [Vera](https://www.macroption.com/option-vera/) = Also rhova. Sensitivity of option price to small changes in [volatility](https://www.macroption.com/volatility/) and interest rates, sensitivity of [rho](https://www.macroption.com/option-rho/) to small changes in [volatility](https://www.macroption.com/volatility/), or sensitivity of [vega](https://www.macroption.com/option-vega/) to small changes in interest rates.
* [Veta](https://www.macroption.com/option-veta/) = Also vega decay or DvegaDtime. Sensitivity of option price to small changes in [volatility](https://www.macroption.com/volatility/) and passage of time, sensitivity of [vega](https://www.macroption.com/option-vega/) to passage of time, or sensitivity of [theta](https://www.macroption.com/option-theta/) to small changes in [volatility](https://www.macroption.com/volatility/).
* [Vomma](https://www.macroption.com/option-vomma/) = Also [vega](https://www.macroption.com/option-vega/) convexity, volga, or DvegaDvol. Sensitivity of vega to small changes in [volatility](https://www.macroption.com/volatility/).
* [Charm](https://www.macroption.com/option-charm/) = Also delta decay or DdeltaDtime. Sensitivity of option price to small changes in [underlying price](https://www.macroption.com/underlying-price/) and passage of time, sensitivity of [theta](https://www.macroption.com/option-theta/) to small changes in [underlying price](https://www.macroption.com/underlying-price/), or sensitivity of [delta](https://www.macroption.com/option-delta/) to passage of time.

third order

[Color](https://www.macroption.com/option-color/) = Also gamma decay or DgammaDtime. [Third order Greek](https://www.macroption.com/third-order-greeks/) which measures sensitivity of [gamma](https://www.macroption.com/option-gamma/) to passage of time (small changes in time to expiration).
[Speed](https://www.macroption.com/option-speed/) = Also DgammaDspot. [Third order Greek](https://www.macroption.com/third-order-greeks/) which measures sensitivity of [gamma](https://www.macroption.com/option-gamma/) to small changes in [underlying price](https://www.macroption.com/underlying-price/).
[Ultima](https://www.macroption.com/option-ultima/) = Also DvommaDvol. [Third order Greek](https://www.macroption.com/third-order-greeks/) which measures sensitivity of [vomma](https://www.macroption.com/option-vomma/) to small changes in [volatility](https://www.macroption.com/volatility/).
danielhstahl commented 1 year ago

I added vanna, vomma, and charm to the latest release (v0.10.0). Let me know if that works for you.