QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
|
Statistics tool. More...
#include <generalstatistics.hpp>
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, Size > | expectationValue (const Func &f, const Predicate &inRange) const |
template<class Func > | |
std::pair< Real, Size > | expectationValue (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... | |
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.
typedef Real value_type |
Definition at line 48 of file generalstatistics.hpp.
Size samples | ( | ) | const |
number of samples collected
Definition at line 202 of file generalstatistics.hpp.
collected data
Definition at line 207 of file generalstatistics.hpp.
Real weightSum | ( | ) | const |
sum of data weights
Definition at line 25 of file generalstatistics.cpp.
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.
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.
Real standardDeviation | ( | ) | const |
returns the standard deviation \( \sigma \), defined as the square root of the variance.
Definition at line 211 of file generalstatistics.hpp.
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.
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.
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.
Real min | ( | ) | const |
returns the minimum sample value
Definition at line 219 of file generalstatistics.hpp.
Real max | ( | ) | const |
returns the maximum sample value
Definition at line 225 of file generalstatistics.hpp.
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.
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.
\( y \)-th percentile, defined as the value \( \bar{x} \) such that
\[ y = \frac{\sum_{x_i < \bar{x}} w_i}{ \sum_i w_i} \]
Definition at line 88 of file generalstatistics.cpp.
\( 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} \]
Definition at line 112 of file generalstatistics.cpp.
adds a datum to the set, possibly with a weight
Definition at line 232 of file generalstatistics.hpp.
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.
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.
void reset | ( | ) |
resets the data to a null set
Definition at line 238 of file generalstatistics.hpp.
void reserve | ( | Size | n | ) | const |
informs the internal storage of a planned increase in size
Definition at line 243 of file generalstatistics.hpp.
void sort | ( | ) | const |
sort the data set in increasing order
Definition at line 247 of file generalstatistics.hpp.
Definition at line 191 of file generalstatistics.hpp.
|
mutableprivate |
Definition at line 192 of file generalstatistics.hpp.