QuantLib
A free/open-source library for quantitative finance
Reference manual - version 1.20
Public Types | List of all members
IncrementalStatistics Class Reference

Statistics tool based on incremental accumulation. More...

#include <ql/math/statistics/incrementalstatistics.hpp>

Public Types

typedef Real value_type
 

Public Member Functions

Inspectors
Size samples () const
 number of samples collected
 
Real weightSum () const
 sum of data weights
 
Real mean () const
 
Real variance () const
 
Real standardDeviation () const
 
Real errorEstimate () const
 
Real skewness () const
 
Real kurtosis () const
 
Real min () const
 
Real max () const
 
Size downsideSamples () const
 number of negative samples collected
 
Real downsideWeightSum () const
 sum of data weights for negative samples
 
Real downsideVariance () const
 
Real downsideDeviation () const
 

Modifiers

void add (Real value, Real weight=1.0)
 adds a datum to the set, possibly with a weight More...
 
template<class DataIterator >
void addSequence (DataIterator begin, DataIterator end)
 adds a sequence of data to the set, with default weight
 
template<class DataIterator , class WeightIterator >
void addSequence (DataIterator begin, DataIterator end, WeightIterator wbegin)
 adds a sequence of data to the set, each with its weight More...
 
void reset ()
 resets the data to a null set
 

Detailed Description

Statistics tool based on incremental accumulation.

It can accumulate a set of data and return statistics (e.g: mean, variance, skewness, kurtosis, error estimation, etc.). This class is a wrapper to the boost accumulator library.

Member Function Documentation

◆ mean()

Real mean ( ) const

returns the mean, defined as

\[ \langle x \rangle = \frac{\sum w_i x_i}{\sum w_i}. \]

◆ variance()

Real variance ( ) const

returns the variance, defined as

\[ \frac{N}{N-1} \left\langle \left( x-\langle x \rangle \right)^2 \right\rangle. \]

◆ standardDeviation()

Real standardDeviation ( ) const

returns the standard deviation \( \sigma \), defined as the square root of the variance.

◆ errorEstimate()

Real errorEstimate ( ) const

returns the error estimate \( \epsilon \), defined as the square root of the ratio of the variance to the number of samples.

◆ skewness()

Real skewness ( ) const

returns the skewness, defined as

\[ \frac{N^2}{(N-1)(N-2)} \frac{\left\langle \left( x-\langle x \rangle \right)^3 \right\rangle}{\sigma^3}. \]

The above evaluates to 0 for a Gaussian distribution.

◆ kurtosis()

Real kurtosis ( ) const

returns the excess kurtosis, defined as

\[ \frac{N^2(N+1)}{(N-1)(N-2)(N-3)} \frac{\left\langle \left(x-\langle x \rangle \right)^4 \right\rangle}{\sigma^4} - \frac{3(N-1)^2}{(N-2)(N-3)}. \]

The above evaluates to 0 for a Gaussian distribution.

◆ min()

Real min ( ) const

returns the minimum sample value

◆ max()

Real max ( ) const

returns the maximum sample value

◆ downsideVariance()

Real downsideVariance ( ) const

returns the downside variance, defined as

\[ \frac{N}{N-1} \times \frac{ \sum_{i=1}^{N} \theta \times x_i^{2}}{ \sum_{i=1}^{N} w_i} \]

, where \( \theta \) = 0 if x > 0 and \( \theta \) =1 if x <0

◆ downsideDeviation()

Real downsideDeviation ( ) const

returns the downside deviation, defined as the square root of the downside variance.

◆ add()

void add ( Real  value,
Real  weight = 1.0 
)

adds a datum to the set, possibly with a weight

Precondition
weight must be positive or null

◆ addSequence()

void addSequence ( DataIterator  begin,
DataIterator  end,
WeightIterator  wbegin 
)

adds a sequence of data to the set, each with its weight

Precondition
weights must be positive or null