import Normal from '../dist/normal'; import Process from './_process'; /** * Ornstein-Uhlenbeck mean-reverting process, using an exact discrete-time sampler. * * The underlying SDE is * * $\mathrm{d}X_t = \theta(\mu - X_t) \mathrm{d}t + \sigma \mathrm{d}W_t.$ * * Because the SDE is linear, $X_{t+\mathrm{d}t} \mid X_t$ is Gaussian with closed-form mean and * variance. The sampler draws from that distribution directly * * $X_{t+\mathrm{d}t} = X_t\,e^{-\theta\,\mathrm{d}t} + \mu\left(1 - e^{-\theta\,\mathrm{d}t}\right) + \sigma\sqrt{\frac{1 - e^{-2\theta\,\mathrm{d}t}}{2\theta}}\,Z,$ * * where $Z \sim \mathcal{N}(0, 1)$. There is no step-size discretization error regardless of $\mathrm{d}t$. * * @class OrnsteinUhlenbeck * @memberof ran.process * @constructor */ export default class OrnsteinUhlenbeck extends Process { p: { theta: number; mu: number; sigma: number; dt: number; }; x: number; x0: number; c: { decay: number; noise: number; logNoise: number; }; /** * @param {number} theta Mean-reversion speed (must be > 0). * @param {number} mu Long-run mean. * @param {number} sigma Diffusion coefficient (must be > 0). * @param {number} [dt=1] Time step (must be > 0). */ constructor(theta: number, mu: number, sigma: number, dt?: number); _next(): number; /** * The one-step transition X_{i+1} | X_i is Normal(X_i*decay + mu*(1-decay), noise^2), the * same law _next() draws from. decay/noise are the one-step (dt) constants precomputed in * this.c — distinct from mean(t)/variance(t)'s elapsed-time decay exp(-theta*t) for * arbitrary t. * * @method _transitionLnPdf * @memberof ran.process.OrnsteinUhlenbeck * @param {number} xPrev State at the start of the step. * @param {number} xNext State at the end of the step. * @returns {number} Log-density of the transition xPrev -> xNext. * @protected * @ignore */ protected _transitionLnPdf(xPrev: number, xNext: number): number; /** @inheritdoc */ mean(t: any): number; /** @inheritdoc */ variance(t: any): number; /** @inheritdoc */ pdf(x: any, t: any): number; /** @inheritdoc */ covariogram(s: any, t: any): number; /** @inheritdoc */ marginal(t: any): Normal; /** * Estimates theta, mu, and sigma from an observed path via OLS regression of X_{n+1} on * X_n. Because _next() is already the exact AR(1) transition X_{n+1} = a + b*X_n + eps * (b = exp(-theta*dt), a = mu*(1-b)), this OLS regression coincides exactly with the MLE. * * @method fit * @memberof ran.process.OrnsteinUhlenbeck * @param {Array} path Array of observed states (as returned by path()). * @param {number} [dt=1] Time step between consecutive path observations (must be > 0). * @returns {OrnsteinUhlenbeck} A new instance with estimated theta, mu, and sigma. * @throws {Error} If path has fewer than 4 states, if dt is not > 0, or if the estimated * AR(1) slope falls outside (0,1) (too short or too noisy a path to recover mean reversion). */ static fit(path: any[], dt?: number): OrnsteinUhlenbeck; }