Your question is Simulate a Stochastic Process. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
For a McKinsey risk analytics prototype, estimate the probability that an asset price reaches an upper barrier during a finite horizon. Model the asset with geometric Brownian motion and improve the usual discrete-monitoring Monte Carlo estimate using Brownian bridge crossing probabilities between time steps.
Implement estimate_barrier_probability, which receives pre-generated standard-normal shocks so that results are reproducible and independently testable.
Input values are:
s0, mu, sigma, barrier, and horizon: real numbers.shocks: a non-empty rectangular list of paths, where each inner list contains independent standard-normal shocks for successive time steps.Use len(shocks) paths and len(shocks[0]) equally spaced time steps. Under geometric Brownian motion, update the log price with:
log(S[t+1]) = log(S[t]) + (mu - sigma² / 2) * dt + sigma * sqrt(dt) * shock
Estimate each path's probability of crossing the barrier. If both endpoints of a segment are below the barrier, use the Brownian bridge crossing probability:
exp(-2 * (log(barrier)-x) * (log(barrier)-y) / (sigma² * dt))
Return a dictionary containing the mean crossing probability, its standard error, and a 95% confidence interval. Round numeric values to six decimal places.
def estimate_barrier_probability(s0, mu, sigma, barrier, horizon, shocks):