vega

Binary options

Computes Vega for binary cash-or-nothing call and put options using the Black-Scholes model (per 1% vol move).

Avg. gas

1,805

Max abs. error

1e-14

Signature

solidity
function vega(
    uint128 spot,
    uint128 strike,
    uint32  timeToExp,
    uint64  volatility,
    uint64  rate
) internal pure returns (int128 vegaCall, int128 vegaPut)

Parameters

NameTypeDescription
spotuint128Current spot price, 18-decimal fixed-point.
strikeuint128Strike price, 18-decimal fixed-point. Precision-tuned for the no-arbitrage band against spot — 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 rate, 18-decimal fixed-point.

Returns

NameTypeDescription
vegaCallint128Binary call vega per 1% vol for unit payout in 18-decimal fixed-point. Signed.
vegaPutint128Binary put vega per 1% vol for unit payout in 18-decimal fixed-point. Equal to −vegaCall.

Bounds

BoundValue
MIN_SPOT1e-6 smallest allowed spot price (1e12)
MAX_SPOT1e15 largest allowed spot price (1e33)
MAX_STSP_RATIO5× (strike must lie within [spot/5, spot·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. Binary vega is signed and changes sign at d₁ = 0 (around the strike) — unlike vanilla vega, which is always ≥ 0. νput = −νcall.
  • Volatility has no explicit revert — it's bounded only by its uint64 type (max ≈ 1.84e19, i.e. ~1840% annualized).
  • Fast-path on expiration: when timeToExp == 0, returns (0, 0).
  • Composes four DeFiMath primitives — ln, sqrtTime (specialized sqrt for years), expPositive (the discount factor), and exp (the density φ(d₂)).
  • Pure internal function; no external calls, no storage. Inlined into the caller's bytecode at compile time.

How it works

Binary vega is the sensitivity of the cash-or-nothing price to volatility, returned per 1% vol move (the raw figure divided by 100):

νcall=1100erTφ(d2)d1σ,νput=νcall\nu_{call} = -\frac{1}{100} \cdot \frac{e^{-rT} \, \varphi(d_2) \, d_1}{\sigma}, \qquad \nu_{put} = -\nu_{call}

Like binary gamma, the d₁ factor makes it sign-changing: raising volatility pushes probability toward the tail on one side of the strike and away on the other, so vega flips sign at-the-money. The density φ(d₂) uses Math.exp, the discount factor e^(−rT) uses Math.expPositive, and √T / ln(spot/strike) use Math.sqrtTime / Math.ln.

On the supported domain the magnitude stays well below 1, so the suite enforces an absolute error only — 1e-14 per 1% vol — with no relative bound. Head-to-head measurements live in defimath-compare.

Errors

ErrorTrigger
SpotLowerBoundErrorspot ≤ MIN_SPOT
SpotUpperBoundErrorspot ≥ MAX_SPOT
StrikeLowerBoundErrorstrike · 5 < spot
StrikeUpperBoundErrorspot · 5 < strike
TimeToExpiryUpperBoundErrortimeToExp ≥ MAX_EXPIRATION
RateUpperBoundErrorrate ≥ MAX_RATE

Example

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

(int128 vegaCall, int128 vegaPut) = BinaryOptions.vega(
    1000e18,         // spot = $1,000
    1050e18,         // strike = $1,050
    30 days,         // 30 days to expiry
    0.60e18,         // 60% annualized vol
    0.05e18          // 5% risk-free rate
);
// vegaCall per 1% vol (sign flips across the strike), vegaPut = -vegaCall