delta
Black-ScholesComputes Delta for both call and put options using the Black-Scholes model (sensitivity to spot price change).
Avg. gas
1,661
Max abs. error
1.2e-13
Signature
function delta(
uint128 spot,
uint128 strike,
uint32 timeToExp,
uint64 volatility,
uint64 rate
) internal pure returns (int128 deltaCall, int128 deltaPut)Parameters
| Name | Type | Description |
|---|---|---|
| spot | uint128 | Current spot price, 18-decimal fixed-point. |
| strike | uint128 | Strike price, 18-decimal fixed-point. Precision-tuned for the no-arbitrage band against spot — see Bounds. |
| timeToExp | uint32 | Time to expiration in seconds. timeToExp == 0 is allowed (handled as expired). |
| volatility | uint64 | Annualized implied volatility, 18-decimal fixed-point (e.g. 60% → 6e17). |
| rate | uint64 | Annualized risk-free rate, 18-decimal fixed-point. |
Returns
| Name | Type | Description |
|---|---|---|
| deltaCall | int128 | Call delta in 18-decimal fixed-point. δcall ∈ [0, 1]. |
| deltaPut | int128 | Put delta in 18-decimal fixed-point. δput = δcall − 1 ∈ [−1, 0]. |
Bounds
| Bound | Value |
|---|---|
| MIN_SPOT | 1e-6 smallest allowed spot price (1e12) |
| MAX_SPOT | 1e15 largest allowed spot price (1e33) |
| MAX_STSP_RATIO | 5× (strike must lie within [spot/5, spot·5]) |
| MAX_EXPIRATION | 32 years (1,009,152,000 seconds) |
| MAX_RATE | 400% annual (4e18) |
Behavior
- Validates all five inputs against module-wide constants and reverts with a typed error on any violation.
- Returns both call and put delta from a single
Φ(d₁)evaluation —δput = δcall − 1by put-call parity, so the second value is free. - Volatility has no explicit revert — it's bounded only by its
uint64type (max ≈1.84e19, i.e. ~1840% annualized). TheMIN_VOL_IV/MAX_VOL_IVconstants apply only to the impliedVolatility solver, not the greeks. - Fast-path on expiration: when
timeToExp == 0, delta collapses to its degenerate expiry value (0or±1by moneyness) without running the pricer. - Composes three DeFiMath primitives — ln,
sqrtTime(specialized sqrt for years), and stdNormCDF. Delta needs no discount factor, so there is noexpcall. - Pure
internalfunction; no external calls, no storage. Inlined into the caller's bytecode at compile time.
How it works
delta is the first derivative of option value with respect to spot. Under Black-Scholes it is simply the standard normal CDF of d₁:
The function annualizes timeToExp (seconds) by dividing by SECONDS_IN_YEAR, scales volatility by √T with Math.sqrtTime, forms ln(spot/strike) with Math.ln, and evaluates Φ(d₁) with Math.stdNormCDF. Because put delta differs from call delta by exactly 1, both are returned from one CDF evaluation — roughly halving gas versus computing them separately.
Delta is bounded to [−1, 1], so the suite enforces an absolute error only — no relative bound. The 1.2e-13 max absolute error is the bound enforced at spot = $1,000 across a full sweep of strike, time, vol, and rate — head-to-head measurements against other libraries live in defimath-compare.
Errors
| Error | Trigger |
|---|---|
| SpotLowerBoundError | spot ≤ MIN_SPOT |
| SpotUpperBoundError | spot ≥ MAX_SPOT |
| StrikeLowerBoundError | strike · 5 < spot |
| StrikeUpperBoundError | spot · 5 < strike |
| TimeToExpiryUpperBoundError | timeToExp ≥ MAX_EXPIRATION |
| RateUpperBoundError | rate ≥ MAX_RATE |
Example
import "defimath-lib/contracts/derivatives/BlackScholes.sol";
(int128 deltaCall, int128 deltaPut) = BlackScholes.delta(
1000e18, // spot = $1,000
980e18, // strike = $980
60 days, // 60 days to expiry
0.60e18, // 60% annualized vol
0.05e18 // 5% risk-free rate
);
// deltaCall ≈ 0.58e18, deltaPut ≈ -0.42e18