MathFin
Map / Valuation · Black–Scholes and Bachelier / MathFin.Models.BlackScholes.BinaryBarrierOption

Binary (digital) barrier options: Rubinstein & Reiner's closed form

MathFin.Models.BlackScholes.BinaryBarrierOptionMSC 91G20JEL G13 source

A digital (cash-or-nothing / asset-or-nothing) option that is additionally knocked in or knocked out by a single barrier H (Rubinstein & Reiner, Risk 4(9) (1991); Haug, The Complete Guide to Option Pricing Formulas, 2nd ed. (2007), ch. 4, "Binary Barrier Options"). Unlike the two-asset barriers in HeynenKatTwoAssetBarrier.lean, this is single-underlying, single-variable Black–Scholes machinery — no bivariate normal CDF needed.

Transcribed from QuantLib's ql/pricingengines/barrier/analyticbinarybarrierengine.cpp (AnalyticBinaryBarrierEngine_helper::payoffAtExpiry, upstream commit 6efc1ed, 2026-09-23). QuantLib computes a drift mu once (mu = log(dividendDiscount/discount)/variance − 1/2, which for constant cost-of-carry b = r − q is (b − σ²/2)/σ², i.e. the same hkMu-style drift divided by σ²) and shares one formula shape between the cash-or-nothing payoff (K = the fixed cash amount) and the asset-or-nothing payoff (mu shifted by +1, K = the forward price S·e^{bT}, QuantLib's spot·dividendDiscount/discount). We keep mu an explicit parameter rather than hard-wiring either case, exactly mirroring QuantLib's shared code path — the docstrings below name which mu/K substitution each payoff kind uses, but the lemmas hold for the shared formula shape regardless of which substitution is made.

With stdDev = σ√T, η = 1 for Down{In,Out} / η = −1 for Up{In,Out}, φ = 1 for a call / φ = −1 for a put:

x₁ = φ(log(S/X)/stdDev + μ·stdDev), x₂ = φ(log(S/H)/stdDev + μ·stdDev), y₁ = η(log(H²/(SX))/stdDev + μ·stdDev), y₂ = η(log(H/S)/stdDev + μ·stdDev),

and, with (H/S)^{2μ} written as exp(2μ·log(H/S)) (algebraically identical for S, H > 0; QuantLib's own overflow guard evaluates the product (H/S)^{2μ}·Φ(y) as a whole in logs, exp(2μ·log(H/S) + log Φ(y)), rather than this factor alone),

B₁ = Φ(x₁), B₂ = Φ(x₂), B₃ = (H/S)^{2μ}·Φ(y₁), B₄ = (H/S)^{2μ}·Φ(y₂).

QuantLib's 16-branch switch (barrier type × call/put × strike-vs-barrier) selects one of B₁, B₂, B₃, B₄ and their ± combinations per branch; the final price is discount·K·α. The 16 branches are transcribed verbatim below as bboDownInAlpha/bboDownOutAlpha (both share η = 1) and bboUpInAlpha/bboUpOutAlpha (both share η = −1).

Main definitions

  • bboPhiOf: the sign φ, equal to 1 for a call and -1 for a put.
  • bboX1, bboX2, bboY1, bboY2: the exponents of the four terms, struck at X (x₁), at the barrier H (x₂), at the reflected log log (H²/(S X)) (y₁) and at log (H/S) (y₂).
  • bboHS2mu: the factor (H/S)^{2μ}, written as exp (2μ · log (H/S)).
  • bboB1, bboB2, bboB3, bboB4: the four building blocks B₁ to B₄ of the Rubinstein and Reiner binary-barrier formulas.
  • bboDownInAlpha, bboDownOutAlpha, bboUpInAlpha, bboUpOutAlpha: the knock-in and knock-out α-factors for a down or up barrier (before the discount and payoff scale), each selected from B₁ to B₄ by isCall and the strike-barrier comparison xGeH.

Main results

  • bboDownIn_add_DownOut: knock-in + knock-out, same direction/type/regime, collapses to the vanilla digital α-factor B₁ — the barrier-hit event and its complement partition the payoff (the closed-form counterpart of BarrierParity.lean's knockIn_add_knockOut_eq_vanilla, checked on the literal 16-branch table; not derived from it here). Checked for every (isCall, xGeH) combination by decide-free case split.
  • bboUpIn_add_UpOut: the same parity for the up-barrier family (η = −1).
  • bboB1_eq_Phi_bsd2: at the risk-neutral drift μ = (r − σ²/2)/σ² the vanilla exponent x₁ is Black–Scholes' d₂ (bsd2 S X r σ T) — B₁ is the standard-normal factor of the cash-or-nothing digital.
  • value_digitalCall_eq_bboB1: under BSCallHyp, the Black–Scholes value of the digital call contract Contracts.digitalCall K T is the parity's vanilla leg e^{−rT}·B₁ (call side), through Contracts.BlackScholes.value_digitalCall.

Scope, disclosed honestly: this is a transcription of the QuantLib closed form, not a from-first-principles reflection-principle derivation of the barrier density. The in–out identity here is the closed-form counterpart of the measure-theoretic parity knockIn_add_knockOut_eq_vanilla (BarrierParity.lean): the barrier-hit event and its complement partition the payoff, so knock-in + knock-out must equal the vanilla leg B₁ — and the 16-branch table satisfies it branch-by-branch (a misplaced +/− sign on any one of the 14 sign-bearing QuantLib branches breaks it; the other two branches are the constant 0), though by pure term cancellation once the table is fixed. The vanilla leg alone is grounded beyond transcription: value_digitalCall_eq_bboB1 proves that, on the call side and at the risk-neutral drift, e^{−rT}·B₁ is the Black–Scholes value of the digital call contract. The knock-in and knock-out terms are not proved to be prices. The variance = 0 and (H/S)^{2μ} overflow edge cases QuantLib special-cases numerically, and the already-knocked-in/knocked-out spot guards AnalyticBinaryBarrierEngine::calculate() applies before calling payoffAtExpiry (a DownOut/UpOut priced at 0 once the spot has already crossed the barrier, a DownIn/UpIn re-priced as a plain vanilla digital via AnalyticEuropeanEngine once it has), are all out of scope — this file formalizes exactly payoffAtExpiry's own closed form, for a spot strictly on the live side of the barrier.

References

Tags

digital barrier option, Rubinstein–Reiner, cash-or-nothing, knock-in knock-out, exotic option, closed-form pricing, MSC 91G20, JEL G13

Import neighbourhood

Above: what it imports. Below: what imports it.

Corpus entries

mf-binary-barrier-inout-parity · exotic_options.json · reduced core
Binary Barrier In-Out Parity (Down and Up Families)

Rubinstein & Reiner's binary (digital) barrier closed forms, as transcribed: the down- and up-barrier knock-in plus knock-out alpha-factors sum to the vanilla digital alpha-factor B1 across all sixteen branch cases; and, on the call side at the risk-neutral drift, the Black-Scholes value of the digital call contract (Contracts.digitalCall, under BSCallHyp) equals the discounted vanilla leg e^{-rT} B1. The knock-in and knock-out terms are transcribed, not derived, and not proved to be prices: the barrier density behind the reflected terms is not proved.

Declarations 18

defMathFin.bboPhiOfsource
Bool → ℝ

φ(isCall) = 1 for a call, −1 for a put (QuantLib's phi).

defMathFin.bboX1source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

x₁: the B₁-side exponent for the payoff struck at X.

defMathFin.bboX2source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

x₂: the B₂-side exponent, struck at the barrier H instead of X.

used by 1: bboB2
defMathFin.bboY1source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

y₁: the B₃-side exponent, built from the reflected log log(H²/(SX)).

used by 1: bboB3
defMathFin.bboY2source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

y₂: the B₄-side exponent, built from log(H/S).

used by 1: bboB4
defMathFin.bboHS2musource
ℝ → ℝ → ℝ → ℝ

(H/S)^{2μ}, written as exp(2μ·log(H/S)) — algebraically the same value for S, H > 0. QuantLib's own overflow guard evaluates this factor together with its Φ(y) multiplier as one logged product, not this factor alone.

used by 2: bboB3, bboB4
defMathFin.bboB1source
ℝ → ℝ → ℝ → ℝ → ℝ → Bool → ℝ

B₁: the vanilla (barrier-free) digital α-factor for the isCall side — cash-or-nothing or asset-or-nothing depending on which mu/K substitution is made (see the module docstring); the price itself is discount·K·B₁, not B₁ alone.

defMathFin.bboB2source
ℝ → ℝ → ℝ → ℝ → ℝ → Bool → ℝ

B₂: B₁ with the strike replaced by the barrier H.

defMathFin.bboB3source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

B₃: the reflected term paired with B₁ across the barrier.

defMathFin.bboB4source
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → ℝ

B₄: the reflected term paired with B₂ across the barrier.

defMathFin.bboDownInAlphasource
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → Bool → Bool → ℝ

Down-barrier knock-in value (η = 1), QuantLib's DownIn switch case: B₃ when isCall and the strike dominates the barrier (xGeH), B₁ − B₂ + B₄ when isCall and X < H, B₂ − B₃ + B₄ for a put with X ≥ H, and B₁ for a put with X < H.

defMathFin.bboDownOutAlphasource
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → Bool → Bool → ℝ

Down-barrier knock-out value (η = 1), QuantLib's DownOut switch case: B₁ − B₃, B₂ − B₄, B₁ − B₂ + B₃ − B₄, or 0, selected the same way as bboDownInAlpha.

defMathFin.bboUpInAlphasource
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → Bool → Bool → ℝ

Up-barrier knock-in value (η = −1), QuantLib's UpIn switch case: B₁, B₂ − B₃ + B₄, B₁ − B₂ + B₄, or B₃, selected the same way as bboDownInAlpha (note the branches swap relative to DownIn: the isCall ∧ xGeH branch is B₁ here, not B₃).

defMathFin.bboUpOutAlphasource
ℝ → ℝ → ℝ → ℝ → ℝ → ℝ → Bool → Bool → ℝ

Up-barrier knock-out value (η = −1), QuantLib's UpOut switch case: 0, B₁ − B₂ + B₃ − B₄, B₂ − B₄, or B₁ − B₃.

theoremMathFin.bboDownIn_add_DownOutsource
∀ (S X H mu σ T : ℝ) (isCall xGeH : Bool), bboDownInAlpha S X H mu σ T isCall xGeH + bboDownOutAlpha S X H mu σ T isCall xGeH = bboB1 S X mu σ T isCall

In–out parity, down-barrier family: for every call/put choice and every strike-vs-barrier regime, the down-knock-in and down-knock-out values (QuantLib's DownIn and DownOut switch cases, η = 1 throughout) sum to the vanilla digital α-factor B₁ — the closed-form counterpart of knockIn_add_knockOut_eq_vanilla's partition identity (not derived from it here). Each of the four (isCall, xGeH) branches cancels its B₂, B₃, B₄ terms against the paired branch independently (so a transposed sign on any one of the seven sign-bearing Down* branches would break exactly that case; the eighth, the knock-out put with X < H, is the constant 0). On the call side, value_digitalCall_eq_bboB1 identifies e^{−rT}·B₁ with the value of the digital call contract.

theoremMathFin.bboUpIn_add_UpOutsource
∀ (S X H mu σ T : ℝ) (isCall xGeH : Bool), bboUpInAlpha S X H mu σ T isCall xGeH + bboUpOutAlpha S X H mu σ T isCall xGeH = bboB1 S X mu σ T isCall

In–out parity, up-barrier family: the same parity for UpIn/UpOut (η = −1 throughout).

theoremMathFin.bboB1_eq_Phi_bsd2source
∀ (S X r σ T mu : ℝ), σ ≠ 0 → 0 < T → mu = (r - σ ^ 2 / 2) / σ ^ 2 → bboB1 S X mu σ T true = Phi (bsd2 S X r σ T)

The vanilla leg is Black–Scholes' cash-or-nothing factor. At the risk-neutral drift μ = (r − σ²/2)/σ², the B₁ exponent x₁ = log(S/X)/(σ√T) + μσ√T is exactly Black–Scholes' d₂ with the same strike/rate/vol (bsd2 S X r σ T, Models/BlackScholes/Call.lean): the two disagree by μσ²T − (r − σ²/2)T = 0.

theoremMathFin.value_digitalCall_eq_bboB1source
∀ {Ω : Type u_1} {mΩ : MeasurableSpace Ω} {Q : Measure Ω} [IsProbabilityMeasure Q] {S_0 K r σ mu : ℝ} {T : NNReal} {Z : Ω → ℝ}, BSCallHyp Q S_0 K r σ (↑T) Z → mu = (r - σ ^ 2 / 2) / σ ^ 2 → Contract.value Q (fun x x_1 => Real.exp (-r * ↑T)) (assets S_0 r σ (↑T) Z) (digitalCall K T) = Real.exp (-r * ↑T) * bboB1 S_0 K mu σ (↑T) true

The parity's vanilla leg is the price of the digital call contract. Under BSCallHyp and at the risk-neutral drift μ = (r − σ²/2)/σ², the value of the contract Contracts.digitalCall K T (pay 1 at T if S_T > K) in the Black–Scholes model is the discounted vanilla leg e^{−rT}·B₁ (call side) of both parity theorems: Contracts.BlackScholes.value_digitalCall prices it at e^{−rT}·Φ(d₂), and bboB1_eq_Phi_bsd2 identifies Φ(d₂) with B₁.