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 Descriptive Statistics

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


Knowledge Sources
Domains Mathematics, Statistics
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for computing descriptive statistics on vectors of floating point numbers provided by the RustQuant library.

Description

The Statistic trait defines a comprehensive set of descriptive statistical functions for vectors of floating point numbers. It is implemented for Vec<f64> and provides methods organized into several categories:

Mean functions:

  • mean() -- wrapper for arithmetic_mean.
  • arithmetic_mean() -- sum of elements divided by count.
  • geometric_mean() -- nth root of the product of elements.
  • harmonic_mean() -- reciprocal of the arithmetic mean of reciprocals.

Variance and standard deviation:

  • variance() / sample_variance() -- uses Bessel's correction (divides by n-1).
  • population_variance() -- divides by n.
  • standard_deviation() / sample_standard_deviation() -- square root of sample variance.
  • population_standard_deviation() -- square root of population variance.

Bivariate statistics:

  • covariance(other) -- sample covariance between two vectors.
  • correlation(other) -- Pearson correlation coefficient.

Shape statistics:

  • skewness() -- adjusted Fisher-Pearson standardized moment coefficient.
  • kurtosis() -- excess kurtosis with bias correction.

Order statistics:

  • min(), max() -- extreme values.
  • median() -- middle value of sorted data.
  • percentile(p), quantile(q) -- interpolated order statistics (p, q in [0, 1]).
  • interquartile_range() -- Q3 - Q1.
  • range() -- max - min.

All methods include assertions for minimum vector length requirements (e.g., mean requires at least 1 element, standard deviation requires at least 2, skewness requires at least 3, kurtosis requires at least 4).

Usage

Use this trait whenever you need to compute summary statistics on a vector of numeric data. In quantitative finance, descriptive statistics are fundamental for analyzing return distributions, computing risk metrics, performing portfolio analysis, and evaluating the statistical properties of time series data.

Code Reference

Source Location

Signature

pub trait Statistic<T: Float> {
    fn mean(&self) -> T;
    fn arithmetic_mean(&self) -> T;
    fn geometric_mean(&self) -> T;
    fn harmonic_mean(&self) -> T;
    fn variance(&self) -> T;
    fn sample_variance(&self) -> f64;
    fn population_variance(&self) -> f64;
    fn standard_deviation(&self) -> T;
    fn sample_standard_deviation(&self) -> f64;
    fn population_standard_deviation(&self) -> f64;
    fn covariance(&self, other: &Self) -> T;
    fn correlation(&self, other: &Self) -> T;
    fn skewness(&self) -> T;
    fn kurtosis(&self) -> T;
    fn min(&self) -> T;
    fn max(&self) -> T;
    fn median(&self) -> T;
    fn percentile(&self, percentile: f64) -> T;
    fn quantile(&self, quantile: f64) -> T;
    fn interquartile_range(&self) -> T;
    fn range(&self) -> T;
}

impl Statistic<f64> for Vec<f64> { /* ... */ }

Import

use RustQuant::math::Statistic;

I/O Contract

Inputs

Name Type Required Description
self &Vec<f64> Yes The vector of data to compute statistics on. Must not be empty.
other &Vec<f64> For covariance/correlation A second vector of equal length for bivariate statistics.
percentile f64 For percentile() Value in [0, 1] specifying the desired percentile.
quantile f64 For quantile() Value in [0, 1] specifying the desired quantile.

Outputs

Name Type Description
mean() f64 Arithmetic mean of the vector elements.
variance() f64 Sample variance (Bessel-corrected).
standard_deviation() f64 Sample standard deviation.
covariance() f64 Sample covariance between two vectors.
correlation() f64 Pearson correlation coefficient in [-1, 1].
skewness() f64 Adjusted skewness of the distribution.
kurtosis() f64 Excess kurtosis of the distribution.
median() f64 Median value of the sorted data.

Usage Examples

use RustQuant::math::Statistic;

let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];

// Central tendency
let mean = data.arithmetic_mean();     // 3.0
let geo = data.geometric_mean();       // ~2.605
let harm = data.harmonic_mean();       // ~2.190
let med = data.median();               // 3.0

// Dispersion
let var = data.variance();             // 2.5 (sample variance)
let pop_var = data.population_variance(); // 2.0
let sd = data.standard_deviation();    // ~1.581

// Order statistics
let mn = data.min();                   // 1.0
let mx = data.max();                   // 5.0
let rng = data.range();               // 4.0
let iqr = data.interquartile_range();  // Q3 - Q1
let p50 = data.percentile(0.5);       // median

// Bivariate statistics
let x = vec![2.1, 2.5, 4.0, 3.6];
let y = vec![8.0, 10.0, 12.0, 14.0];
let cov = x.covariance(&y);           // 2.0
let corr = x.correlation(&y);         // ~0.864

Related Pages

Page Connections

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