Black-Scholes Option Delta and Hedging

Easy · Software Engineering Fundamentals · Data Scientist · Technical Screen

Problem Statement

An option's delta measures the instantaneous rate of change of the contract's fair price V with respect to the underlying asset's current market price S (delta = dV / dS), revealing both the contract's directional exposure (positive for calls, negative for puts) and the share ratio required to construct a locally delta-neutral hedge.

Implement option_delta to evaluate the exact analytical delta of a European call or put option under the Black-Scholes-Merton model with a continuous dividend yield:

def option_delta(
    option_type: str,
    spot: float,
    strike: float,
    time_to_expiry: float,
    rate: float,
    volatility: float,
    dividend_yield: float,
) -> float:
    ...

Parameters & Pricing Rules

  • option_type: "call" or "put" (matched case-insensitively after stripping leading/trailing whitespace).
  • spot (S > 0): current price of one share of the underlying asset.
  • strike (K > 0): contractual exercise price at expiration.
  • time_to_expiry (T >= 0): time remaining until expiration, measured in years.
  • rate (r): continuously compounded annual risk-free interest rate as a decimal (e.g., 0.04 for 4%).
  • volatility (sigma >= 0): annualized log-return volatility as a decimal (e.g., 0.40 for 40%).
  • dividend_yield (q): continuously compounded annual dividend yield as a decimal.

When sigma * sqrt(T) > 0, define:

  • d1 = (ln(S / K) + (r - q + 0.5 * sigma^2) * T) / (sigma * sqrt(T))
  • Call delta: e^(-q * T) * N(d1)
  • Put delta: e^(-q * T) * (N(d1) - 1) = -e^(-q * T) * N(-d1)

where N(x) is the standard normal cumulative distribution function. In the deterministic boundary case sigma * sqrt(T) == 0 (T == 0 or sigma == 0), use the smooth right-hand limit based on m = ln(S / K) + (r - q) * T: take d1 = +inf if m > 0, d1 = -inf if m < 0, and d1 = 0.0 if m == 0. Raise ValueError for invalid option_type strings or out-of-domain numeric inputs (spot <= 0, strike <= 0, time_to_expiry < 0, or volatility < 0).

Examples

Example 1

  • Input: option_type = "call", spot = 80, strike = 80, time_to_expiry = 0.25, rate = 0.04, volatility = 0.40, dividend_yield = 0.0
  • Output: 0.5596176923702425
  • Explanation: Total volatility is 0.40 * sqrt(0.25) = 0.20, log forward moneyness is ln(80 / 80) + 0.04 * 0.25 = 0.01, and d1 = (0.01 + 0.5 * 0.20^2) / 0.20 = 0.15. With q = 0, call delta equals N(0.15) ≈ 0.559618.

Example 2

  • Input: option_type = "put", spot = 80, strike = 80, time_to_expiry = 0.25, rate = 0.04, volatility = 0.40, dividend_yield = 0.0
  • Output: -0.4403823076297575
  • Explanation: Using the same contract parameters (d1 = 0.15), the European put delta is -N(-0.15) = N(0.15) - 1 ≈ -0.440382. Notice delta_call - delta_put = 1.0 = e^(-0 * 0.25).

Example 3

  • Input: option_type = "call", spot = 110, strike = 100, time_to_expiry = 1.0, rate = 0.06, volatility = 0.25, dividend_yield = 0.02
  • Output: 0.7325724303139259
  • Explanation: Here d1 = (ln(1.1) + (0.06 - 0.02 + 0.5 * 0.25^2) * 1.0) / 0.25 ≈ 0.666241, so e^(-0.02) * N(0.666241) ≈ 0.980199 * 0.747371 ≈ 0.732572.

Constraints

  • option_type.strip().lower() must be "call" or "put" (otherwise raise ValueError).
  • spot > 0 and strike > 0 (otherwise raise ValueError).
  • time_to_expiry >= 0 and volatility >= 0 (otherwise raise ValueError).
  • -1.0 <= rate, dividend_yield <= 1.0.
  • Answers within 1e-6 relative or absolute tolerance are accepted.

Step-by-step walkthrough

  1. Understand option delta in plain English

    Start with the contracts and market inputs:

    • A European call option grants its holder the right (without obligation) to buy one share of an underlying asset at a fixed strike price K on expiration date T.
    • A European put option grants its holder the right (without obligation) to sell one share at the strike price K on expiration date T.
    • The spot price S is today's market price of one share of that asset.

    An option's delta is the first partial derivative (instantaneous slope) of the contract's fair value V with respect to the spot price S, holding all other inputs fixed:

    delta = dV / dS
    

    Concretely, if a call carries a delta of 0.56, a small $1.00 uptick in the share price lifts the call's value by roughly $0.56 (and a $1.00 drop trims it by roughly $0.56).

    Our function option_delta receives seven arguments, with time in years and rates/volatility expressed as decimals (0.04 for 4%):

    • option_type: "call" or "put"
    • spot (S): current share price (S > 0)
    • strike (K): exercise price (K > 0)
    • time_to_expiry (T): years remaining until expiration (T >= 0)
    • rate (r): annual continuously compounded risk-free rate
    • volatility (sigma): annualized standard deviation of log returns (sigma >= 0)
    • dividend_yield (q): continuous annual dividend yield paid by the asset
  2. Intuition and signs for calls vs. puts

    Even before writing equations, the sign and bounds of delta follow directly from each contract's payoff:

    • Call delta is positive (0 to e^(-qT), or 0 to 1 when q = 0): Higher stock prices make the right to buy at K worth more.
      • Deep out of the money (S far below K): a $1 rise barely changes the tiny chance of finishing above K, so delta sits near 0.
      • At the money (S near K): the share is near the boundary of finishing above vs. below K, so delta sits near 0.5 (slightly higher when r > q).
      • Deep in the money (S far above K): exercise is nearly certain, so the call tracks one share of stock minus the dividend stream q forfeited prior to expiry, pushing delta toward e^(-qT) (1 when q = 0).
    • Put delta is negative (-e^(-qT) to 0, or -1 to 0 when q = 0): Higher stock prices make the right to sell at K worth less. Deep in the money (S far below K), put delta approaches -e^(-qT); deep out of the money (S far above K), put delta approaches 0.
    Call price V(S) vs. spot price S (with q = 0):
    
      V ^                        /  <-- slope (delta) -> 1 deep in the money
        |                      /
        |                    /      <-- slope (delta) ~ 0.5 near S = K
        |              _ . '
        |________. - '              <-- slope (delta) -> 0 deep out of the money
        +------------+-------------> S
                     K
    

    European calls and puts sharing (K, T) obey put-call parity — the no-arbitrage relation C - P = S * e^(-qT) - K * e^(-rT). Differentiating with respect to S (K * e^(-rT) has zero S-derivative) yields:

    delta_call - delta_put = e^(-qT)
    
  3. The Black-Scholes-Merton delta formulas

    Differentiating the Black-Scholes-Merton European pricing formula with respect to S gives:

    d1 = [ ln(S / K) + (r - q + 0.5 * sigma^2) * T ] / (sigma * sqrt(T))
    
    delta_call =  e^(-qT) * N(d1)
    delta_put  =  e^(-qT) * (N(d1) - 1)  =  -e^(-qT) * N(-d1)
    

    Here N(x) denotes the standard normal cumulative distribution function (CDF) — the probability P(Z <= x) for a standard normal variable Z (mean 0, variance 1). Symmetry of the bell curve (1 - N(d1) = N(-d1)) gives -e^(-qT) * N(-d1) for puts.

    Each term inside d1 has a clear role:

    • ln(S / K) + (r - q) * T = ln(S * e^((r - q)T) / K) measures log forward moneyness — how far the expected forward price sits above or below K.
    • sigma * sqrt(T) is the total log-return standard deviation over the remaining horizon T.
    • Watch the d1 vs. d2 distinction: N(d2) (with d2 = d1 - sigma * sqrt(T)) is the risk-neutral probability of expiring in the money, whereas delta uses N(d1), which weights exercise outcomes by how high S_T finishes.
  4. Compute the standard normal CDF accurately

    Python's math module supplies the complementary error function math.erfc(y) = 1 - erf(y), which gives N(x) via:

    N(x) = 0.5 * erfc(-x / sqrt(2))
    

    Why write 0.5 * erfc(-x / sqrt(2)) rather than 0.5 * (1 + erf(x / sqrt(2)))? When x is strongly negative (say x = -10), erf(x / sqrt(2)) rounds to -1.0 in 64-bit float, causing catastrophic cancellation (subtracting two nearly equal floats destroys significant digits) and returning 0.0. Calling erfc evaluates the small tail probability (~7.6e-24) directly without subtraction.

    import math
    
    
    def normal_cdf(x: float) -> float:
        """Return P(Z <= x) for a standard normal random variable Z."""
        return 0.5 * math.erfc(-x / math.sqrt(2.0))
    
  5. Handle boundary limits and code `option_delta`

    Before calling math.log or dividing by sigma * sqrt(T), handle two edge conditions cleanly:

    1. Domain checks: Verify option_type is "call" or "put" (case-insensitively), spot > 0, strike > 0, time_to_expiry >= 0, and volatility >= 0.
    2. Zero remaining uncertainty (sigma * sqrt(T) == 0): At expiration (T == 0) or zero volatility (sigma == 0), dividing by total_volatility would raise ZeroDivisionError. Taking the limit as total_volatility -> 0+ gives:
      • log_forward_moneyness > 0 -> d1 = +inf (N(+inf) = 1.0).
      • log_forward_moneyness < 0 -> d1 = -inf (N(-inf) = 0.0).
      • log_forward_moneyness == 0 -> 0.5 * total_volatility -> 0.0 (N(0) = 0.5).

    Evaluating -dividend_discount * normal_cdf(-d1) for puts also avoids float cancellation when normal_cdf(d1) is near 1.0.

    import math
    
    
    def normal_cdf(x: float) -> float:
        return 0.5 * math.erfc(-x / math.sqrt(2.0))
    
    
    def option_delta(option_type: str, spot: float, strike: float, time_to_expiry: float, rate: float, volatility: float, dividend_yield: float) -> float:
        kind = option_type.strip().lower()
        if kind not in ("call", "put"):
            raise ValueError("option_type must be 'call' or 'put'")
        if spot <= 0.0 or strike <= 0.0:
            raise ValueError("spot and strike must be strictly positive")
        if time_to_expiry < 0.0 or volatility < 0.0:
            raise ValueError("time_to_expiry and volatility must be non-negative")
    
        log_forward_moneyness = math.log(spot / strike) + (rate - dividend_yield) * time_to_expiry
        total_volatility = volatility * math.sqrt(time_to_expiry)
    
        if total_volatility > 0.0:
            variance_half = 0.5 * total_volatility * total_volatility
            d1 = (log_forward_moneyness + variance_half) / total_volatility
        elif log_forward_moneyness > 0.0:
            d1 = math.inf
        elif log_forward_moneyness < 0.0:
            d1 = -math.inf
        else:
            d1 = 0.0
    
        dividend_discount = math.exp(-dividend_yield * time_to_expiry)
        if kind == "call":
            return dividend_discount * normal_cdf(d1)
        return -dividend_discount * normal_cdf(-d1)
    
  6. Trace the three examples by hand

    Verify every intermediate figure on Examples 1, 2, and 3:

    Examples 1 & 2: S = 80, K = 80, T = 0.25, r = 0.04, sigma = 0.40, q = 0
      log_forward_moneyness = ln(80 / 80) + (0.04 - 0) * 0.25 = 0.01
      total_volatility      = 0.40 * sqrt(0.25)               = 0.20
      variance_half         = 0.5 * 0.20^2                    = 0.02
      d1                    = (0.01 + 0.02) / 0.20            = 0.15
      dividend_discount     = e^(0)                           = 1.0
    
      Example 1 (call):  1.0 * N(0.15)   =  0.559618
      Example 2 (put):  -1.0 * N(-0.15)  = -0.440382
      Check parity:      0.559618 - (-0.440382) = 1.000000 = e^(-0 * 0.25)
    
    Example 3: call, S = 110, K = 100, T = 1.0, r = 0.06, sigma = 0.25, q = 0.02
      log_forward_moneyness = ln(1.1) + (0.06 - 0.02) * 1.0   = 0.095310 + 0.04 = 0.135310
      total_volatility      = 0.25 * sqrt(1.0)                = 0.25
      variance_half         = 0.5 * 0.25^2                    = 0.031250
      d1                    = (0.135310 + 0.031250) / 0.25    = 0.666241
      dividend_discount     = e^(-0.02 * 1.0)                 = 0.980199
    
      Example 3 (call):  0.980199 * N(0.666241) = 0.980199 * 0.747371 = 0.732572
    
  7. How delta hedging works on a trading desk

    One share of stock moves $1 per $1 change in S, giving it a delta of +1. Because derivatives add linearly across positions, delta hedging buys or sells shares until the combined book's net delta is 0 (delta-neutral), canceling first-order exposure to small immediate moves in S.

    Walk through a concrete position using Example 1 (delta_call = 0.5596):

    Position: Short 10 call contracts (100 shares per contract = 1,000 calls).
      Options delta  = -1,000 * 0.5596 = -559.6 shares
      Hedge trade    = Buy +560 shares of stock (delta = +560)
      Combined delta = -559.6 + 560 ≈ 0 (delta-neutral)
    

    Suppose S ticks up by $1 from $80 to $81:

    • First-order estimate: the short calls lose roughly 1,000 * $0.5596 = $559.60, offset by a +$560.00 gain on the 560 shares.
    • Why dynamic rebalancing is needed: exact Black-Scholes pricing moves the call from $6.7467 to $7.3185 (-$571.85 on 1,000 short calls vs. +$560.00 on the shares), while the call's delta itself rises from 0.5596 to 0.5840. That curvature (d(delta) / dS) is gamma—so desks periodically buy ~24 additional shares here, balancing residual gamma exposure against transaction costs.
  8. Complete solution

    from typing import Any, Dict, List, Optional, Set, Tuple
    import math
    
    
    def normal_cdf(x: float) -> float:
        """Return P(Z <= x) for a standard normal random variable Z."""
        # Using erfc(-x / sqrt(2)) instead of 1 + erf(x / sqrt(2)) avoids subtracting nearly
        # equal floats when x is very negative, preserving precision in the far left tail.
        return 0.5 * math.erfc(-x / math.sqrt(2.0))
    
    
    def option_delta(option_type: str, spot: float, strike: float, time_to_expiry: float, rate: float, volatility: float, dividend_yield: float) -> float:
        """Compute the Black-Scholes delta of a European call or put with continuous dividend yield."""
        # Phase 1: Validate option type and domain constraints before taking logarithms or roots.
        kind = option_type.strip().lower()
        if kind not in ("call", "put"):
            raise ValueError("option_type must be 'call' or 'put'")
        if spot <= 0.0 or strike <= 0.0:
            raise ValueError("spot and strike must be strictly positive")
        if time_to_expiry < 0.0 or volatility < 0.0:
            raise ValueError("time_to_expiry and volatility must be non-negative")
    
        # Phase 2: Compute log forward moneyness ln(S * e^((r - q)T) / K) and total std dev sigma * sqrt(T).
        log_forward_moneyness = math.log(spot / strike) + (rate - dividend_yield) * time_to_expiry
        total_volatility = volatility * math.sqrt(time_to_expiry)
    
        # Phase 3: Compute d1, using the exact deterministic limit when sigma * sqrt(T) == 0.
        if total_volatility > 0.0:
            variance_half = 0.5 * total_volatility * total_volatility
            d1 = (log_forward_moneyness + variance_half) / total_volatility
        elif log_forward_moneyness > 0.0:
            # Zero uncertainty left and forward price > strike: option finishes in the money for sure.
            d1 = math.inf
        elif log_forward_moneyness < 0.0:
            # Zero uncertainty left and forward price < strike: option finishes out of the money for sure.
            d1 = -math.inf
        else:
            # Exactly at the forward price (S * e^((r - q)T) == K): d1 = 0.5 * sigma * sqrt(T) -> 0.
            d1 = 0.0
    
        # Phase 4: Scale by e^(-qT) because continuous dividends leak value out of the stock before expiry.
        dividend_discount = math.exp(-dividend_yield * time_to_expiry)
        if kind == "call":
            return dividend_discount * normal_cdf(d1)
    
        # By put-call parity, put delta = e^(-qT) * (N(d1) - 1) = -e^(-qT) * N(-d1).
        # Evaluating -N(-d1) avoids precision loss when N(d1) is very close to 1.
        return -dividend_discount * normal_cdf(-d1)
    

    ✅ Submit now — all tests should pass.

Intuition & how it works

Picture an option's fair value plotted as a smooth curve against today's share price (spot price S): delta (dV / dS) is the tangent slope of that curve at S, measuring both how many cents the contract moves per small $1 stock change and what fraction of a share replicates the option locally. A call option (the right to buy at strike price K on date T) benefits from higher share prices, giving positive delta in [0, e^(-qT)]; a put option (the right to sell at K) benefits from lower share prices, giving negative delta in [-e^(-qT), 0], where q is the continuous dividend yield (the annualized rate at which dividend value leaves the stock).

Treating delta as an all-or-nothing step (1 whenever S > K, 0 whenever S < K) fails prior to expiry because random return swings (volatility) can carry an out-of-the-money stock above K or pull an in-the-money stock below K. Repricing the contract at S + h and S - h (finite-difference bumping) works numerically, yet requires two full pricing calls and step-size tuning when calculus gives an exact closed form via the standard normal cumulative distribution function (CDF) N(x) (the probability that a zero-mean, unit-variance bell-curve variable lands at or below x).

Walk through Examples 1 and 2 (S = 80, K = 80, T = 0.25 years, r = 0.04, sigma = 0.40, q = 0):

  1. Compute log forward moneyness ln(80 / 80) + (0.04 - 0) * 0.25 = 0.01 and total volatility 0.40 * sqrt(0.25) = 0.20.
  2. Compute d1 = (0.01 + 0.5 * 0.20²) / 0.20 = 0.03 / 0.20 = 0.15.
  3. Evaluate the bell-curve CDF: call delta is e^0 * N(0.15) = 0.5596, and by put-call parity (delta_call - delta_put = e^(-qT)), put delta is -N(-0.15) = 0.5596 - 1 = -0.4404.

Complexity

  • Time: O(1), executing a fixed handful of floating-point operations (math.log, math.sqrt, math.exp, and math.erfc) regardless of input magnitudes.
  • Space: O(1), storing only scalar float variables (log_forward_moneyness, total_volatility, d1, dividend_discount) with no containers or recursion.

Edge cases

  • At the money with positive interest rate (S = K, r > 0, q = 0): Call delta sits strictly above 0.5 (0.5596 in Example 1) because d1 = (r + 0.5 * sigma²) * sqrt(T) / sigma > 0, while put delta sits closer to 0 than -0.5 (-0.4404).
  • At expiry (T = 0) or zero volatility (sigma = 0): sigma * sqrt(T) == 0 would divide by zero in the raw formula. Taking the deterministic limit maps d1 to +inf (delta_call = e^(-qT)), -inf (delta_call = 0), or 0.0 right at the forward strike S * e^((r - q)T) = K (0.5 * e^(-qT)).
  • Extreme moneyness: When d1 is large and positive, N(d1) rounds to 1.0 in float64 so N(d1) - 1.0 loses precision on deep out-of-the-money puts; computing -N(-d1) via math.erfc preserves accurate tail digits.
  • Continuous dividend yield (q > 0): Option holders miss dividends paid prior to T, scaling both deltas by e^(-qT) (as in Example 3, where e^(-0.02) ≈ 0.9802 scales 0.7474 down to 0.7326).
  • Invalid domains (S <= 0, K <= 0, T < 0, sigma < 0): Up-front checks raise a descriptive ValueError rather than failing inside math.log or math.sqrt.

Common mistakes

  • Plugging d2 instead of d1 into N(...): N(d2) (d2 = d1 - sigma * sqrt(T)) is the risk-neutral exercise probability and understates N(d1) whenever sigma * sqrt(T) > 0.
  • Omitting e^(-qT) or confusing it with e^(-rT): Dividends leak from the share (e^(-qT)), whereas e^(-rT) discounts the fixed strike K (whose S-derivative vanishes).
  • Dropping the leading minus sign on put delta: Returning N(-d1) instead of -N(-d1) makes put delta positive.
  • Miswriting d1: Dividing by sigma * T instead of sigma * sqrt(T), forgetting + 0.5 * sigma² * T, or passing whole percentages (4 instead of 0.04).
  • Relying on delta alone across large jumps: Delta is a local tangent; over wider moves, gamma (d²V / dS², the rate of change of delta) contributes 0.5 * gamma * (dS)².

Alternative approaches

  • Central finite difference (bump and reprice): Evaluate Black-Scholes prices (V(S + h) - V(S - h)) / (2 * h) with h = 1e-4 * S. That costs two full pricing calls and trades truncation error (O(h²)) against float cancellation (O(eps / h)), so closed-form option_delta is strictly better here—though finite differences remain standard for exotic contracts lacking closed-form Greeks.
  • statistics.NormalDist().cdf(x): Clean standard-library helper for moderate x, though CPython's internal 1.0 + math.erf(...) underflows in the far left tail earlier than 0.5 * math.erfc(-x / math.sqrt(2.0)).

Follow-up questions

  • How does gamma interact with delta, and why does a delta-neutral hedge drift out of balance? Gamma (d²V / dS²) measures how fast delta changes per $1 move in S, equal to e^(-qT) * n(d1) / (S * sigma * sqrt(T)) (where n is the standard normal density) for both calls and puts. Even after trading shares so net portfolio delta is 0 (delta-neutral), any subsequent stock move dS shifts option delta by roughly gamma * dS, leaving the hedge mismatched. Gamma peaks for at-the-money contracts near expiration (scaling like 1 / sqrt(T)), creating "pin risk" as delta swings sharply between 0 and 1.
  • Why does a European call's delta differ from its risk-neutral probability of expiring in the money? Under Black-Scholes, the risk-neutral probability P(S_T > K) equals N(d2), whereas a non-dividend call's delta is N(d1) with d1 = d2 + sigma * sqrt(T). Intuitively, N(d1) weights in-the-money outcomes by how high S_T lands (mathematically, it is P(S_T > K) under the stock-numeraire measure rather than the cash measure). For short-dated, low-volatility options sigma * sqrt(T) is tiny so traders loosely treat 0.30 delta as ~30% ITM odds, but for long-dated or high-volatility contracts the gap is substantial.
  • How do you calculate the underlying share trade needed to delta-hedge a multi-leg option book? Differentiation is linear, so net book delta equals the sum of contracts * multiplier * option_delta across all option legs plus 1 per underlying share already held; trading -book_delta shares brings net delta to 0. For example, holding +4 call contracts (100 shares each, delta +0.55) and +2 put contracts (100 shares each, delta -0.40) gives 400 * 0.55 + 200 * (-0.40) = +140 share-equivalents, so selling 140 shares neutralizes first-order spot exposure.

Follow-up questions

Similar questions

More Bnp interview questions

All 4 Bnp questions →