astrovascpy.ou

Functions

compute_OU_params(time, x_max, c)

Zero finder function to compute the value of kappa and sigma.

expected_time(kappa, x_max, C[, Nspace])

Calculate the expected time to reach x_max starting from x_0=0.

ornstein_uhlenbeck_process(kappa, sigma, dt)

Monte Carlo simulation of the OU process with a reflecting boundary at zero.

astrovascpy.ou.compute_OU_params(time, x_max, c)

Zero finder function to compute the value of kappa and sigma.

Parameters:
  • time (float) – simulation time.

  • x_max (float) – maximum value for the radius.

  • c (float) – number of st dev distance from origin

Returns:

(kappa, sigma)

Return type:

tuple

astrovascpy.ou.expected_time(kappa, x_max, C, Nspace=10000)

Calculate the expected time to reach x_max starting from x_0=0.

We assume that x_max = C sigma/ sqrt(2 kappa) The code solves the ODE:

-kappa x U’(x) + 1/2 sigma^2 U’’(x) = -1

with U’(0)=0 and U(x_max) = 0 We use backward discretization for the first order derivative. Using the BC we get U(-1)=U(0) and U(N)=0. In matrix form, we solve: DU = -1, with tri-diagonal matrix D.

Parameters:
  • kappa (float) – mean reversion coefficient.

  • x_max (float) – maximum value for the radius.

  • C (float) – number of st dev distance from origin

  • Nspace (int) – number of discretization points.

Returns:

expected time.

Return type:

float

astrovascpy.ou.ornstein_uhlenbeck_process(kappa, sigma, dt, iterations=1, zero_noise_time=1, seed=1234)

Monte Carlo simulation of the OU process with a reflecting boundary at zero.

Stochastic differential equation:

dX(t) = - kappa X(t) dt + sigma dW

with solution:

X(t+dt) = X(t) * exp(-kappa dt) + alpha * epsilon(t)

where: alpha = sqrt( sigma^2 / (2kappa) * (1-exp(-2*kappa*dt)) ) alpha is the standard deviation of epsilon. epsilon is a standard Gaussian random variable. The process starts at X(0) = 0

Parameters:
  • kappa (float) – mean reversion coefficient.

  • sigma (float) – diffusion coefficient of the noise W

  • dt (float) – time-step.

  • iterations (int) – number of iterations.

  • zero_noise_time (int) – index at which the noise is set to zero for the rest of the simulation

  • seed (int) – RNG seed

Returns:

Reflected OU process starting at zero.

Return type:

numpy.array