QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
incrementalstatistics.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6 Copyright (C) 2015 Peter Caspers
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
28#ifndef quantlib_incremental_statistics_hpp
29#define quantlib_incremental_statistics_hpp
30
31#include <ql/utilities/null.hpp>
32#include <ql/errors.hpp>
33#include <boost/accumulators/accumulators.hpp>
34#include <boost/accumulators/statistics/stats.hpp>
35#include <boost/accumulators/statistics/count.hpp>
36#include <boost/accumulators/statistics/sum.hpp>
37#include <boost/accumulators/statistics/min.hpp>
38#include <boost/accumulators/statistics/max.hpp>
39#include <boost/accumulators/statistics/weighted_mean.hpp>
40#include <boost/accumulators/statistics/weighted_variance.hpp>
41#include <boost/accumulators/statistics/weighted_skewness.hpp>
42#include <boost/accumulators/statistics/weighted_kurtosis.hpp>
43#include <boost/accumulators/statistics/weighted_moment.hpp>
44
45namespace QuantLib {
46
48
54 public:
58
59
60 Size samples() const;
61
63 Real weightSum() const;
64
68 Real mean() const;
69
74 Real variance() const;
75
79 Real standardDeviation() const;
80
85 Real errorEstimate() const;
86
92 Real skewness() const;
93
100 Real kurtosis() const;
101
103 Real min() const;
104
106 Real max() const;
107
109 Size downsideSamples() const;
110
112 Real downsideWeightSum() const;
113
120 Real downsideVariance() const;
121
125 Real downsideDeviation() const;
126
128
130
131
133 void add(Real value, Real weight = 1.0);
135 template <class DataIterator>
136 void addSequence(DataIterator begin, DataIterator end) {
137 for (;begin!=end;++begin)
138 add(*begin);
139 }
141
142 template <class DataIterator, class WeightIterator>
143 void addSequence(DataIterator begin, DataIterator end,
144 WeightIterator wbegin) {
145 for (;begin!=end;++begin,++wbegin)
146 add(*begin, *wbegin);
147 }
149 void reset();
151 private:
152 typedef boost::accumulators::accumulator_set<
153 Real,
154 boost::accumulators::stats<
155 boost::accumulators::tag::count, boost::accumulators::tag::min,
156 boost::accumulators::tag::max,
157 boost::accumulators::tag::weighted_mean,
158 boost::accumulators::tag::weighted_variance,
159 boost::accumulators::tag::weighted_skewness,
160 boost::accumulators::tag::weighted_kurtosis,
161 boost::accumulators::tag::sum_of_weights>,
164 typedef boost::accumulators::accumulator_set<
165 Real, boost::accumulators::stats<
166 boost::accumulators::tag::count,
167 boost::accumulators::tag::weighted_moment<2>,
168 boost::accumulators::tag::sum_of_weights>,
171 };
172
173}
174
175
176#endif
Statistics tool based on incremental accumulation.
Size samples() const
number of samples collected
Size downsideSamples() const
number of negative samples collected
Real weightSum() const
sum of data weights
void add(Real value, Real weight=1.0)
adds a datum to the set, possibly with a weight
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
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
void addSequence(DataIterator begin, DataIterator end)
adds a sequence of data to the set, with default weight
Real downsideWeightSum() const
sum of data weights for negative samples
void addSequence(DataIterator begin, DataIterator end, WeightIterator wbegin)
adds a sequence of data to the set, each with its weight
void reset()
resets the data to a null set
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35