Skip to main content

ou_step

Function ou_step 

Source
pub fn ou_step(x: f32, mu: f32, theta: f32, sigma: f32, dt: f32, w: f32) -> f32
Expand description

Ornstein-Uhlenbeck step with caller-supplied noise.

The O-U process is the canonical mean-reverting stochastic process. It is used in Idle Hero for economy curves (resource prices, rival activity) that should wander but always return to a set point.

§Math

dx  =  θ(μ - x) dt + σ √dt · w
x'  =  x + θ(μ - x) dt + σ √dt · w

where w is a sample from a standard normal distribution N(0, 1).

§Arguments

  • x — current value
  • mu — long-run mean (equilibrium point)
  • theta — mean-reversion speed (> 0; typical 0.1–1.0)
  • sigma — volatility / noise scale (> 0)
  • dt — time step
  • w — standard normal noise sample N(0, 1)

§Returns

Next value x'.

§Edge cases

  • dt = 0 → returns x unchanged
  • theta = 0 → no mean reversion; pure random walk x + σ√dt·w
  • sigma = 0 → deterministic decay to mu: x + θ(μ−x)dt

§Example

use prime_diffusion::ou_step;
// No noise — converges toward mu=0 from x=1.0
let x1 = ou_step(1.0, 0.0, 0.5, 0.0, 0.1, 0.0);
assert!((x1 - 0.95).abs() < 1e-5);