import Gamma from '../dist/gamma'; import Process from './_process'; /** * Cox-Ingersoll-Ross (CIR) mean-reverting process, using an Euler-Maruyama discretization * with reflection to keep paths non-negative. * * The underlying SDE is * * $\mathrm{d}X_t = \kappa(\theta - X_t) \mathrm{d}t + \sigma\sqrt{X_t} \mathrm{d}W_t.$ * * The Euler-Maruyama step uses reflection to prevent the noise term from amplifying * negative states: * * $X_{t+\mathrm{d}t} = X_t + \kappa(\theta - X_t)\,\mathrm{d}t + \sigma\sqrt{\max(X_t, 0)}\,\sqrt{\mathrm{d}t}\,Z,$ * * where $Z \sim \mathcal{N}(0, 1)$. When the Feller condition $2\kappa\theta > \sigma^2$ holds, the continuous-time process * is strictly positive; below the Feller threshold, paths may occasionally become negative * under Euler-Maruyama despite the reflection. * * @class CoxIngersollRoss * @memberof ran.process * @constructor */ export default class CoxIngersollRoss extends Process { p: { kappa: number; theta: number; sigma: number; dt: number; }; x: number; x0: number; c: { kappaDt: number; sigmaSqrtDt: number; sigma2OverKappa: number; }; /** * @param {number} kappa Mean-reversion speed (must be > 0). * @param {number} theta Long-run mean (must be > 0). * @param {number} sigma Volatility (must be > 0). * @param {number} [dt=1] Time step (must be > 0). */ constructor(kappa: number, theta: number, sigma: number, dt?: number); _next(): 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): Gamma; /** * Estimates kappa, theta, and sigma from an observed path via Conditional Least Squares * (Overbeck & Ryden, 1997). The true one-step conditional transition of CIR is a scaled * noncentral chi-squared with generally non-integer degrees of freedom — this codebase has * no machinery to represent that exactly (ran.dist.NoncentralChi2 rounds its k to the * nearest integer), so this estimator instead matches the first two conditional moments, * both of which are affine in the previous observation: stage 1 regresses X_{n+1} on X_n * (identical algebra to OrnsteinUhlenbeck.fit()) for kappa and theta; stage 2 regresses the * squared stage-1 residuals on X_n for sigma. This is consistent but not maximally * efficient (unlike BrownianMotion/GeometricBrownianMotion/OrnsteinUhlenbeck's exact MLE), * and its accuracy degrades near the Feller boundary and at large dt, where _next()'s own * Euler-Maruyama discretization diverges further from the exact continuous-time conditional * moments this estimator targets. See decisions/0044-process-fit-static-factory.md and * solutions/correctness/2026-07-28-1600-cir-conditional-vs-marginal-gamma-mismatch.md (why the * issue's literal "gamma transition density" ask is a marginal, not the true conditional). * * @method fit * @memberof ran.process.CoxIngersollRoss * @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 {CoxIngersollRoss} A new instance with estimated kappa, theta, and sigma. * @throws {Error} If path has fewer than 4 states, if dt is not > 0, if the estimated * AR(1) slope falls outside (0,1), or if the estimated sigma^2 is not positive. */ static fit(path: any[], dt?: number): CoxIngersollRoss; }