QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
integral.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 François du Vignaud
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#include <ql/math/integrals/integral.hpp>
21#include <ql/errors.hpp>
22
23namespace QuantLib {
24
25 Integrator::Integrator(Real absoluteAccuracy,
26 Size maxEvaluations)
27 : absoluteAccuracy_(absoluteAccuracy),
28 maxEvaluations_(maxEvaluations) {
29 QL_REQUIRE(absoluteAccuracy > QL_EPSILON,
30 std::scientific << "required tolerance (" <<
31 absoluteAccuracy << ") not allowed. It must be > " <<
33 }
34
36 absoluteAccuracy_= accuracy;
37 }
38
39 void Integrator::setMaxEvaluations(Size maxEvaluations) {
41 }
42
44 return absoluteAccuracy_;
45 }
46
48 return maxEvaluations_;
49 }
50
52 return absoluteError_;
53 }
54
56 absoluteError_ = error;
57 }
58
60 return evaluations_;
61 }
62
63 void Integrator::setNumberOfEvaluations(Size evaluations) const {
64 evaluations_ = evaluations;
65 }
66
68 evaluations_ += increase;
69 }
70
74 }
75
76 Real Integrator::operator()(const ext::function<Real (Real)>& f,
77 Real a,
78 Real b) const {
79 evaluations_ = 0;
80 if (a == b)
81 return 0.0;
82 if (b > a)
83 return integrate(f, a, b);
84 else
85 return -integrate(f, b, a);
86 }
87
88}
Real absoluteAccuracy() const
Definition: integral.cpp:43
Size numberOfEvaluations() const
Definition: integral.cpp:59
Size maxEvaluations() const
Definition: integral.cpp:47
void setMaxEvaluations(Size)
Definition: integral.cpp:39
Integrator(Real absoluteAccuracy, Size maxEvaluations)
Definition: integral.cpp:25
Real operator()(const ext::function< Real(Real)> &f, Real a, Real b) const
Definition: integral.cpp:76
void increaseNumberOfEvaluations(Size increase) const
Definition: integral.cpp:67
void setAbsoluteError(Real error) const
Definition: integral.cpp:55
Real absoluteError() const
Definition: integral.cpp:51
void setNumberOfEvaluations(Size evaluations) const
Definition: integral.cpp:63
void setAbsoluteAccuracy(Real)
Definition: integral.cpp:35
virtual Real integrate(const ext::function< Real(Real)> &f, Real a, Real b) const =0
virtual bool integrationSuccess() const
Definition: integral.cpp:71
#define QL_EPSILON
Definition: qldefines.hpp:178
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