// Generated untyped declarations with JSDoc preserved export type UltoscOptions = { s1?: number; s2?: number; s3?: number; }; /** * Know Sure Thing (KST) momentum oscillator * Default parameters match common KST configuration */ export type KstOptions = { r1?: number; r2?: number; r3?: number; r4?: number; n1?: number; n2?: number; n3?: number; n4?: number; w1?: number; w2?: number; w3?: number; w4?: number; }; export type IchimokuOptions = { tenkan?: number; kijun?: number; senkouB?: number; }; export type DrawdownDurationResult = { durations: Int32Array; maxDuration: number; }; export type MaxDrawdownInfo = { maxDrawdown: number; peakIndex: number; troughIndex: number; startIndex: number; endIndex: number; }; declare namespace math { /** * Element-wise absolute value. * @param source Input array * @returns Float64Array of absolute values */ export function abs(source: ArrayLike): number[]; /** * Element-wise addition. * - If `b` is a number, returns `a + b` for each element. * - If `b` is an array, returns element-wise sum up to the shorter length. * @param a Left operand array * @param b Right operand array or scalar * @returns Float64Array of sums */ export function add(a: ArrayLike, b: ArrayLike | number): number[]; /** * Logical AND for boolean masks (Uint8Array) or with a scalar. * Returns a Uint8Array of 1/0 values. * @param a Left boolean mask * @param b Right boolean mask or scalar * @returns Uint8Array mask result */ export function and(a: Uint8Array, b: Uint8Array | number): number[]; /** * Index of the first maximum value (ignores NaNs). Returns -1 if none found. * @param source Input array * @returns Index of maximum or -1 */ export function argmax(source: ArrayLike): number; /** * Index of the first minimum value (ignores NaNs). Returns -1 if none found. * @param source Input array * @returns Index of minimum or -1 */ export function argmin(source: ArrayLike): number; /** * Element-wise average: (a + b) / 2. * Computes the average without allocating temporaries. * @param a First array * @param b Second array or scalar * @returns Float64Array of averages */ export function avg(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise ceil operation. * @param source Input array * @returns Float64Array of ceiled values */ export function ceil(source: ArrayLike): number[]; /** * Clamp values to the inclusive range [lo, hi]. Preserves NaN entries. * @param source Input array * @param lo Lower bound * @param hi Upper bound * @returns Float64Array with values clamped or NaN preserved */ export function clamp(source: ArrayLike, lo: number, hi: number): number[]; /** * Cumulative maximum: at each index the maximum over all prior valid elements. * NaNs are preserved in the output at positions where input is NaN. * @param source Input array * @returns Float64Array of cumulative maxima */ export function cummax(source: ArrayLike): number[]; /** * Cumulative minimum: at each index the minimum over all prior valid elements. * NaNs are preserved in the output at positions where input is NaN. * @param source Input array * @returns Float64Array of cumulative minima */ export function cummin(source: ArrayLike): number[]; /** * Cumulative product (NaN-preserving). At each index the product of all prior valid elements. * @param source Input array * @returns Float64Array of cumulative products (NaN where input was NaN) */ export function cumprod(source: ArrayLike): number[]; /** * Cumulative sum preserving NaNs: NaN entries do not increase the running sum * but are represented as the running total up to that point. * @param source Input array * @returns Float64Array of cumulative sums */ export function cumsum(source: ArrayLike): number[]; /** * First difference: output[i] = source[i] - source[i-1]. * The first element is NaN (no previous value). * @param source Input array * @returns Float64Array of differences (first element NaN) */ export function diff(source: ArrayLike): number[]; /** * Element-wise division. * - If `b` is a number, divides each element of `a` by `b`. * - If `b` is an array, returns element-wise quotients up to the shorter length. * @param a Numerator array * @param b Denominator array or scalar * @returns Float64Array of quotients */ export function div(a: ArrayLike, b: ArrayLike | number): number[]; /** * Dot product of two vectors: sum_i x[i] * y[i]. * Operates up to the shorter length of the inputs. * @param x First vector * @param y Second vector * @returns Scalar dot product */ export function dot(x: ArrayLike, y: ArrayLike): number; /** * Element-wise equality comparison using `Number.EPSILON` tolerance. * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask of equality tests */ export function eq(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise floor operation. * @param source Input array * @returns Float64Array of floored values */ export function floor(source: ArrayLike): number[]; /** * Element-wise greater-than comparison. Returns `Uint8Array` mask with 1 where true. * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask of comparisons */ export function gt(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise greater-than-or-equal comparison (with epsilon tolerance). * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask of comparisons */ export function gte(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise less-than comparison. Returns `Uint8Array` mask with 1 where true. * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask of comparisons */ export function lt(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise less-than-or-equal comparison (with epsilon tolerance). * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask of comparisons */ export function lte(a: ArrayLike, b: ArrayLike | number): number[]; /** * Maximum of an array, ignoring NaNs. Returns NaN if no valid entries. * @param source Input array * @returns Maximum value or NaN */ export function max(source: ArrayLike): number; /** * Minimum of an array, ignoring NaNs. Returns NaN if no valid entries. * @param source Input array * @returns Minimum value or NaN */ export function min(source: ArrayLike): number; /** * Element-wise multiplication. * - If `b` is a number, scales each element of `a` by `b`. * - If `b` is an array, returns element-wise products up to the shorter length. * @param a Left operand array * @param b Right operand array or scalar * @returns Float64Array of products */ export function mul(a: ArrayLike, b: ArrayLike | number): number[]; /** * Element-wise inequality comparison. * @param a Left operand * @param b Right operand or scalar * @returns Uint8Array mask where elements are not equal */ export function neq(a: ArrayLike, b: ArrayLike | number): number[]; /** * Vector p-norm. Supports common p values (1, 2, Infinity) with a fast dense path. * When `skipna` is true the implementation ignores NaNs and returns NaN if no valid entries exist. * @param x Input vector * @param p Norm order (default 2) * @param skipna Whether to ignore NaNs (default true) * @returns Norm value or NaN */ export function norm(x: ArrayLike, p?: number, skipna?: boolean): number; /** * Logical NOT for a boolean mask (Uint8Array). * @param a Input boolean mask * @returns Uint8Array mask with bits inverted */ export function not(a: Uint8Array): number[]; /** * Ordinary least squares for a simple linear model y = intercept + slope * x. * Ignores paired NaN entries and returns NaN coefficients if no valid pairs or singular design. * @param x Predictor values * @param y Response values * @returns Object with `intercept` and `slope` or NaNs on failure */ export function ols(x: ArrayLike, y: ArrayLike): { intercept: number; slope: number; }; /** * Multiple linear regression using normal equations (adds intercept column internally). * Returns coefficient vector or null if the normal matrix is singular or inputs are empty. * @param X Design matrix (rows = observations, cols = features) * @param y Response vector * @returns Coefficient array [intercept, beta1, beta2, ...] or null */ export function olsMulti(X: number[][], y: number[]): number[] | null; /** * Logical OR for boolean masks (Uint8Array) or with a scalar. * Returns a Uint8Array of 1/0 values. * @param a Left boolean mask * @param b Right boolean mask or scalar * @returns Uint8Array mask result */ export function or(a: Uint8Array, b: Uint8Array | number): number[]; /** * Product of array elements, ignoring NaNs. Returns NaN if no valid entries. * @param source Input array * @returns Product of values or NaN */ export function prod(source: ArrayLike): number; /** * Generate `n` standard normal samples using the Box-Muller transform. * Uses `Math.random()`; tests should stub `Math.random` for determinism. * @param n Number of samples to generate * @param options Optional `{ mean, sd }` to shift/scale samples * @returns Float64Array of length `n` */ export function randnormal(n: number, options?: { mean?: number; sd?: number; }): number[]; /** * Generate `n` uniform random values in [lo, hi). * Uses `Math.random()`; tests should stub `Math.random` for determinism. * @param n Number of samples to generate * @param options Optional `{ lo, hi }` bounds (defaults to 0..1) * @returns Float64Array of length `n` */ export function randuniform(n: number, options?: { lo?: number; hi?: number; }): number[]; /** * Rolling argmax: returns the index (into `source`) of the maximum value in each window. * Positions before the window fills are NaN. * @param source Input array * @param period Window length * @returns Float64Array of argmax indices (NaN when not available) */ export function rollargmax(source: ArrayLike, period: number): number[]; /** * Rolling argmin: returns the index (into `source`) of the minimum value in each window. * Positions before the window fills are NaN. * @param source Input array * @param period Window length * @returns Float64Array of argmin indices (NaN when not available) */ export function rollargmin(source: ArrayLike, period: number): number[]; /** * Rolling maximum over a window. NaN-aware: windows containing only NaNs produce NaN. * @param source Input values * @param period Window length (must be > 0) * @returns Float64Array of rolling maxima (NaN for positions before the window fills) */ export function rollmax(source: ArrayLike, period: number): number[]; /** * Rolling minimum over a window. NaN-aware: windows containing only NaNs produce NaN. * @param source Input values * @param period Window length (must be > 0) * @returns Float64Array of rolling minima (NaN for positions before the window fills) */ export function rollmin(source: ArrayLike, period: number): number[]; /** * Compute rolling minima and maxima pairwise over two input series. * Optional callback `cb(minVal, maxVal, i)` is invoked for each computed window. * @param minSource Input for minima * @param maxSource Input for maxima * @param period Window length (must be > 0) * @param cb Optional callback invoked per window * @returns Object with `min` and `max` Float64Array results */ export function rollminmax(minSource: ArrayLike, maxSource: ArrayLike, period: number, cb?: (minVal: number, maxVal: number, i: number) => void): { min: number[]; max: number[]; }; /** * Rolling product over a window. NaN-aware: windows with no valid entries produce NaN. * Zeros are handled efficiently by tracking counts. * @param source Input array * @param period Window length (must be > 0) * @returns Float64Array of rolling products (NaN for positions before window fills) */ export function rollprod(source: ArrayLike, period: number): number[]; /** * Rolling sum over a window with optional NaN-skipping. * If `skipna` is true, windows with no valid values produce NaN. * Supports a fast dense path when inputs contain no NaNs. * @param source Input array * @param period Window length (must be > 0) * @param skipna Whether to ignore NaNs (default: true) * @returns Float64Array of rolling sums (NaN for positions before window fills) */ export function rollsum(source: ArrayLike, period: number, skipna?: boolean): number[]; /** * Round values to nearest integer. Ties are rounded away from zero. * @param source Input array * @returns Float64Array of rounded integers */ export function round(source: ArrayLike): number[]; /** * Scale an array by a scalar: `source * s`. * @param source Input array * @param s Scale factor * @returns Float64Array scaled values */ export function scale(source: ArrayLike, s: number): number[]; /** * Element-wise sign (-1, 0, 1) for each entry. * @param source Input array * @returns Float64Array of sign values */ export function sign(source: ArrayLike): number[]; /** * Element-wise subtraction. * - If `b` is a number, returns `a - b` for each element. * - If `b` is an array, returns element-wise difference up to the shorter length. * @param a Left operand array * @param b Right operand array or scalar * @returns Float64Array of differences */ export function sub(a: ArrayLike, b: ArrayLike | number): number[]; /** * Sum of array elements with optional NaN-skipping. * When `skipna` is true (default) NaNs are ignored; returns NaN if no valid samples. * Uses a fast dense path when global optimization allows it. * @param source Input array * @param skipna Whether to ignore NaNs (default: true) * @returns Sum or NaN */ export function sum(source: ArrayLike, skipna?: boolean): number; } declare namespace ta { /** * Accumulation/Distribution (AD) line. * Computes the cumulative money flow: AD[i] = AD[i-1] + MFM[i] * volume[i], * where MFM = ((close - low) - (high - close)) / (high - low). * NaNs propagate for invalid input tuples and the accumulator only updates on finite values. * @param high High price series * @param low Low price series * @param close Close price series * @param volume Volume series * @returns Float64Array of AD values */ export function ad(high: ArrayLike, low: ArrayLike, close: ArrayLike, volume: ArrayLike): number[]; /** * Accumulation/Distribution Oscillator (ADOSC). * Computes the difference between short- and long-term EMAs of the cumulative * money flow (AD). Supports NaN-aware and dense fast-paths; outputs are NaN * until the long EMA seeding is complete. * @param high High price series * @param low Low price series * @param close Close price series * @param volume Volume series * @param shortPeriod Short EMA period * @param longPeriod Long EMA period * @param skipna Whether to ignore NaNs during computation (default: true) * @returns Float64Array of ADOSC values (NaN where undefined) */ export function adosc(high: ArrayLike, low: ArrayLike, close: ArrayLike, volume: ArrayLike, shortPeriod: number, longPeriod: number, skipna?: boolean): number[]; /** * Average Directional Index (ADX). * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of ADX values (NaN where undefined) */ export function adx(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * ADXR (Average DX Rating) - smoothed ADX. * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of ADXR values (NaN where undefined) */ export function adxr(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * Awesome Oscillator (AO): difference between short and long simple moving averages * of the median price ((high + low)/2). Supports NaN-aware and dense fast-paths. * @param high High price series * @param low Low price series * @param shortPeriod Short SMA period (default 5) * @param longPeriod Long SMA period (default 34) * @param skipna When true, ignore NaNs inside windows; false forces dense path * @returns Float64Array AO series (NaN where undefined) */ export function ao(high: ArrayLike, low: ArrayLike, shortPeriod?: number, longPeriod?: number, skipna?: boolean): number[]; /** * Absolute Price Oscillator (APO). * Computes the difference between a short and a long EMA of `src`. * Skips NaNs and seeds EMAs on the first valid value; returns NaN * for indices before both EMAs have filled. * @param src Input series * @param shortPeriod Short EMA period * @param longPeriod Long EMA period * @returns Float64Array of APO values (NaN where undefined) */ export function apo(src: ArrayLike, shortPeriod: number, longPeriod: number): number[]; /** * Aroon indicator: returns `[up, down]` arrays in percentage form (0-100) * describing the time since the highest/lowest value within the lookback * `period`. Supports NaN-aware and dense fast-paths. * @param high High price series * @param low Low price series * @param period Lookback period (>0) * @param skipna When true ignore NaNs in windows; false forces dense path * @returns Tuple `[up, down]` Float64Array indicators */ export function aroon(high: ArrayLike, low: ArrayLike, period: number, skipna?: boolean): [number[], number[]]; /** * Average True Range (ATR). * Computes ATR using Wilder's RMA over the true-range series. Handles NaNs * via the `rma` NaN-aware implementation; returns NaN for indices before the * lookback is filled. * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of ATR values */ export function atr(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * Bollinger Bands (BB). * Returns `[middle, upper, lower]` where `middle` is the SMA, and `upper`/`lower` * are `middle ± mult * stddev`. Uses a NaN-aware or dense `rollstdev` depending * on input; positions before the window fills are NaN. * @param source Input series * @param period Window length (must be > 0) * @param mult Standard-deviation multiplier * @returns Tuple `[middle, upper, lower]` as Float64Array */ export function bb(source: ArrayLike, period: number, mult: number): [number[], number[], number[]]; /** * Bollinger Band Width (BBW). * Returns the normalized width of the Bollinger Bands as percentage: `100*(upper-lower)/middle`. * NaNs propagate and positions with `middle === 0` leave the output unchanged (NaN or 0). * @param source Input series * @param period Window length * @param mult Standard-deviation multiplier used for BB * @returns Float64Array of BB width percentages */ export function bbw(source: ArrayLike, period: number, mult: number): number[]; /** * Commodity Channel Index (CCI). * Computes the typical price (TP) and compares to a moving average and * mean absolute deviation (MAD) scaled by 0.015. Positions before the * full lookback or with invalid inputs are NaN. * Performance: O(n*p) due to MAD recomputation per window. * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of CCI values (NaN where undefined) */ export function cci(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * Simple change over `period`. * Computes `src[i] - src[i-period]` for each index `i >= period`. * Outputs NaN for indices before `period` and propagates NaNs for invalid pairs. * @param src Input series * @param period Lookback period (must be > 0) * @returns Float64Array of simple change values (NaN where undefined) */ export function change(src: ArrayLike, period: number): number[]; /** * Chande Momentum Oscillator (CMO). * Computes CMO over `period` using percent scaling in [-100, 100]. * Ignores NaNs in the input deltas; positions before the first * computable value are NaN. * @param src Input series * @param period Period over which to compute the oscillator * @returns Float64Array of CMO values (NaN where undefined) */ export function cmo(src: ArrayLike, period: number): number[]; /** * Test whether series `a` crosses `b` (or a scalar) between the previous and * current index. By default uses a symmetric cross test that detects both * upward and downward crossings. Comparisons are strict and require non-NaN * current and previous values for both operands. * @param a Left series * @param b Right series or scalar * @param test Optional custom comparator receiving (ai, aim1, bi, bim1) * @returns Uint8Array mask where 1 indicates a crossing at that index */ export function cross(a: ArrayLike, b: ArrayLike | number, test?: (ai: number, aim1: number, bi: number, bim1: number) => boolean): number[]; /** * Detect an upward crossover (a crosses above b). */ export function crossover(a: ArrayLike, b: ArrayLike | number): number[]; /** * Detect a downward crossunder (a crosses below b). */ export function crossunder(a: ArrayLike, b: ArrayLike | number): number[]; /** * Double Exponential Moving Average (DEMA). * DEMA reduces lag by combining a single EMA and a double-smoothed EMA: * DEMA = 2 * EMA(source, period) - EMA(EMA(source, period), period). * Preserves NaN gaps and follows the same seeding semantics as `ema`. * @param source Input series * @param period Smoothing period (must be > 0) * @returns Float64Array of DEMA values (NaN where undefined) */ export function dema(source: ArrayLike, period: number): number[]; /** * Directional Indicators (DI+ and DI-). * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Tuple `[diplus, diminus]` as Float64Array */ export function di(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): [number[], number[]]; /** * Donchian Channels. * Returns `[upper, lower, middle]` where `upper` is the highest high * and `lower` the lowest low over the lookback `period`. `middle` is the * midpoint. NaNs propagate when inputs are invalid. * @param high High price series * @param low Low price series * @param period Lookback period (must be > 0) * @returns Tuple `[upper, lower, middle]` as Float64Array */ export function donchian(high: ArrayLike, low: ArrayLike, period: number): [number[], number[], number[]]; /** * Detrended Price Oscillator (DPO). * Computes DPO[i] = source[i - shift] - SMA(source, period)[i], where * shift = floor(period/2) + 1. Outputs are NaN for indices before the * shift or when insufficient data exists. * @param source Input series * @param period Lookback period (must be > 0) * @returns Float64Array of DPO values (NaN where undefined) */ export function dpo(source: ArrayLike, period: number): number[]; /** * DX (Directional Movement Index). * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of DX values (NaN where undefined) */ export function dx(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * Exponential Moving Average (EMA). * Seeds on the first non-NaN value and uses the standard EMA recurrence. * Preserves NaN gaps in the input: outputs are NaN until enough valid samples * have been seen to initialize the EMA. * @param source Input series * @param period Smoothing period (must be > 0) * @returns Float64Array of EMA values (NaN where undefined) */ export function ema(source: ArrayLike, period: number): number[]; /** * Falling mask: returns a Uint8Array where `1` indicates `source[i]` is * strictly less than the value `length` periods ago (NaN-aware). * When `skipna` is true, NaNs are tolerated and preserved; when false a * dense fast-path is used (assumes no NaNs). * @param source Input numeric series * @param length Lookback length (>0) * @param skipna Whether to ignore NaNs during computation (default: true) * @returns Uint8Array mask with 0/1 values */ export function falling(source: ArrayLike, length: number, skipna?: boolean): number[]; /** * Hull Moving Average (HMA). * Computes a lower-lag smoothing by combining WMAs at different lengths * and then applying a final WMA on the derived series. Pine-compatible * and NaN-aware: NaNs propagate where insufficient valid samples exist. * @param source Input series * @param period Window length (must be > 0) * @returns Float64Array of HMA values (NaN where undefined) */ export function hma(source: ArrayLike, period: number): number[]; /** * Ichimoku Kinko Hyo indicator components. * Returns `[tenkan, kijun, senkouA, senkouB, chikou]` where senkou lines * are shifted forward by the `kijun` displacement and chikou is the close * shifted backward. NaN is produced where rolling inputs are invalid. * @param high High price series * @param low Low price series * @param close Close price series * @param options Optional periods `{ tenkan, kijun, senkouB }` * @returns Tuple of Float64Array: `[tenkan, kijun, senkouA, senkouB, chikou]` */ export function ichimoku(high: ArrayLike, low: ArrayLike, close: ArrayLike, options?: IchimokuOptions): [number[], number[], number[], number[], number[]]; /** * Kaufman Adaptive Moving Average (KAMA). * Adapts smoothing based on the efficiency ratio (market noise vs direction). * This implementation supports NaN-aware and dense fast-paths; when NaNs are * present the compacting + mapping strategy is used, otherwise an O(n) * incremental volatility approach is used for speed. * @param source Input series * @param period Efficiency smoothing lookback (must be > 0) * @param fastPeriod Fast smoothing period (default: 2) * @param slowPeriod Slow smoothing period (default: 30) * @param skipna Whether to ignore NaNs (default: true) * @returns Float64Array of KAMA values (NaN where undefined) */ export function kama(source: ArrayLike, period: number, fastPeriod?: number, slowPeriod?: number, skipna?: boolean): number[]; /** * Keltner Channels. * Returns `[middle(EMA of typical price), upper, lower]` where upper/lower are `middle ± mult * ATR`. * Preserves NaNs when inputs are invalid. * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @param mult Multiplier applied to ATR * @returns Tuple `[middle, upper, lower]` as Float64Array */ export function keltner(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number, mult: number): [number[], number[], number[]]; /** * Know Sure Thing (KST) momentum oscillator. * Computes a weighted sum of smoothed rate-of-change series. * Parameters may be supplied via the `options` object or defaults are used. * The output length equals `src.length`; positions before the required * lookback periods are NaN. * @param src Input series * @param options Optional parameters for ROC and smoothing windows * @returns Float64Array of KST values (NaN where insufficient data) */ export function kst(src: ArrayLike, options?: KstOptions): number[]; /** * Moving Average Convergence Divergence (MACD). * Produces the MACD line (short EMA - long EMA), the signal line (EMA of MACD), * and the histogram (MACD - signal). Skips NaNs and seeds EMAs on first valid * value; outputs are NaN until the EMAs and signal have seeded. * @param src Input series * @param shortPeriod Short EMA period * @param longPeriod Long EMA period * @param signalPeriod Signal EMA period * @returns Tuple `[macdLine, signalLine, histogram]` as Float64Array */ export function macd(src: ArrayLike, shortPeriod: number, longPeriod: number, signalPeriod: number): [number[], number[], number[]]; /** * Money Flow Index (MFI). * Computes MFI over `period` using typical price and money flow; NaN-aware * sliding-window implementation that emits NaN where insufficient valid data exists. * @param high High price series * @param low Low price series * @param close Close price series * @param volume Volume series * @param period Lookback period (must be > 0) * @returns Float64Array of MFI values in [0,100] */ export function mfi(high: ArrayLike, low: ArrayLike, close: ArrayLike, volume: ArrayLike, period: number): number[]; /** * Momentum (difference) indicator. * Computes `src[i] - src[i - period]` for each index; positions where * the lagged value is not available are NaN. * @param src Input series * @param period Lag period (must be > 0) * @returns Float64Array of momentum values (NaN where undefined) */ export function mom(src: ArrayLike, period: number): number[]; export function natr(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; /** * On-Balance Volume (OBV). * Accumulates volume by sign of price change: add volume when price rises, * subtract when price falls; NaNs in inputs yield NaN outputs for that index. * @param price Price series * @param volume Volume series * @returns Float64Array of OBV values */ export function obv(price: ArrayLike, volume: ArrayLike): number[]; /** * Positive/Negative Volume Index (PNVI). * Returns `[pvi, nvi]` series tracking separate indices when volume increases * (PVI) or decreases (NVI). Preserves NaNs and treats zero close as missing. * @param close Close price series * @param volume Volume series * @param start Initial index value (default: 1000) * @returns Tuple `[pvi, nvi]` as Float64Array */ export function pnvi(close: ArrayLike, volume: ArrayLike, start?: number): [number[], number[]]; /** * Percentage Price Oscillator (PPO). * PPO = 100 * (EMA_short - EMA_long) / EMA_long. * Skips NaNs and seeds EMAs on first valid value; outputs are NaN until the * long EMA has enough data. When EMA_long is zero, returns 0 to avoid division. * @param src Input series * @param shortPeriod Short EMA period * @param longPeriod Long EMA period * @returns Float64Array of PPO values (NaN where undefined) */ export function ppo(src: ArrayLike, shortPeriod: number, longPeriod: number): number[]; /** * Parabolic SAR (PSAR) indicator. * @param high High price series * @param low Low price series * @param step Acceleration step increment (>0) * @param maxStep Maximum acceleration value (>= step) * @param skipna When true ignore NaNs; when false use dense fast-path * @returns Float64Array PSAR values (NaN for undefined positions) */ export function psar(high: ArrayLike, low: ArrayLike, step: number, maxStep: number, skipna?: boolean): number[]; /** * Rising mask: returns a Uint8Array where `1` indicates `source[i]` is * strictly greater than the value `length` periods ago (NaN-aware). * When `skipna` is true, NaNs are tolerated and preserved; when false a * dense fast-path is used (assumes no NaNs). * @param source Input numeric series * @param length Lookback length (>0) * @param skipna Whether to ignore NaNs during computation (default: true) * @returns Uint8Array mask with 0/1 values */ export function rising(source: ArrayLike, length: number, skipna?: boolean): number[]; /** * Wilder's Moving Average / RMA. * Implements the Wilder smoothing recurrence (rma = (rma*(period-1) + x)/period). * When `skipna` is true NaNs are ignored during seeding and updates; otherwise * a dense fast-path is used for NaN-free inputs. * @param source Input series * @param period Smoothing period (must be > 0) * @param skipna Whether to ignore NaNs during computation (default: true) * @returns Float64Array of RMA values (NaN before window fills) */ export function rma(source: ArrayLike, period: number, skipna?: boolean): number[]; /** * Percentage Rate-of-Change (ROC). * Returns 100 * (src[i] - src[i-period]) / src[i-period]. NaN is returned * for indices before `period` or when a denominator is NaN/zero. * @param src Input series * @param period Lookback period (must be > 0) * @returns Float64Array of ROC values (NaN where undefined) */ export function roc(src: ArrayLike, period: number): number[]; /** * Relative Strength Index (RSI) with optional NaN-aware behavior. * - `skipna=false` (dense path): assumes inputs contain no NaNs or that NaN * propagation is desired; uses a dense fast-path implementation. * - `skipna=true` (NaN-aware): skips NaNs when computing deltas and preserves * gaps in the output where insufficient valid data exists. * Seeding: the implementation seeds on the first valid value and uses Wilder * smoothing once the initial window is filled. * @param src Input series * @param period Lookback period for RSI (must be > 0) * @param skipna Whether to ignore NaNs during computation (default: true) * @returns Float64Array of RSI values (NaN where undefined) */ export function rsi(src: ArrayLike, period: number, skipna?: boolean): number[]; /** * Simple Moving Average (SMA). * Computes the arithmetic mean over a sliding window. * When `skipna` is true, NaNs inside the window are ignored; when false * a dense fast-path is used (assumes no NaNs). * @param source Input series * @param period Window length (must be > 0) * @param skipna Whether to ignore NaNs inside windows (default: true) * @returns Float64Array of SMA values (NaN before window fills) */ export function sma(source: ArrayLike, period: number, skipna?: boolean): number[]; /** * Stochastic oscillator (fast %K and %D smoothed outputs). * Computes fast %K based on rolling highest/lowest over `kPeriod`, then * smooths with `kSlow` and `dPeriod` using dense SMA. Assumes input series * length equality and returns NaN when insufficient data exists. * @param high High price series * @param low Low price series * @param close Close price series * @param kPeriod %K lookback period * @param kSlow Smoothing period for %K * @param dPeriod Smoothing period for %D * @returns Tuple `[slowK, slowD]` as Float64Array */ export function stoch(high: ArrayLike, low: ArrayLike, close: ArrayLike, kPeriod: number, kSlow: number, dPeriod: number): [number[], number[]]; /** * Stochastic RSI. * Applies a stochastic calculation to the RSI series, producing values in [0,1]. * This implementation is NaN-aware and maintains deques over valid RSI samples. * @param close Close price series * @param period RSI lookback period * @returns Float64Array of StochRSI values (NaN where undefined) */ export function stochrsi(close: ArrayLike, period: number): number[]; /** * Supertrend indicator. * Returns `[supertrend, finalUpper, finalLower, isUpMask]`. * `supertrend` contains the plotted trend line (either finalLower when up or finalUpper when down), * `finalUpper`/`finalLower` are the band values, and `isUpMask` is a Uint8Array mask (1 when up). * NaNs are preserved for invalid inputs or before enough data is available. * @param high High price series * @param low Low price series * @param close Close price series * @param period ATR lookback period * @param mult Multiplier applied to ATR to form bands * @returns Tuple `[supertrend, finalUpper, finalLower, isUpMask]` */ export function supertrend(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number, mult: number): [number[], number[], number[], number[]]; /** * Triple Exponential Moving Average (T3) * * T3 is a triple-smoothed moving average developed by Tim Tillson that reduces lag * and smoothing compared to traditional EMAs while maintaining responsiveness to price changes. * * @param source - Input data array * @param period - Smoothing period (default: 5) * @param volumeFactor - Volume factor for smoothing (default: 0.7) * @returns T3 values */ /** * Triple Exponential Moving Average (T3) * * Implemented following TA‑Lib's algorithm (see TA_T3 C implementation). * This inlines the nested EMA seeding (e1..e6) and performs a single-pass * update, which is significantly faster than calling `ema()` six times. * * Notes: * - Lookback = 6 * (period - 1) * - For inputs containing NaNs we propagate NaN outputs where we cannot * compute valid seeds or updates. */ export function t3(source: ArrayLike, period: number, volumeFactor: number): number[]; /** * Triple Exponential Moving Average (TEMA). * Combines three nested EMAs to reduce lag while smoothing: * TEMA = 3*EMA1 - 3*EMA2 + EMA3. Preserves NaN gaps and seeds * each EMA before emitting values. * @param source Input series * @param period Smoothing period (must be > 0) * @returns Float64Array of TEMA values (NaN where undefined) */ export function tema(source: ArrayLike, period: number): number[]; /** * True Range (TR). * TR[i] = max(high[i]-low[i], |high[i]-close[i-1]|, |low[i]-close[i-1]|). * Preserves NaNs and returns NaN where inputs are invalid. * @param high High price series * @param low Low price series * @param close Close price series * @returns Float64Array of TR values */ export function tr(high: ArrayLike, low: ArrayLike, close: ArrayLike): number[]; /** * Triangular Moving Average (TRIMA). * A triangular-weighted moving average implemented via two `sma` passes. * Preserves NaN handling by delegating to `sma` implementations. * @param source Input series * @param period Window length (must be > 0) * @returns Float64Array of TRIMA values (NaN where undefined) */ export function trima(source: ArrayLike, period: number): number[]; /** * Ultimate Oscillator (ULTOSC). * Combines short-, mid-, and long-term averages of the buying pressure / true range * to produce a bounded oscillator in [0,100]. Preserves NaN inputs and returns * NaN for indices before the longest lookback has sufficient data. * @param high High price series * @param low Low price series * @param close Close price series * @param options Optional periods for short/mid/long (s1,s2,s3) * @returns Float64Array of Ultimate Oscillator values (NaN where undefined) */ export function ultosc(high: ArrayLike, low: ArrayLike, close: ArrayLike, options?: UltoscOptions): number[]; /** * Volume Weighted Moving Average (VWMA). * Computes pvSum / vSum over a sliding window, NaN-aware. When `skipna` is * true NaNs in either series are ignored within the window; when false a * dense fast-path is used (assumes no NaNs). * @param price Price series * @param volume Volume series * @param period Window length (>0) * @param skipna Whether to ignore NaNs inside windows (default: true) * @returns Float64Array of VWMA values (NaN before window fills) */ export function vwma(price: ArrayLike, volume: ArrayLike, period: number, skipna?: boolean): number[]; /** * Williams Accumulation/Distribution (WAD). * Accumulates the money flow based on price movement using either a dense * fast-path or a NaN-aware path depending on `skipna` and input contents. * @param high High price series * @param low Low price series * @param close Close price series * @param skipna Whether to ignore NaNs (default: true) * @returns Float64Array of WAD values (NaN where undefined) */ export function wad(high: ArrayLike, low: ArrayLike, close: ArrayLike, skipna?: boolean): number[]; /** * Weighted Moving Average (WMA). * Computes a linearly-weighted average over a sliding window with weights * 1..period (oldest..newest). When `skipna` is true NaNs are ignored * within the window; when false a dense fast-path is used. * @param source Input series * @param period Window length (must be > 0) * @param skipna Whether to ignore NaNs inside windows (default: true) * @returns Float64Array of WMA values (NaN before window fills) */ export function wma(source: ArrayLike, period: number, skipna?: boolean): number[]; /** * Williams %R (WPR). * Computes %R = (highestHigh - close) / (highestHigh - lowestLow) * -100 * over a rolling `period`. Uses `rollminmax` to compute window extrema and * returns NaN for indices before `period` or when the range is zero. * @param high High price series * @param low Low price series * @param close Close price series * @param period Lookback period (must be > 0) * @returns Float64Array of %R values (NaN where undefined) */ export function wpr(high: ArrayLike, low: ArrayLike, close: ArrayLike, period: number): number[]; } declare namespace arr { } declare namespace stats { /** * Draw `k` bootstrap samples (with replacement) from `arr`. * Uses `Math.random()`; tests should stub `Math.random` for determinism. * @param arr Source array * @param k Number of draws * @returns Array of sampled elements (with replacement) */ export function bootstrap(arr: T[], k: number): T[]; /** * Pearson correlation between `x` and `y`. When `skipna` is true only * pairwise-valid entries are used; otherwise a dense fast-path is taken. * @param x First input array * @param y Second input array * @param options Optional `{ skipna? }` * @returns Correlation coefficient or NaN */ export function corr(x: ArrayLike, y: ArrayLike, skipna?: boolean): number; /** * Pairwise covariance: cov(X,Y) = E[XY] - E[X]E[Y] */ export function covar(x: ArrayLike, y: ArrayLike, options?: { ddof?: number; }): number; /** * Geometric mean (optionally weighted). Values must be positive; NaNs are * ignored when `skipna` is true. Returns NaN when no valid values. * @param source Input array * @param options Optional `{ weights?, skipna? }` * @returns Geometric mean or NaN */ export function gmean(source: ArrayLike, options?: { weights?: ArrayLike; skipna?: boolean; }): number; /** * Harmonic mean (optionally weighted). Values must be positive; NaNs are * ignored when `skipna` is true. Returns NaN when no valid values. * @param source Input array * @param options Optional `{ weights?, skipna? }` * @returns Harmonic mean or NaN */ export function hmean(source: ArrayLike, options?: { weights?: ArrayLike; skipna?: boolean; }): number; /** * Excess kurtosis (kurtosis - 3) for `source` (ignores NaNs). Returns NaN when insufficient data. * @param source Input array * @returns Excess kurtosis or NaN */ export function kurtosis(source: ArrayLike): number; /** * Mean absolute deviation from the mean. When `skipna` is true NaNs are * ignored. Returns NaN when the input contains no valid values. * @param source Input array * @param options Optional `{ skipna? }` * @returns Mean absolute deviation or NaN */ export function mad(source: ArrayLike, skipna?: boolean): number; /** * Compute the (possibly weighted) mean of `source`. * By default NaNs are skipped (`skipna=true`). When `weights` are provided they * must match `source` length and the function computes the weighted mean. * A dense fast-path is used when the global optimization allows it. * @param source Input array * @param options Optional `{ weights?, skipna? }` * @returns Mean value or NaN when undefined */ export function mean(source: ArrayLike, options?: { weights?: ArrayLike; skipna?: boolean; }): number; /** * Median of `source` (ignores NaNs). Implemented via `quantile(source, 0.5)`. * @param source Input array * @returns Median value or NaN */ export function median(source: ArrayLike): number; /** * Normalize to [0,1] by min/max scaling. Preserves NaNs when `skipna` is true. * @param source Input array * @param options Optional `{ skipna? }` * @returns Float64Array of normalized values */ export function norminmax(source: ArrayLike, skipna?: boolean): number[]; /** * Compute multiple percentiles (quantiles) for `source`. When `qs.length` * is small, selection is used for each quantile; otherwise the data are * sorted once for efficiency. * @param source Input array * @param qs Array of quantiles in [0,1] * @returns Array of quantile values */ export function percentiles(source: ArrayLike, qs: number[]): number[]; /** * Compute the quantile `q` of `source`, ignoring NaNs. Implements a * selection-based algorithm using quickselect for expected linear time. * @param source Input array * @param q Quantile in [0,1] * @returns Quantile value or NaN */ export function quantile(source: ArrayLike, q: number): number; /** * Rolling Pearson correlation computed from rolling covariance and stddev. * Supports alignment modes via `options.outLength` ('min' or 'max'). * @param x First input array * @param y Second input array * @param period Window length * @param options Optional `{ skipna?, outLength? }` * @returns Float64Array of rolling correlations */ export function rollcorr(x: ArrayLike, y: ArrayLike, period: number, options?: { skipna?: boolean; outLength?: 'min' | 'max'; }): number[]; export function rollcovar(x: ArrayLike, y: ArrayLike, period: number, options?: { ddof?: number; }): number[]; /** * Rolling excess kurtosis over a sliding window of length `period`. * @param source Input array * @param period Window length * @returns Float64Array of rolling kurtosis values */ export function rollkurtosis(source: ArrayLike, period: number): number[]; /** * Rolling mean (moving average) over a sliding window of length `period`. * When `skipna` is true, NaNs inside windows are ignored; windows with no * valid values produce NaN. A fast dense path is used when no NaNs. * @param source Input array * @param period Window length (>0) * @param skipna Whether to ignore NaNs (default: true) * @returns Float64Array of rolling means */ export function rollmean(source: ArrayLike, period: number, skipna?: boolean): number[]; /** * Compute the rolling median over a sliding window. * Ignores NaNs and validates `period`. * Returns a Float64Array with NaN entries for positions before the window fills. * @param source Input array * @param period Window length * @returns Float64Array of rolling medians */ export function rollmedian(source: ArrayLike, period: number): number[]; /** * Compute the rolling quantile over a sliding window. * Ignores NaNs and validates `period` and `q`. * Returns a Float64Array with NaN entries for positions before the window fills. * @param source Input array * @param period Window length * @param q Quantile in [0,1] * @returns Float64Array of rolling quantiles */ export function rollquantile(source: ArrayLike, period: number, q: number): number[]; /** * Rolling skewness over a sliding window of length `period`. * @param source Input array * @param period Window length * @returns Float64Array of rolling skewness values */ export function rollskew(source: ArrayLike, period: number): number[]; export function rollstdev(source: ArrayLike, period: number, options?: { skipna?: boolean; ddof?: number; }): number[]; /** * Rolling variance over a sliding window. Accepts `{ skipna?, ddof? }`. * @param source Input array * @param period Window length (>0) * @param options Optional `{ skipna?, ddof? }` * @returns Float64Array of rolling variances */ export function rollvar(source: ArrayLike, period: number, options?: { skipna?: boolean; ddof?: number; }): number[]; /** * Draw `k` unique samples without replacement from `arr`. * If `k` >= arr.length a shallow copy is returned. Uses `Math.random()`. * @param arr Source array * @param k Number of samples to draw * @returns Array of sampled elements */ export function sample(arr: T[], k: number): T[]; /** * In-place Fisher–Yates shuffle of `arr`. * Uses `Math.random()`; tests should stub `Math.random` for determinism. * @param arr Array to shuffle (mutated) * @returns The shuffled array (same reference) */ export function shuffle(arr: T[]): T[]; /** * Fisher-Pearson sample skewness (ignores NaNs). Returns NaN when insufficient data. * @param source Input array * @returns Skewness or NaN */ export function skew(source: ArrayLike): number; /** * Standard deviation: compute a single standard deviation over the whole series, dropping NaNs. * Uses `ddof` (delta degrees of freedom) like NumPy/pandas: denominator = N - ddof. * Default pandas behavior is sample standard deviation (ddof=1), so the default here is ddof=1. */ export function stdev(source: ArrayLike, options?: { ddof?: number; skipna?: boolean; }): number; /** * Variance: compute a single variance over the whole series, dropping NaNs. * Uses `ddof` (delta degrees of freedom) like NumPy/pandas: denominator = N - ddof. * Default pandas behavior is sample variance (ddof=1), so the default here is ddof=1. */ export function variance(source: ArrayLike, options?: { ddof?: number; skipna?: boolean; }): number; /** * Winsorize values to the given lower and upper quantile bounds. * Preserves NaNs when `skipna` is true. * @param source Input array * @param options Optional `{ lower?, upper?, skipna? }` where bounds are in [0,1] * @returns Float64Array of winsorized values */ export function winsorize(source: ArrayLike, options?: { lower?: number; upper?: number; skipna?: boolean; }): number[]; /** * Compute z-scores for `source`: (x - mean) / std (ddof=1). NaNs preserved. * @param source Input array * @param options Optional `{ skipna? }` to ignore NaNs * @returns Float64Array of z-scores */ export function zscore(source: ArrayLike, skipna?: boolean): number[]; } declare namespace perf { /** * Compute the compound annual growth rate (CAGR) from a returns series. * Ignores NaNs. `freq` is the number of periods per year (default 252). * @param returns Simple returns series * @param freq Periods per year (default 252) * @returns CAGR as a number, or NaN when insufficient data */ export function cagr(returns: ArrayLike, freq?: number): number; /** * Calmar ratio: CAGR over a lookback period divided by the max drawdown magnitude over the same period. * If `lookbackPeriodYears` is null uses the entire series. Returns NaN on invalid inputs or zero drawdown. * @param equity Array-like equity or price series * @param lookbackPeriodYears Lookback window in years (null = full span) * @param freq Periods per year (default 252) * @returns Calmar ratio or NaN */ export function calmar(equity: ArrayLike, lookbackPeriodYears?: number | null, freq?: number): number; /** * Compute cumulative compound returns from a returns series, skipping NaNs. * Cumulative return at i is prod_{j<=i, r_j finite} (1+r_j) - 1; NaN inputs leave an output NaN at that position. * @param returns Simple returns series * @returns Float64Array of cumulative returns */ export function cumreturns(returns: ArrayLike): number[]; /** * Aggregate irregular (event-aligned) returns into calendar-day returns. * * The function groups `returnsArr` by calendar day (optionally shifted by `tzOffsetMinutes`), * compounds returns within each day (prod(1+r)-1) and returns a continuous range of days * from the minimum to the maximum observed day. Missing days are filled with zero returns. * * @param tsMs Array of timestamps (ms since epoch) aligned to `returnsArr` * @param returnsArr Array of simple returns aligned to `tsMs` * @param tzOffsetMinutes Optional timezone offset in minutes (default 0, UTC) * @returns Object { days: number[], dailyReturns: Float32Array } */ export function dailyreturns(tsMs: ArrayLike, returnsArr: ArrayLike, tzOffsetMinutes?: number): { days: number[]; dailyReturns: number[]; }; /** * Compute the drawdown series from an equity/price series. * For valid points: out[i] = equity[i]/peak - 1 (<= 0). NaNs propagate and do not update the peak. * @param equity Array-like equity or price series * @returns Float64Array of drawdowns (same length) */ export function dd(equity: ArrayLike): number[]; /** * Compute drawdown durations (consecutive periods in current drawdown) and the maximum duration. * Positions where equity is NaN are marked with -1. * @param equity Array-like equity or price series * @returns DrawdownDurationResult { durations: Int32Array, maxDuration: number } */ export function dduration(equity: ArrayLike): DrawdownDurationResult; /** * Expected shortfall (conditional tail expectation) estimator. * Supports `historical` (empirical mean of losses <= VaR) and `parametric` (normal) methods. * Returns NaN for empty inputs, invalid alpha, or invalid parametric stats. * @param returns Array-like returns series * @param alpha Tail probability (default 0.05) * @param method 'historical' | 'parametric' (default 'historical') * @returns Expected shortfall (left-tail) or NaN */ export function expshortfall(returns: ArrayLike, alpha?: number, method?: 'historical' | 'parametric'): number; /** * Compute log returns from a level series. * For each i>0: logreturns[i] = log(source[i]/source[i-1]) when both values are finite and previous>0. * The first element is always NaN. Invalid or non-positive previous values yield NaN. * @param source Input level series (prices/equity) * @returns Float32Array of log returns (same length as `source`) */ export function logreturns(source: ArrayLike): number[]; /** * Compute the maximum drawdown magnitude over the entire series. * Returns a positive number (0..+inf) or NaN when no valid points. * @param equity Array-like equity or price series * @returns Maximum drawdown magnitude (positive) or NaN */ export function maxdd(equity: ArrayLike): number; /** * Compute detailed information about the maximum drawdown, including peak, trough, and recovery indices. * When no valid points exist returns NaN/placeholder indices (-1). * @param equity Array-like equity or price series * @returns MaxDrawdownInfo with `maxDrawdown`, `peakIndex`, `troughIndex`, `startIndex`, and `endIndex` */ export function maxddDetails(equity: ArrayLike): MaxDrawdownInfo; /** * Omega ratio: sum of gains above `requiredReturn` divided by sum of losses below it. * Returns NaN for empty inputs or when there is no variation (all gains or all losses zero). * @param returns Array-like returns series * @param requiredReturn Threshold for gains/losses (default 0) * @returns Omega ratio number, Infinity if no losses, or NaN when no variation */ export function omega(returns: ArrayLike, requiredReturn?: number): number; /** * Recovery factor: ratio of annualized return (CAGR) to maximum drawdown magnitude. * Returns NaN if insufficient data, invalid start value, or zero/NaN max drawdown. * @param equity Array-like equity or price series * @param freq Periods per year (default 252) * @returns Recovery factor or NaN */ export function recoveryfactor(equity: ArrayLike, freq?: number): number; /** * Compute simple period returns from a level series. * For each i>0: returns[i] = source[i]/source[i-1] - 1 when both values are finite and previous != 0. * The first element is always NaN. Invalid or non-finite inputs produce NaN at that position. * @param source Input level series (prices/equity) * @returns Float32Array of simple returns (same length as `source`) */ export function returns(source: ArrayLike): number[]; /** * Rolling maximum drawdown over a trailing window. * For each index i computes the max drawdown observed within the trailing window. * @param equity Array-like equity or price series * @param window Rolling window length (positive integer) * @returns Float64Array of rolling max drawdowns */ export function rollmaxdd(equity: ArrayLike, window: number): number[]; /** * Rolling Sharpe ratio computed over a trailing window. * Output is a Float64Array aligned with `returns`; positions before enough data are NaN. * @param returns Array-like returns series * @param window Rolling window length * @param riskFree Annualized risk-free rate (default 0) * @param freq Periods per year (default 252) * @param minPeriod Minimum number of valid samples required per window (default 1) * @returns Float64Array of rolling Sharpe ratios */ export function rollsharpe(returns: ArrayLike, window: number, riskFree?: number, freq?: number, minPeriod?: number): number[]; /** * Rolling Sortino ratio computed over a trailing window using downside deviations. * Outputs NaN where insufficient downside or invalid data exists. * @param returns Array-like returns series * @param window Rolling window length * @param requiredReturn Target return to define downside (default 0) * @param freq Periods per year (default 252) * @param minPeriod Minimum number of valid samples required per window (default 1) * @returns Float64Array of rolling Sortino ratios */ export function rollsortino(returns: ArrayLike, window: number, requiredReturn?: number, freq?: number, minPeriod?: number): number[]; /** * Rolling Ulcer Index computed over a trailing window. * Returns NaN for windows with insufficient valid samples (< minPeriod) or invalid window. * @param equity Array-like equity or price series * @param window Rolling window length (positive integer) * @param minPeriod Minimum number of valid points required in window * @returns Float64Array of rolling ulcer index values */ export function rollulcer(equity: ArrayLike, window: number, minPeriod?: number): number[]; /** * Rolling annualized volatility (sample stddev) over a trailing window. * Outputs NaN for windows with insufficient valid samples or zero/NaN sigma. * @param returns Array-like returns series * @param window Rolling window length * @param freq Periods per year (default 252) * @param minPeriod Minimum number of valid samples required per window (default 1) * @returns Float64Array of rolling volatilities */ export function rollvol(returns: ArrayLike, window: number, freq?: number, minPeriod?: number): number[]; /** * Compute the (annualized) Sharpe ratio for a returns series. * Uses NaN-aware mean and sample standard deviation (ddof=1). * Returns NaN for empty input, zero or NaN volatility, or invalid mean. * @param returns Array-like returns series * @param riskFree Annualized risk-free rate (default 0) * @param freq Periods per year (default 252) * @returns Sharpe ratio (annualized) or NaN */ export function sharpe(returns: ArrayLike, riskFree?: number, freq?: number): number; /** * Compute the (annualized) Sortino ratio for a returns series. * Uses downside deviation (sample corrected) computed over negative excess returns. * Requires at least two downside observations; returns NaN otherwise. * @param returns Array-like returns series * @param requiredReturn Target return to define downside (default 0) * @param freq Periods per year (default 252) * @param minPeriod Minimum valid periods (unused for scalar Sortino) * @returns Sortino ratio (annualized) or NaN */ export function sortino(returns: ArrayLike, requiredReturn?: number, freq?: number, minPeriod?: number): number; /** * Tail ratio: mean of upper tail divided by absolute mean of lower tail. * Returns NaN for empty inputs, invalid alpha, or when either tail has no observations or lower mean is zero. * @param returns Array-like returns series * @param alpha Tail probability (default 0.05) * @returns Tail ratio or NaN */ export function tail(returns: ArrayLike, alpha?: number): number; /** * Ulcer Index: measures depth and duration of drawdowns (root-mean-square of depths). * Returns NaN for empty input. * @param equity Array-like equity or price series * @returns Ulcer Index (>=0) or NaN */ export function ulcer(equity: ArrayLike): number; /** * Value-at-Risk (VaR) estimator. * Supports `historical` (empirical quantile) and `parametric` (normal) methods. * Returns NaN for empty inputs or invalid alpha or when parametric stats are invalid. * @param returns Array-like returns series * @param alpha Tail probability (default 0.05) * @param method 'historical' | 'parametric' (default 'historical') * @returns VaR as a number (left-tail) or NaN */ export function valueAtRisk(returns: ArrayLike, alpha?: number, method?: 'historical' | 'parametric'): number; /** * Annualized volatility (sample standard deviation) of returns. * Uses NaN-aware `stats.stdev` with ddof=1. Returns NaN for empty input or zero/NaN sigma. * @param returns Array-like returns series * @param freq Periods per year (default 252) * @returns Annualized volatility or NaN */ export function vol(returns: ArrayLike, freq?: number): number; } export { math, ta, arr, stats, perf };