Binary options

Cash-or-nothing binary options. The call pays 1 if spot > strike at expiry, otherwise 0; the put is symmetric. Greek functions return both call and put values in a single call.

Contract: Binary.sol

Functions

FunctionGasDescription
binaryCallPrice2,092Cash-or-nothing call: e^(−r·τ) · Φ(d₂)
binaryPutPrice2,097Cash-or-nothing put
binaryDelta1,825First derivative w.r.t. spot — returns (Δcall, Δput)
binaryGamma1,967Second derivative w.r.t. spot — returns (Γcall, Γput)
binaryTheta3,501Time decay, per day — returns (Θcall, Θput)
binaryVega1,913Sensitivity per 1% vol — returns (νcall, νput)

npm install defimath-lib

Conventions

  • spot, strikeuint128, 18-decimal fixed-point (1e18 = 1.0).
  • timeToExpuint32, seconds to expiration.
  • volatilityuint64, annualized vol as 18-decimal fixed-point (e.g. 50% → 5e17).
  • rateuint64, annualized risk-free rate as 18-decimal fixed-point.
  • Unit payout. All results assume a payout of 1. Multiply the result externally for an arbitrary payout Q.
  • All functions are internal pure.

Quick example

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

uint256 binCall = DeFiMathBinary.binaryCallPrice(spot, strike, timeToExp, vol, rate);
uint256 binPut  = DeFiMathBinary.binaryPutPrice (spot, strike, timeToExp, vol, rate);

// All binary Greeks return (call, put) tuples.
(int128 dC, int128 dP) = DeFiMathBinary.binaryDelta(spot, strike, timeToExp, vol, rate);

Important notes

  • All four Greeks return tuples. Unlike vanilla options (where gamma and vega are equal for call and put under put-call parity), binary call and put have different second-order sensitivities — so all of binaryDelta, binaryGamma, binaryTheta, and binaryVega return (call, put).
  • Unit payout — scale externally. To price a digital with payout Q, compute the unit-payout price and multiply by Q on the call site.
  • binaryTheta is per day. The result is the price change for a one-day decrease in time to expiration.
  • binaryVega is per 1% vol. The result is the price change for a 1-percentage-point change in volatility.
  • When to use binary vs. vanilla. Use binaries when the payout is discrete (prediction markets, depeg coverage, threshold hedges). For continuous payoff structures, reach for the Options module.

Limits & errors

ConstantValue
MIN_SPOT1e-6 (smallest allowed spot price)
MAX_SPOT1e15 (largest allowed spot price)
MAX_STSP_RATIO5× (strike must be within [spot/5, spot·5])
MAX_EXPIRATION2 years (63,072,000 seconds)
MAX_RATE400% annual (4e18)
ErrorTrigger
SpotLowerBoundErrorspot ≤ MIN_SPOT
SpotUpperBoundErrorspot ≥ MAX_SPOT
StrikeLowerBoundErrorstrike · 5 < spot
StrikeUpperBoundErrorspot · 5 < strike
TimeToExpiryUpperBoundErrortimeToExp ≥ MAX_EXPIRATION
RateUpperBoundErrorrate ≥ MAX_RATE