Guide 02 Knock-outs and knock-ins in closed form
Barrier options
Prices
A barrier option is a European option that is knocked out (out) or activated (in) the first time the underlying crosses a barrier $H$, below the spot (down) or above it (up). The barrier is monitored continuously and there is no rebate (Merton, Reiner and Rubinstein). The four functions take the arguments of blsprice, with the barrier before the flag:
| Function | Barrier | The option pays the European payoff if the underlying |
|---|---|---|
blsdownout | $H < S$ | never goes below $H$ |
blsdownin | $H < S$ | goes below $H$ at least once |
blsupout | $H > S$ | never goes above $H$ |
blsupin | $H > S$ | goes above $H$ at least once |
using FinancialToolbox
S = 100.0; K = 100.0; r = 0.02; T = 1.0; σ = 0.2; d = 0.01
blsdownout(S, K, r, T, σ, d, 90.0), blsdownin(S, K, r, T, σ, d, 90.0)(6.807708095396878, 1.5416976716998807)blsupout(S, K, r, T, σ, d, 110.0, false), blsupin(S, K, r, T, σ, d, 110.0, false)(5.658241328506518, 1.706048394348981)Exactly one of the knock-out and the knock-in pays, so together they are the European option (in-out parity):
blsdownout(S, K, r, T, σ, d, 90.0) + blsdownin(S, K, r, T, σ, d, 90.0) ≈ blsprice(S, K, r, T, σ, d)trueThe knock-outs vanish on the barrier, where the knock-ins become the European option. Near the barrier the delta of a knock-out is large: the option loses all its value over a small move of the spot.
Reflection principle
The prices are not new formulas, they are combinations of blsprice and blsbin. Let $\tilde V$ be the European price of the payoff restricted to the side of the barrier where the option is alive. By the reflection principle, the knock-out is
\[V_{out}(S) = \tilde V(S) - \left(\frac{H}{S}\right)^{p} \tilde V\!\left(\frac{H^2}{S}\right), \qquad p = \frac{2 (r - d)}{\sigma^2} - 1,\]
and the knock-in is the European option minus the knock-out. With $A(z)$ the price of $(S_T - K) 1_{S_T > z}$, a call struck at $z$ plus a binary paying $z - K$, and $B(z)$ the price of $(K - S_T) 1_{S_T < z}$, a put struck at $z$ plus a binary paying $K - z$:
| Option | $\tilde V$ |
|---|---|
| down-and-out call | $A(\max(K, H))$ |
| down-and-out put | $A(\max(K, H)) - A(H)$ |
| up-and-out call | $B(\min(K, H)) - B(H)$ |
| up-and-out put | $B(\min(K, H))$ |
The put and the call differ by $(S_T - K)$ restricted to the alive side (put-call parity). In the code this is a weight of 0 or -1 from the flag, not a branch, and the position of the strike with respect to the barrier is absorbed by max and min. So one formula covers every case, and reverse mode AD (Zygote) records no control flow. The price is smooth at $K = H$, where the kink of max is multiplied by $\max(K, H) - K = 0$. A down-and-out put with $K \le H$ and an up-and-out call with $K \ge H$ are worth exactly zero: the payoff needs the barrier to be crossed.
blsdownout(S, 90.0, r, T, σ, d, 95.0, false), blsupout(S, 110.0, r, T, σ, d, 105.0)(0.0, 0.0)Sensitivities
There are no closed form Greeks for the barrier options and no differentiation rules of their own: every AD backend and number type differentiates through the code, down to the rules of the Black formula. Here the gradient with respect to all the inputs, barrier included, with ForwardDiff and with Zygote:
using ForwardDiff, Zygote
x = [S, K, r, T, σ, d, 90.0]
ForwardDiff.gradient(y -> blsdownout(y...), x)7-element Vector{Float64}:
0.7011209224082544
-0.3311923148677801
41.240934570716476
1.9266878592604035
15.823555945072075
-48.0486426661134
-0.3353905850961172collect(Zygote.gradient((y...) -> blsdownout(y...), x...))7-element Vector{Float64}:
0.7011209224082545
-0.33119231486778017
41.24093457071651
1.9266878592604035
15.823555945072068
-48.04864266611338
-0.33539058509611713Monte Carlo check
These closed forms are the references of the barrier options of FinancialMonteCarlo.jl. A plain Monte Carlo on a time grid monitors the barrier only at the grid points and overprices the knock-out. The probability that a Brownian bridge crosses the barrier between two points corrects for this, and recovers continuous monitoring. The estimate and its standard error, then the closed form:
using Random
function down_and_out_monte_carlo(S, K, r, T, σ, d, H; steps = 100, paths = 100_000, rng = Xoshiro(0))
dt = T / steps
drift, vol, h = (r - d - σ^2 / 2) * dt, σ * sqrt(dt), log(H)
total, total_squares = 0.0, 0.0
for _ = 1:paths
x, alive = log(S), 1.0
for _ = 1:steps
y = x + drift + vol * randn(rng)
# probability that the bridge from x to y stays above the barrier
alive *= y > h ? 1 - exp(-2 * (x - h) * (y - h) / vol^2) : 0.0
x = y
end
payoff = alive * max(exp(x) - K, 0.0)
total += payoff
total_squares += abs2(payoff)
end
mean = total / paths
return exp(-r * T) .* (mean, sqrt((total_squares / paths - abs2(mean)) / paths))
end
price, standard_error = down_and_out_monte_carlo(S, K, r, T, σ, d, 90.0)
price, standard_error, blsdownout(S, K, r, T, σ, d, 90.0)(6.769770870403964, 0.04078651049022816, 6.807708095396878)