Skip to main content

gbm_step

Function gbm_step 

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

Geometric Brownian motion step with caller-supplied noise.

GBM models multiplicative processes where the quantity is always positive — resource stockpiles, market prices, skill multipliers.

§Math

Exact solution for one step:
x'  =  x · exp((μ − σ²/2) dt + σ √dt · w)

§Arguments

  • x — current value (must be > 0)
  • mu — drift rate (annualised, or per unit time)
  • sigma — volatility (> 0)
  • dt — time step
  • w — standard normal noise sample N(0, 1)

§Returns

Next value x' (always positive when x > 0).

§Edge cases

  • dt = 0 → returns x unchanged
  • sigma = 0 → deterministic exponential growth: x · exp(μ·dt)
  • x = 0 → returns 0 (absorbing state)

§Example

use prime_diffusion::gbm_step;
// Zero drift, no noise → x unchanged
let x1 = gbm_step(1.0, 0.0, 0.0, 0.1, 0.0);
assert!((x1 - 1.0).abs() < 1e-5);