vega

Black-76

Computes Vega of the option on a future using the Black-76 model (sensitivity to volatility change).

Avg. gas

1,659

Max abs. error

4e-13

when ν < 1

Max rel. error

5e-12

when ν ≥ 1

Signature

solidity
function vega(
    uint128 future,
    uint128 strike,
    uint32  timeToExp,
    uint64  volatility,
    uint64  rate
) internal pure returns (uint256 vegaOut)

Parameters

NameTypeDescription
futureuint128Current future price in 18-decimal fixed-point format.
strikeuint128Strike price, 18-decimal fixed-point. Precision-tuned for the no-arbitrage band against the future — see Bounds.
timeToExpuint32Time to expiration in seconds. timeToExp == 0 is allowed (handled as expired).
volatilityuint64Annualized implied volatility, 18-decimal fixed-point (e.g. 60% → 6e17).
rateuint64Annualized risk-free (discount) rate, 18-decimal fixed-point.

Returns

NameTypeDescription
vegaOutuint256Vega per 1% vol move in 18-decimal fixed-point. ν ≥ 0; identical for call and put under put-call parity.

Bounds

BoundValue
MIN_FUTURE1e-6 smallest allowed future price (1e12)
MAX_FUTURE1e15 largest allowed future price (1e33)
MAX_STSP_RATIO5× (strike must lie within [future/5, future·5])
MAX_EXPIRATION32 years (1,009,152,000 seconds)
MAX_RATE400% annual (4e18)

Behavior

  • Validates all five inputs against module-wide constants and reverts with a typed error on any violation.
  • Returns vega per 1% vol move as a single value — call and put vega are identical under put-call parity.
  • Fast-path on expiration: when timeToExp == 0, returns 0.
  • Composes three DeFiMath primitives — ln, sqrtTime (specialized sqrt for years), and exp (for the density φ(d₁)), plus expPositive for the discount.
  • Pure internal function; no external calls, no storage. Inlined into the caller's bytecode at compile time.

How it works

vega is the derivative of option value with respect to volatility, returned per 1% vol move (the raw figure divided by 100):

ν=erTFTφ(d1)100,φ(d1)=ed12/22π\nu = \frac{e^{-rT} F \sqrt{T} \, \varphi(d_1)}{100}, \qquad \varphi(d_1) = \frac{e^{-d_1^2 / 2}}{\sqrt{2\pi}}
d1=ln(F/K)+σ22TσTd_1 = \frac{\ln(F/K) + \tfrac{\sigma^2}{2} T}{\sigma \sqrt{T}}

The density φ(d₁) is evaluated as Math.exp(−d₁²/2) / √(2π), multiplied by future · √T, discounted by e^(−rT), and divided by 100 for the per-1% convention. Vega is symmetric across the call/put boundary, so only one value is returned.

Precision follows the dual-metric rule: a relative bound of 5e-12 where ν ≥ 1 and an absolute bound of 4e-13 where ν < 1, at future = $1,000 — head-to-head measurements live in defimath-compare.

Errors

ErrorTrigger
FutureLowerBoundErrorfuture ≤ MIN_FUTURE
FutureUpperBoundErrorfuture ≥ MAX_FUTURE
StrikeLowerBoundErrorstrike · 5 < future
StrikeUpperBoundErrorfuture · 5 < strike
TimeToExpiryUpperBoundErrortimeToExp ≥ MAX_EXPIRATION
RateUpperBoundErrorrate ≥ MAX_RATE

Example

solidity
import "defimath-lib/contracts/derivatives/Black76.sol";

uint256 v = Black76.vega(
    1000e18,         // future = $1,000
    1050e18,         // strike = $1,050
    90 days,         // 90 days to expiry
    0.60e18,         // 60% annualized vol
    0.05e18          // 5% discount rate
);
// v ≈ 1.9e18 per 1% change in volatility