LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#36
Barrier-touch probability
hardMathsacceptance —~35 min
Implement touch_probability(S, B, T, r, sigma) — the probability that a geometric Brownian motion starting at S touches an upper barrier B > S at some point before T, under risk-neutral drift. With m = ln(B / S), nu = r - sigma²/2 and s = sigma·sqrt(T), the reflection principle gives P = Φ((-m + nu·T) / s) + (B / S)^(2·nu / sigma²)·Φ((-m - nu·T) / s). Use statistics.NormalDist().cdf for Φ.
This is the probability behind every knock-in, every stop-loss and the /learn probability chapter's third way. Return P rounded to 4 decimal places.
example 1
input
S=100.0, B=110.0, T=1.0, r=0.02, sigma=0.2
output
0.6337
note
Here r = sigma²/2 exactly, so the drift term vanishes.
example 2
input
S=100.0, B=110.0, T=1.0, r=0.05, sigma=0.2
output
0.6783
constraints
- 0 < S < B
- 0 < T ≤ 5
- 0 ≤ r ≤ 0.2
- 0.01 ≤ sigma ≤ 2
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to touch_probability()
S=100.0, B=110.0, T=1.0, r=0.02, sigma=0.2
expected
0.6337
the judge calls touch_probability() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice