Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant OrnsteinUhlenbeck

From Leeroopedia
Revision as of 14:32, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Avhz_RustQuant_OrnsteinUhlenbeck.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Stochastic_Processes, Quantitative_Finance
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete implementation of the Ornstein-Uhlenbeck (OU) mean-reverting stochastic process provided by the RustQuant library.

Description

The Ornstein-Uhlenbeck process is a continuous-time, mean-reverting stochastic process defined by the SDE:

dX(t) = theta * (mu - X(t)) dt + sigma dW(t)

where theta is the speed of mean reversion, mu is the long-run mean level, and sigma is the volatility. The process is the continuous-time analogue of the AR(1) process. It is Gaussian, with known mean and variance:

  • E[X(T)] = X(0) * e^(-theta*T) + mu * (1 - e^(-theta*T))
  • Var[X(T)] = (sigma^2 / (2*theta)) * (1 - e^(-2*theta*T))

Key parameters:

  • mu (ModelParameter) -- The long-run mean level
  • sigma (ModelParameter) -- The volatility (must be non-negative)
  • theta (ModelParameter) -- Mean reversion speed

Usage

Use this process for modeling mean-reverting quantities such as interest rates (Vasicek model), commodity prices, volatility, or any financial variable that tends to revert to a long-run average. The OU process is the foundation for many short-rate models.

Code Reference

Source Location

Signature

pub struct OrnsteinUhlenbeck {
    pub mu: ModelParameter,
    pub sigma: ModelParameter,
    pub theta: ModelParameter,
}

impl OrnsteinUhlenbeck {
    pub fn new(
        mu: impl Into<ModelParameter>,
        sigma: impl Into<ModelParameter>,
        theta: impl Into<ModelParameter>,
    ) -> Self
}

impl StochasticProcess for OrnsteinUhlenbeck {
    fn drift(&self, x: f64, t: f64) -> f64
    fn diffusion(&self, _x: f64, t: f64) -> f64
    fn jump(&self, _x: f64, _t: f64) -> Option<f64>
    fn parameters(&self) -> Vec<f64>
}

Import

use RustQuant::stochastics::OrnsteinUhlenbeck;

I/O Contract

Inputs

Name Type Required Description
mu impl Into<ModelParameter> Yes The long-run mean level
sigma impl Into<ModelParameter> Yes The volatility (must be non-negative)
theta impl Into<ModelParameter> Yes Mean reversion speed

Outputs

Name Type Description
drift() f64 Returns theta(t) * (mu(t) - x) -- mean-reverting drift
diffusion() f64 Returns sigma(t) -- the diffusion component
jump() Option<f64> Always returns None (no jump component)
parameters() Vec<f64> Returns [mu(0), sigma(0), theta(0)]

Usage Examples

use RustQuant::stochastics::OrnsteinUhlenbeck;
use RustQuant::stochastics::{StochasticProcessConfig, StochasticScheme};

// Create an OU process with mu=0.15, sigma=0.45, theta=0.01
let ou = OrnsteinUhlenbeck::new(0.15, 0.45, 0.01);

// Configure simulation: x0=10.0, t_start=0.0, t_end=0.5, n_steps=100, 100 paths
let config = StochasticProcessConfig::new(
    10.0, 0.0, 0.5, 100, StochasticScheme::EulerMaruyama, 100, false, None
);

let output = ou.generate(&config);

// Access simulated paths
let paths = &output.paths;

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment