[][src]Module black_scholes_pricer::bs

! # BSPricer ! Scalar and Vectorised version of: ! ! * Black scholes ! * Greeks
! * Binomial ! * Implied vol ! * Implied Interest rates ! * Strike from delta ! ! This library depends on the wide library which provides the crucial math functions exp/log/pow/cdf in vectorised versions. This makes the difference of over 50% ! compared to the serial versions of this function. ! ! Somewhat surprisingly on the (admittedly) small sample of PCs I've run it on with FMA/AVX instructions, the code generated is a touch faster than the equivalent with Intel's ISPC. That's probably due to instruction scheduling and cache differences. ! ! Compared to any other open source version of black scholes pricing I've found online, I believe this is the fastest CPU version. GPU versions can be faster depending on the circumstances ! ! On an i5 7300HQ I'm seeing 100,000,000 prices calculated per second. YMMV ! ! Compared to a serialised version of around 1800ms

Structs

Greeks

A container for all the greeks

Enums

OptionDir

Specify whether an option is put or call

Functions

bs_call

Black Scholes call pricing. The results are at the same index as the inputs Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

bs_put

Black Scholes put pricing for arrays. The results are at the same index as the inputs Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

call_delta

Call delta Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

call_greeks

Calculate all the greeks for put options in a single step This is more efficient than calculating the values individually, infact, if you need more than a two greeks it's faster to use this than the individual pricers However be aware the memory allocation cost for the results is the bottleneck and could slow things down if you do not have a large L1/L2 cache.

call_implied_interest_rate

Calculate implied interest rate from an call option price Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc Note this is an iterative calculation as there is no closed form solution. It exits when all the values in the array have reached a stable number

call_implied_vol

Calculate call implied vol from an option price Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc Note this is an iterative calculation as there is no closed form solution. It exits when all the values in the array have reached a stable number

call_rho

Call rho Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

call_strike_from_delta

Calculate the call strike from delta value given

call_theta

Call Theta Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

gamma

Gamma - is the same if call or put Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

put_delta

Put delta Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

put_greeks

Calculate all the greeks for put options in a single step This is more efficient than calculating the values individually, infact, if you need more than a two greeks it's faster to use this than the individual pricers However be aware the memory allocation cost for the results is the bottleneck and could slow things down if you do not have a large L1/L2 cache.

put_implied_interest_rate

Calculate implied interest rate from an put option price Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc Note this is an iterative calculation as there is no closed form solution. It exits when all the values in the array have reached a stable number

put_implied_vol

Calculate put implied vol from an option price Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc Note this is an iterative calculation as there is no closed form solution. It exits when all the values in the array have reached a stable number

put_rho

Put rho Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc

put_strike_from_delta

Calculate the call strike from delta value given

put_theta

Put Theta Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc The calculate for the put theta seems to have a number of different implementations. Bug fixes welcome

vega

Vega - is the same if call or put Years to expiry should be expressed as a f32 such as 20 days is 20/252 = 0.79 Risk free rate, volatility and dividend yield expressed as f32 with 1.0 = 100%. 0.2 = 20% etc