QuantLib
: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
ql
methods
finitedifferences
operators
numericaldifferentiation.hpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
Copyright (C) 2015 Klaus Spanderen
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
25
#ifndef quantlib_numerical_differentiation_hpp
26
#define quantlib_numerical_differentiation_hpp
27
28
#include <ql/math/array.hpp>
29
#include <ql/functional.hpp>
30
31
namespace
QuantLib
{
32
34
41
class
NumericalDifferentiation
{
42
public
:
46
QL_DEPRECATED
47
typedef
Real
argument_type
;
48
52
QL_DEPRECATED
53
typedef
Real
result_type
;
54
55
enum
Scheme
{
Central
,
Backward
,
Forward
};
56
57
NumericalDifferentiation
(ext::function<
Real
(
Real
)> f,
58
Size
orderOfDerivative,
59
Array
x_offsets);
60
61
NumericalDifferentiation
(ext::function<
Real
(
Real
)> f,
62
Size
orderOfDerivative,
63
Real
stepSize,
64
Size
steps,
65
Scheme
scheme);
66
67
Real
operator()
(
Real
x)
const
;
68
const
Array
&
offsets
()
const
;
69
const
Array
&
weights
()
const
;
70
71
private
:
72
const
Array
offsets_
,
w_
;
73
const
ext::function<
Real
(
Real
)>
f_
;
74
};
75
76
77
inline
Real
NumericalDifferentiation::operator()
(
Real
x)
const
{
78
Real
s = 0.0;
79
for
(
Size
i=0; i <
w_
.
size
(); ++i) {
80
if
(std::fabs(
w_
[i]) >
QL_EPSILON
*
QL_EPSILON
) {
81
s +=
w_
[i] *
f_
(x+
offsets_
[i]);
82
}
83
}
84
return
s;
85
}
86
87
inline
const
Array
&
NumericalDifferentiation::weights
()
const
{
88
return
w_
;
89
}
90
91
inline
const
Array
&
NumericalDifferentiation::offsets
()
const
{
92
return
offsets_
;
93
}
94
}
95
96
97
#endif
98
QuantLib::Array
1-D array used in linear algebra.
Definition:
array.hpp:52
QuantLib::Array::size
Size size() const
dimension of the array
Definition:
array.hpp:495
QuantLib::Forward
Abstract base forward class.
Definition:
forward.hpp:66
QuantLib::NumericalDifferentiation
Numerical Differentiation on arbitrarily spaced grids.
Definition:
numericaldifferentiation.hpp:41
QuantLib::NumericalDifferentiation::operator()
Real operator()(Real x) const
Definition:
numericaldifferentiation.hpp:77
QuantLib::NumericalDifferentiation::Scheme
Scheme
Definition:
numericaldifferentiation.hpp:55
QuantLib::NumericalDifferentiation::Backward
@ Backward
Definition:
numericaldifferentiation.hpp:55
QuantLib::NumericalDifferentiation::Central
@ Central
Definition:
numericaldifferentiation.hpp:55
QuantLib::NumericalDifferentiation::offsets
const Array & offsets() const
Definition:
numericaldifferentiation.hpp:91
QuantLib::NumericalDifferentiation::w_
const Array w_
Definition:
numericaldifferentiation.hpp:72
QuantLib::NumericalDifferentiation::offsets_
const Array offsets_
Definition:
numericaldifferentiation.hpp:72
QuantLib::NumericalDifferentiation::argument_type
QL_DEPRECATED typedef Real argument_type
Definition:
numericaldifferentiation.hpp:47
QuantLib::NumericalDifferentiation::result_type
QL_DEPRECATED typedef Real result_type
Definition:
numericaldifferentiation.hpp:53
QuantLib::NumericalDifferentiation::weights
const Array & weights() const
Definition:
numericaldifferentiation.hpp:87
QuantLib::NumericalDifferentiation::f_
const ext::function< Real(Real)> f_
Definition:
numericaldifferentiation.hpp:73
QL_EPSILON
#define QL_EPSILON
Definition:
qldefines.hpp:178
QuantLib::Real
QL_REAL Real
real number
Definition:
types.hpp:50
QuantLib::Size
std::size_t Size
size of a container
Definition:
types.hpp:58
QuantLib
Definition:
any.hpp:35
Generated by
Doxygen
1.9.5