QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
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
31namespace QuantLib {
32
34
42 public:
46 QL_DEPRECATED
48
52 QL_DEPRECATED
54
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:
73 const ext::function<Real(Real)> f_;
74 };
75
76
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
88 return w_;
89 }
90
92 return offsets_;
93 }
94}
95
96
97#endif
98
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
Abstract base forward class.
Definition: forward.hpp:66
Numerical Differentiation on arbitrarily spaced grids.
const ext::function< Real(Real)> f_
#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