QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
histogram.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Gang Liang
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file histogram.hpp
21 \brief statistics tool for generating histogram of given data
22*/
23
24#ifndef quantlib_histogram_hpp
25#define quantlib_histogram_hpp
26
27#include <ql/utilities/null.hpp>
28#include <vector>
29
30namespace QuantLib {
31
32 //! Histogram class
33 /*! This class computes the histogram of a given data set. The
34 caller can specify the number of bins, the breaks, or the
35 algorithm for determining these quantities in computing the
36 histogram.
37 */
38 class Histogram {
39 public:
41
42 //! \name constructors
43 //@{
45
46 template <class T>
47 Histogram(T data_begin, T data_end, Size breaks)
48 : data_(data_begin, data_end), bins_(breaks + 1) {
49 calculate();
50 }
51
52 template <class T>
53 Histogram(T data_begin, T data_end, Algorithm algorithm)
54 : data_(data_begin,data_end), bins_(Null<Size>()),
56 calculate();
57 }
58
59 template <class T, class U>
60 Histogram(T data_begin, T data_end, U breaks_begin, U breaks_end)
61 : data_(data_begin, data_end), bins_(Null<Size>()), breaks_(breaks_begin, breaks_end) {
62 bins_ = breaks_.size()+1;
63 calculate();
64 }
65 //@}
66
67 //! \name inspectors
68 //@{
69 Size bins() const;
70 const std::vector<Real>& breaks() const;
71 Algorithm algorithm() const;
72 bool empty() const;
73 //@}
74
75 //! \name results
76 //@{
77 Size counts(Size i) const;
78 Real frequency(Size i) const;
79 //@}
80 private:
81 std::vector<Real> data_;
84 std::vector<Real> breaks_;
85 std::vector<Size> counts_;
86 std::vector<Real> frequency_;
87 // update counts and frequencies
88 void calculate();
89 };
90
91}
92
93#endif
Histogram class.
Definition: histogram.hpp:38
Size bins() const
Definition: histogram.cpp:67
std::vector< Real > breaks_
Definition: histogram.hpp:84
Algorithm algorithm_
Definition: histogram.hpp:83
Histogram(T data_begin, T data_end, Algorithm algorithm)
Definition: histogram.hpp:53
std::vector< Real > frequency_
Definition: histogram.hpp:86
std::vector< Size > counts_
Definition: histogram.hpp:85
Algorithm algorithm() const
Definition: histogram.cpp:75
bool empty() const
Definition: histogram.cpp:79
Real frequency(Size i) const
Definition: histogram.cpp:91
Histogram(T data_begin, T data_end, U breaks_begin, U breaks_end)
Definition: histogram.hpp:60
Size counts(Size i) const
Definition: histogram.cpp:83
const std::vector< Real > & breaks() const
Definition: histogram.cpp:71
Histogram(T data_begin, T data_end, Size breaks)
Definition: histogram.hpp:47
std::vector< Real > data_
Definition: histogram.hpp:81
template class providing a null value for a given type.
Definition: null.hpp:76
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
null values