Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Simulate a Stochastic Process

HardPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Formal Specification

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.

Constraints

  • 1 <= len(shocks) <= 100000
  • 1 <= len(shocks[0]) <= 1000
  • Every shock row has the same positive length
  • s0 > 0
  • barrier > 0
  • sigma >= 0
  • horizon >= 0

Function Signature

def estimate_barrier_probability(s0, mu, sigma, barrier, horizon, shocks):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output