Skip to content
TotalFinance

Math · @insiderfinance/totalfinance

@insiderfinance/totalfinance/math/statistics

import { … } from '@insiderfinance/totalfinance/math/statistics'
stable-by-law (pre-1.0; not a 1.0 stability guarantee)iface 7type 1fn 20JSON ↗
iface

KurtosisOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { KurtosisOptions } from '@insiderfinance/totalfinance/math/statistics';

export interface KurtosisOptions extends StatisticsOptions {
    /** Return excess kurtosis (subtract 3). Default `true`. */
    excess?: boolean;
}
Fields, parameters and returned members (2)
Name · typeMeaning · unitRequired · default
excessboolean

Return excess kurtosis (subtract 3). Default true.

unitless by name
OptionalNo @default declared
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

MedianAbsoluteDeviationOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { MedianAbsoluteDeviationOptions } from '@insiderfinance/totalfinance/math/statistics';

// ---- robust statistics ----
export interface MedianAbsoluteDeviationOptions extends StatisticsOptions {
    /** Scale by 1.4826 for consistency with the normal stddev (default `true`). */
    scale?: boolean;
}
Fields, parameters and returned members (2)
Name · typeMeaning · unitRequired · default
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
scaleboolean

Scale by 1.4826 for consistency with the normal stddev (default true).

unitless by name
OptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

type

NanPolicy

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { NanPolicy } from '@insiderfinance/totalfinance/math/statistics';

export type NanPolicy = 'propagate' | 'omit' | 'throw';

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

PopulationOptions

#

The estimator choice alone — the whole contract of the rolling family and covarianceMatrix.

Signature
import type { PopulationOptions } from '@insiderfinance/totalfinance/math/statistics';

/** The estimator choice alone — the whole contract of the rolling family and `covarianceMatrix`. */
export interface PopulationOptions {
    /** Use the population estimator (÷n) instead of the sample estimator (÷(n-1)). */
    population?: boolean;
}
Fields, parameters and returned members (1)
Name · typeMeaning · unitRequired · default
populationboolean

Use the population estimator (÷n) instead of the sample estimator (÷(n-1)).

unitless by name
OptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

StatisticsOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { StatisticsOptions } from '@insiderfinance/totalfinance/math/statistics';

export interface StatisticsOptions {
    nanPolicy?: NanPolicy;
}
Fields, parameters and returned members (1)
Name · typeMeaning · unitRequired · default
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

TrimmedMeanOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { TrimmedMeanOptions } from '@insiderfinance/totalfinance/math/statistics';

export interface TrimmedMeanOptions extends StatisticsOptions {
    /**
     * Fraction dropped from EACH tail before averaging (default 0.1), in [0, 0.5]. At 0.5 nothing
     * but the middle remains and the result is the median; the same fallback applies whenever the
     * two trims would consume the whole sample.
     */
    fraction?: number;
}
Fields, parameters and returned members (2)
Name · typeMeaning · unitRequired · default
fractionnumber

Fraction dropped from EACH tail before averaging (default 0.1), in [0, 0.5]. At 0.5 nothing but the middle remains and the result is the median; the same fallback applies whenever the two trims would consume the whole sample.

unitless by name
OptionalNo @default declared
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

VarianceOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { VarianceOptions } from '@insiderfinance/totalfinance/math/statistics';

export interface VarianceOptions extends StatisticsOptions, PopulationOptions {
}
Fields, parameters and returned members (2)
Name · typeMeaning · unitRequired · default
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
populationboolean

Use the population estimator (÷n) instead of the sample estimator (÷(n-1)).

unitless by name
OptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

iface

WinsorizeOptions

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import type { WinsorizeOptions } from '@insiderfinance/totalfinance/math/statistics';

export interface WinsorizeOptions extends StatisticsOptions {
    /** Lower tail fraction to clip (default 0.05). */
    lower?: number;
    /** Upper tail fraction to clip (default 0.05). */
    upper?: number;
}
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
lowernumber

Lower tail fraction to clip (default 0.05).

unitless by name
OptionalNo @default declared
nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
uppernumber

Upper tail fraction to clip (default 0.05).

unitless by name
OptionalNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

correlation

#

Pearson correlation coefficient. Throws on unequal lengths.

Signature
import { correlation } from '@insiderfinance/totalfinance/math/statistics';

export declare function correlation(xs: ArrayLike<number>, ys: ArrayLike<number>, options?: StatisticsOptions): number;
Fields, parameters and returned members (4)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared
(ys)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

covariance

#

Covariance of two equal-length series (sample by default). Throws on unequal lengths.

Signature
import { covariance } from '@insiderfinance/totalfinance/math/statistics';

export declare function covariance(xs: ArrayLike<number>, ys: ArrayLike<number>, options?: VarianceOptions): number;
Fields, parameters and returned members (5)
Name · typeMeaning · unitRequired · default
(options)VarianceOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(options).populationboolean

Use the population estimator (÷n) instead of the sample estimator (÷(n-1)).

unitless by name
OptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared
(ys)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

kurtosis

#

Population kurtosis; excess (−3) by default.

Signature
import { kurtosis } from '@insiderfinance/totalfinance/math/statistics';

export declare function kurtosis(xs: ArrayLike<number>, options?: KurtosisOptions): number;
Fields, parameters and returned members (4)
Name · typeMeaning · unitRequired · default
(options)KurtosisOptions | undefined—unitless by nameOptionalNo @default declared
(options).excessboolean

Return excess kurtosis (subtract 3). Default true.

unitless by name
OptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

max

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import { max } from '@insiderfinance/totalfinance/math/statistics';

export declare function max(xs: ArrayLike<number>, options?: StatisticsOptions): number;
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

mean

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import { mean } from '@insiderfinance/totalfinance/math/statistics';

export declare function mean(xs: ArrayLike<number>, options?: StatisticsOptions): number;
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

median

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import { median } from '@insiderfinance/totalfinance/math/statistics';

export declare function median(xs: ArrayLike<number>, options?: StatisticsOptions): number;
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

medianAbsoluteDeviation

#

Median absolute deviation.

Signature
import { medianAbsoluteDeviation } from '@insiderfinance/totalfinance/math/statistics';

export declare function medianAbsoluteDeviation(xs: ArrayLike<number>, options?: MedianAbsoluteDeviationOptions): number;
Fields, parameters and returned members (4)
Name · typeMeaning · unitRequired · default
(options)MedianAbsoluteDeviationOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(options).scaleboolean

Scale by 1.4826 for consistency with the normal stddev (default true).

unitless by name
OptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

min

#

Public declaration. Read the signature and member contracts below; no additional behaviour is inferred.

Signature
import { min } from '@insiderfinance/totalfinance/math/statistics';

export declare function min(xs: ArrayLike<number>, options?: StatisticsOptions): number;
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

quantile

#

Quantile via the type-7 (linear interpolation of order statistics) method — the default used by NumPy and R. p is in [0, 1].

Signature
import { quantile } from '@insiderfinance/totalfinance/math/statistics';

export declare function quantile(xs: ArrayLike<number>, probability: number, options?: StatisticsOptions): number;
Fields, parameters and returned members (4)
Name · typeMeaning · unitRequired · default
(options)StatisticsOptions | undefined—unitless by nameOptionalNo @default declared
(options).nanPolicyNanPolicy—unitless by nameOptionalNo @default declared
(probability)number—unitless by nameRequiredNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

rollingCorrelation

#

Rolling Pearson correlation over a window. Aligned with NaN warmup.

Signature
import { rollingCorrelation } from '@insiderfinance/totalfinance/math/statistics';

export declare function rollingCorrelation(xs: ArrayLike<number>, ys: ArrayLike<number>, window: number): number[];
Fields, parameters and returned members (3)
Name · typeMeaning · unitRequired · default
(window)number—unitless by nameRequiredNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared
(ys)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

rollingCovariance

#

Rolling covariance over a window. Aligned with NaN warmup. Takes PopulationOptions for the same reason as rollingStandardDeviation.

Signature
import { rollingCovariance } from '@insiderfinance/totalfinance/math/statistics';

export declare function rollingCovariance(xs: ArrayLike<number>, ys: ArrayLike<number>, window: number, options?: PopulationOptions): number[];
Fields, parameters and returned members (5)
Name · typeMeaning · unitRequired · default
(options)PopulationOptions | undefined—unitless by nameOptionalNo @default declared
(options).populationboolean

Use the population estimator (÷n) instead of the sample estimator (÷(n-1)).

unitless by name
OptionalNo @default declared
(window)number—unitless by nameRequiredNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared
(ys)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.

fn

rollingMean

#

Rolling mean. Output length equals input; the first window-1 values are NaN. A window holding a non-finite value — or whose own sum overflows — is reported NaN, never ±Infinity (see finiteOrNaN).

Signature
import { rollingMean } from '@insiderfinance/totalfinance/math/statistics';

export declare function rollingMean(xs: ArrayLike<number>, window: number): number[];
Fields, parameters and returned members (2)
Name · typeMeaning · unitRequired · default
(window)number—unitless by nameRequiredNo @default declared
(xs)ArrayLike<number>—unitless by nameRequiredNo @default declared

Stability: stable-by-law (pre-1.0; not a 1.0 stability guarantee). Units come from declared names; “unitless by name” means the name alone does not establish a unit. See conventions and errors and warnings.