Diffusal
Math

Black-Scholes Model

Option pricing algorithm and Greeks formulas

Diffusal uses the Black-Scholes model for European option pricing. This page covers the mathematical formulas and Greeks calculations.

For implementation details including fixed-point arithmetic and Solidity code, see Solidity Math.

The Black-Scholes Formula

Call Option

C=SN(d1)KerTN(d2)C = S \cdot N(d_1) - K \cdot e^{-rT} \cdot N(d_2)

Put Option

P=KerTN(d2)SN(d1)P = K \cdot e^{-rT} \cdot N(-d_2) - S \cdot N(-d_1)

d1 and d2

d1=ln(S/K)+(r+σ2/2)TσTd_1 = \frac{\ln(S/K) + (r + \sigma^2/2)T}{\sigma\sqrt{T}} d2=d1σTd_2 = d_1 - \sigma\sqrt{T}

Where:

  • S = Spot price (current underlying price)
  • K = Strike price
  • r = Risk-free interest rate
  • σ (sigma) = Volatility (annualized)
  • T = Time to expiry (in years)
  • N(x) = Cumulative normal distribution function

Parameters

SymbolNameSourceFormat
SSpot PricePrice Oracle (Pyth)8 decimals
KStrike PriceUser inputWAD (1e18)
rRisk-free RateDiffusalOracle8 decimals
σVolatilityDiffusalOracle8 decimals
TTime to ExpiryCalculatedWAD (years)

Greeks

The implementation calculates all primary Greeks alongside the option price.

Delta (Δ)

Rate of change of option price with respect to underlying price.

Δcall=N(d1)\Delta_{\text{call}} = N(d_1) Δput=N(d1)1\Delta_{\text{put}} = N(d_1) - 1

Range: Calls: 0 to 1, Puts: -1 to 0

Gamma (Γ)

Rate of change of Delta with respect to underlying price.

Γ=N(d1)SσT\Gamma = \frac{N'(d_1)}{S \cdot \sigma \cdot \sqrt{T}}

Same for both calls and puts. Always positive.

Vega (ν)

Sensitivity to volatility changes.

ν=SN(d1)T\nu = S \cdot N'(d_1) \cdot \sqrt{T}

Same for both calls and puts. Always positive.

Theta (Θ)

Time decay - rate of change with respect to time.

Θcall=SN(d1)σ2TrKerTN(d2)\Theta_{\text{call}} = -\frac{S \cdot N'(d_1) \cdot \sigma}{2\sqrt{T}} - r \cdot K \cdot e^{-rT} \cdot N(d_2) Θput=SN(d1)σ2T+rKerTN(d2)\Theta_{\text{put}} = -\frac{S \cdot N'(d_1) \cdot \sigma}{2\sqrt{T}} + r \cdot K \cdot e^{-rT} \cdot N(-d_2)

Usually negative (options lose value over time).

Rho (ρ)

Sensitivity to interest rate changes.

ρcall=KTerTN(d2)\rho_{\text{call}} = K \cdot T \cdot e^{-rT} \cdot N(d_2) ρput=KTerTN(d2)\rho_{\text{put}} = -K \cdot T \cdot e^{-rT} \cdot N(-d_2)

Example Calculation

Inputs:

  • Spot (S): $3,000
  • Strike (K): $3,000
  • Rate (r): 5%
  • Volatility (σ): 50%
  • Time (T): 30 days = 0.0822 years

Calculation:

d1=ln(3000/3000)+(0.05+0.52/2)×0.08220.5×0.0822=0+0.01440.1434=0.1003d_1 = \frac{\ln(3000/3000) + (0.05 + 0.5^2/2) \times 0.0822}{0.5 \times \sqrt{0.0822}} = \frac{0 + 0.0144}{0.1434} = 0.1003 d2=0.10030.1434=0.0431d_2 = 0.1003 - 0.1434 = -0.0431 N(d1)=0.5400,N(d2)=0.4828N(d_1) = 0.5400, \quad N(d_2) = 0.4828 Call=3000×0.54003000×e0.05×0.0822×0.4828=$176.7\text{Call} = 3000 \times 0.5400 - 3000 \times e^{-0.05 \times 0.0822} \times 0.4828 = \$176.7

To get this quote on-chain, call quoter.getOptionQuote() with an OptionRequest containing the pairId, strike (3000e18), expiry (30 days from now), and isCall = true. The returned quote price will be approximately 176.7e18.


Limitations

European Options Only

The Black-Scholes model assumes:

  • No early exercise (European style)
  • Constant volatility
  • Log-normal price distribution
  • No dividends

Edge Cases

ConditionBehavior
T = 0 (at expiry)Reverts with OptionExpired
σ = 0 (no volatility)May cause division by zero
S or K = 0Undefined behavior
Very long expiryMay overflow in time calculation

Implementation

The Black-Scholes model is implemented in Solidity using 64.64 fixed-point arithmetic for precision:

LibraryPurpose
BlackScholesLibCore pricing in 64.64 format
BlackScholesWadWAD adapter for external interface
Math64x64ExtendednormalCdf approximation (Abramowitz-Stegun)

The quoter contract provides the public API:


On this page