Skip to content
All library documents

Monte Carlo Estimation of Barrier-Hitting Probabilities for an OU Process

Article Quant Q&A · Author: gwizardry

Summary

The document presents a Monte Carlo approach for estimating whether an Ornstein–Uhlenbeck (OU) process crosses a specified barrier during a finite horizon. It simulates discrete paths using mean-reverting drift toward a long-run level and normally distributed random increments, then counts the fraction of paths that cross the barrier. The code is offered as a starting point for a question about two independent OU processes being above barriers simultaneously; it simulates only one process and would need adaptation to model the joint event.

The approach estimates a path event empirically rather than deriving a closed-form probability. Its accuracy depends on the number of simulated paths and the time-step resolution, which can miss crossings between sampled times. The example checks a minimum against a lower barrier, so its event direction and barrier condition must be changed for an above-barrier question. It gives no simulation output or accuracy analysis, and it does not specify how to combine the two processes’ paths.

Key ideas

  • Monte Carlo path simulation can estimate the probability of an OU process crossing a barrier within a finite horizon.
  • The simulated OU process combines mean-reverting drift with normally distributed random increments.
  • The example counts paths whose minimum falls below a lower barrier.
  • Estimating simultaneous barrier events for two independent processes requires simulating and evaluating both paths jointly.
  • Discrete time steps may miss barrier crossings that occur between observations.

Tags

Full text
# What is the probability of two independent OU processes being above barriers at the same time?


# What is the probability of two independent OU processes being above barriers at the same time?












I have two OU processes.

I'd like to know the probability that during a time period 0 to T that they are both above a barrier simultaneously at least once.

## Answer by AlexAbrahams (score 1, accepted)

https://quant.stackexchange.com/a/38572

Here's my Python code for a Monte Carlo hint to your question. It simulates the Ornstein Uhlenbeck process and calculates the probability of touching a barrier $B < r_0$. It should be adjusted for this case of two independent OU.

```
import numpy as np
from matplotlib import pyplot as plt
from math import *
import numpy.random as nrand

plt.style.use('seaborn')

# Parameters

r0 = 0.02  # Starting interest rate
time = 100  # Simulation time
delta = 1 / 252  # Delta time
sigma = 0.03  # Volatility
ou_a = 20  # Rate of mean reversion
ou_mu = 0.02  # Long run average
end = 90  # Time = T
end = end + 1
i = 1000  # Number of simulations
barrier = 0.01  # Level of barrier

def brownian_motion_log_returns(dt, sig):
    sqrt_delta_sigma = sqrt(dt) * sig
    return nrand.normal(loc=0, scale=sqrt_delta_sigma, size=time)

def ornstein_uhlenbeck(t, a, mu, dt):
    paths = [r0]
    brownian_motion_returns = brownian_motion_log_returns(delta, sigma)
    for i in range(1, t):
        drift = a * (mu - paths[i - 1]) * dt
        randomness = brownian_motion_returns[i - 1]
        paths.append(paths[i - 1] + drift + randomness)
    return paths

# MONTE CARLO SIMULATION

paths = []
for i in range(i):
    level = ornstein_uhlenbeck(time, ou_a, ou_mu, delta)
    paths.append(level)

paths = np.asarray(paths)
paths = paths.T
new_paths = np.delete(paths, np.s_[end:], 0)  # Remove paths beyond T
print(np.shape(new_paths))

# MC projection graph

plt.plot(new_paths, lw=0.5)
plt.axhline(y=barrier, color='b', linestyle='-', lw=0.7)
plt.title('Monte Carlo Simulations')
plt.xlabel('Time')
plt.ylabel('Level')
plt.show()

def prob(path, b, i):
    count = 0
    for col in path.T:
        a = min(col)
        if a < b:
            count = count + 1
    p = count / i
    return p

mcp = prob(new_paths, barrier, i)
print('Monte Carlo probability of touching:', mcp)
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.