QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
histogram.hpp
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
24#ifndef quantlib_histogram_hpp
25#define quantlib_histogram_hpp
26
27#include <ql/utilities/null.hpp>
28#include <vector>
29
30namespace QuantLib {
31
33
38 class Histogram {
39 public:
41
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 }
66
68
69 Size bins() const;
70 const std::vector<Real>& breaks() const;
71 Algorithm algorithm() const;
72 bool empty() const;
74
76
77 Size counts(Size i) const;
78 Real frequency(Size i) const;
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