Up-and-out digital put (source code)

= Up-and-out digital put
{title2=$\mathbf1_{\{S_T<K\}}\mathbf1_{\{\sup_{t\leq u\leq T}S_u<B\}}$}

A <digital put option> extinguished if the <stock> reaches an upper barrier $B$. Under the dividend-free <Black-Scholes model>, conditional on not having hit the barrier before the current time, let $0<S<B$, $\tau=T-t>0$, $m=\min(K,B)$, $\gamma=1-2r/\sigma^2$, and
$$
D_m(S,t)=e^{-r\tau}\Phi\!\left(\frac{\log(m/S)-(r-\sigma^2/2)\tau}{\sigma\sqrt\tau}\right).
$$
Then its price is
$$
H(S,t)=D_m(S,t)-(S/B)^\gamma D_m(B^2/S,t).
$$
The <Black-Scholes reflection symmetry> proves the pricing equation, and the two terms cancel at $S=B$. At expiry the reflected argument is above $B\geq m$, so its payoff is zero, while $S<m$ is equivalent to $S<K$ inside the alive region. Thus the correct free strike is capped at the barrier. For $K\geq B$, the value is the discounted upper-barrier survival probability, independent of $K$, as for a <barrier digital put>. For $K>B$ its terminal data have a corner discontinuity at the absorbing barrier. Set the price to zero after a hit; the reflected expression on the other side is not a valid contract value.