QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
GeneralStatistics Class Reference

Statistics tool. More...

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

+ Collaboration diagram for GeneralStatistics:

Public Types

typedef Real value_type
 

Public Member Functions

 GeneralStatistics ()
 
Inspectors
Size samples () const
 number of samples collected More...
 
const std::vector< std::pair< Real, Real > > & data () const
 collected data More...
 
Real weightSum () const
 sum of data weights More...
 
Real mean () const
 
Real variance () const
 
Real standardDeviation () const
 
Real errorEstimate () const
 
Real skewness () const
 
Real kurtosis () const
 
Real min () const
 
Real max () const
 
template<class Func , class Predicate >
std::pair< Real, SizeexpectationValue (const Func &f, const Predicate &inRange) const
 
template<class Func >
std::pair< Real, SizeexpectationValue (const Func &f) const
 
Real percentile (Real y) const
 
Real topPercentile (Real y) const
 

Modifiers

std::vector< std::pair< Real, Real > > samples_
 
bool sorted_
 
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 More...
 
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 More...
 
void reserve (Size n) const
 informs the internal storage of a planned increase in size More...
 
void sort () const
 sort the data set in increasing order More...
 

Detailed Description

Statistics tool.

This class accumulates a set of data and returns their statistics (e.g: mean, variance, skewness, kurtosis, error estimation, percentile, etc.) based on the empirical distribution (no gaussian assumption)

It doesn't suffer the numerical instability problem of IncrementalStatistics. The downside is that it stores all samples, thus increasing the memory requirements.

Definition at line 46 of file generalstatistics.hpp.

Member Typedef Documentation

◆ value_type

typedef Real value_type

Definition at line 48 of file generalstatistics.hpp.

Constructor & Destructor Documentation

◆ GeneralStatistics()

Definition at line 198 of file generalstatistics.hpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ samples()

Size samples ( ) const

number of samples collected

Definition at line 202 of file generalstatistics.hpp.

+ Here is the caller graph for this function:

◆ data()

const std::vector< std::pair< Real, Real > > & data ( ) const

collected data

Definition at line 207 of file generalstatistics.hpp.

◆ weightSum()

Real weightSum ( ) const

sum of data weights

Definition at line 25 of file generalstatistics.cpp.

+ Here is the caller graph for this function:

◆ mean()

Real mean ( ) const

returns the mean, defined as

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

Definition at line 34 of file generalstatistics.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variance()

Real variance ( ) const

returns the variance, defined as

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

Definition at line 40 of file generalstatistics.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ standardDeviation()

Real standardDeviation ( ) const

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

Definition at line 211 of file generalstatistics.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorEstimate()

Real errorEstimate ( ) const

returns the error estimate on the mean value, defined as \( \epsilon = \sigma/\sqrt{N}. \)

Definition at line 215 of file generalstatistics.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Definition at line 54 of file generalstatistics.cpp.

+ Here is the call graph for this function:

◆ 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.

Definition at line 69 of file generalstatistics.cpp.

+ Here is the call graph for this function:

◆ min()

Real min ( ) const

returns the minimum sample value

Definition at line 219 of file generalstatistics.hpp.

+ Here is the call graph for this function:

◆ max()

Real max ( ) const

returns the maximum sample value

Definition at line 225 of file generalstatistics.hpp.

+ Here is the call graph for this function:

◆ expectationValue() [1/2]

std::pair< Real, Size > expectationValue ( const Func &  f,
const Predicate &  inRange 
) const

Expectation value of a function \( f \) on a given range \( \mathcal{R} \), i.e.,

\[ \mathrm{E}\left[f \;|\; \mathcal{R}\right] = \frac{\sum_{x_i \in \mathcal{R}} f(x_i) w_i}{ \sum_{x_i \in \mathcal{R}} w_i}. \]

The range is passed as a boolean function returning true if the argument belongs to the range or false otherwise.

The function returns a pair made of the result and the number of observations in the given range.

Definition at line 116 of file generalstatistics.hpp.

+ Here is the caller graph for this function:

◆ expectationValue() [2/2]

std::pair< Real, Size > expectationValue ( const Func &  f) const

Expectation value of a function \( f \) over the whole set of samples; equivalent to passing the other overload a range function always returning true.

Definition at line 140 of file generalstatistics.hpp.

+ Here is the call graph for this function:

◆ percentile()

Real percentile ( Real  y) const

\( y \)-th percentile, defined as the value \( \bar{x} \) such that

\[ y = \frac{\sum_{x_i < \bar{x}} w_i}{ \sum_i w_i} \]

Precondition
\( y \) must be in the range \( (0-1]. \)

Definition at line 88 of file generalstatistics.cpp.

+ Here is the call graph for this function:

◆ topPercentile()

Real topPercentile ( Real  y) const

\( y \)-th top percentile, defined as the value \( \bar{x} \) such that

\[ y = \frac{\sum_{x_i > \bar{x}} w_i}{ \sum_i w_i} \]

Precondition
\( y \) must be in the range \( (0-1]. \)

Definition at line 112 of file generalstatistics.cpp.

+ Here is the call graph for this function:

◆ add()

void add ( Real  value,
Real  weight = 1.0 
)

adds a datum to the set, possibly with a weight

Precondition
weights must be positive or null

Definition at line 232 of file generalstatistics.hpp.

+ Here is the caller graph for this function:

◆ addSequence() [1/2]

void addSequence ( DataIterator  begin,
DataIterator  end 
)

adds a sequence of data to the set, with default weight

Definition at line 169 of file generalstatistics.hpp.

+ Here is the call graph for this function:

◆ addSequence() [2/2]

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

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

Definition at line 175 of file generalstatistics.hpp.

+ Here is the call graph for this function:

◆ reset()

void reset ( )

resets the data to a null set

Definition at line 238 of file generalstatistics.hpp.

+ Here is the caller graph for this function:

◆ reserve()

void reserve ( Size  n) const

informs the internal storage of a planned increase in size

Definition at line 243 of file generalstatistics.hpp.

◆ sort()

void sort ( ) const

sort the data set in increasing order

Definition at line 247 of file generalstatistics.hpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ samples_

std::vector<std::pair<Real,Real> > samples_
mutableprivate

Definition at line 191 of file generalstatistics.hpp.

◆ sorted_

bool sorted_
mutableprivate

Definition at line 192 of file generalstatistics.hpp.