QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
IncrementalStatistics Class Reference

Statistics tool based on incremental accumulation. More...

#include <incrementalstatistics.hpp>

+ Collaboration diagram for IncrementalStatistics:

Public Types

typedef Real value_type
 

Public Member Functions

 IncrementalStatistics ()
 
Inspectors
Size samples () const
 number of samples collected 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
 
Size downsideSamples () const
 number of negative samples collected More...
 
Real downsideWeightSum () const
 sum of data weights for negative samples More...
 
Real downsideVariance () const
 
Real downsideDeviation () const
 

Modifiers

typedef boost::accumulators::accumulator_set< Real, boost::accumulators::stats< boost::accumulators::tag::count, boost::accumulators::tag::min, boost::accumulators::tag::max, boost::accumulators::tag::weighted_mean, boost::accumulators::tag::weighted_variance, boost::accumulators::tag::weighted_skewness, boost::accumulators::tag::weighted_kurtosis, boost::accumulators::tag::sum_of_weights >, Realaccumulator_set
 
typedef boost::accumulators::accumulator_set< Real, boost::accumulators::stats< boost::accumulators::tag::count, boost::accumulators::tag::weighted_moment< 2 >, boost::accumulators::tag::sum_of_weights >, Realdownside_accumulator_set
 
accumulator_set acc_
 
downside_accumulator_set downsideAcc_
 
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...
 

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.

Definition at line 53 of file incrementalstatistics.hpp.

Member Typedef Documentation

◆ value_type

typedef Real value_type

Definition at line 55 of file incrementalstatistics.hpp.

◆ accumulator_set

typedef boost::accumulators::accumulator_set< Real, boost::accumulators::stats< boost::accumulators::tag::count, boost::accumulators::tag::min, boost::accumulators::tag::max, boost::accumulators::tag::weighted_mean, boost::accumulators::tag::weighted_variance, boost::accumulators::tag::weighted_skewness, boost::accumulators::tag::weighted_kurtosis, boost::accumulators::tag::sum_of_weights>, Real> accumulator_set
private

Definition at line 162 of file incrementalstatistics.hpp.

◆ downside_accumulator_set

typedef boost::accumulators::accumulator_set< Real, boost::accumulators::stats< boost::accumulators::tag::count, boost::accumulators::tag::weighted_moment<2>, boost::accumulators::tag::sum_of_weights>, Real> downside_accumulator_set
private

Definition at line 169 of file incrementalstatistics.hpp.

Constructor & Destructor Documentation

◆ IncrementalStatistics()

Definition at line 27 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ samples()

Size samples ( ) const

number of samples collected

Definition at line 31 of file incrementalstatistics.cpp.

+ Here is the caller graph for this function:

◆ weightSum()

Real weightSum ( ) const

sum of data weights

Definition at line 36 of file incrementalstatistics.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 41 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

◆ variance()

Real variance ( ) const

returns the variance, defined as

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

Definition at line 47 of file incrementalstatistics.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 56 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

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

Definition at line 60 of file incrementalstatistics.cpp.

+ Here is the call 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 64 of file incrementalstatistics.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 74 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

◆ min()

Real min ( ) const

returns the minimum sample value

Definition at line 90 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

◆ max()

Real max ( ) const

returns the maximum sample value

Definition at line 96 of file incrementalstatistics.cpp.

+ Here is the call graph for this function:

◆ downsideSamples()

Size downsideSamples ( ) const

number of negative samples collected

Definition at line 102 of file incrementalstatistics.cpp.

+ Here is the caller graph for this function:

◆ downsideWeightSum()

Real downsideWeightSum ( ) const

sum of data weights for negative samples

Definition at line 107 of file incrementalstatistics.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 112 of file incrementalstatistics.cpp.

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

◆ downsideDeviation()

Real downsideDeviation ( ) const

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

Definition at line 122 of file incrementalstatistics.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
weight must be positive or null

Definition at line 126 of file incrementalstatistics.cpp.

+ 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 136 of file incrementalstatistics.hpp.

+ Here is the call graph for this function:
+ Here is the caller 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

Precondition
weights must be positive or null

Definition at line 143 of file incrementalstatistics.hpp.

+ Here is the call graph for this function:

◆ reset()

void reset ( )

resets the data to a null set

Definition at line 134 of file incrementalstatistics.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ acc_

accumulator_set acc_
private

Definition at line 163 of file incrementalstatistics.hpp.

◆ downsideAcc_

downside_accumulator_set downsideAcc_
private

Definition at line 170 of file incrementalstatistics.hpp.