QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
twodimensionalintegral.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2013 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
24#ifndef quantlib_two_dimensional_integral_2d_hpp
25#define quantlib_two_dimensional_integral_2d_hpp
26
27#include <ql/math/integrals/integral.hpp>
28#include <ql/shared_ptr.hpp>
29#include <ql/functional.hpp>
30#include <utility>
31
32namespace QuantLib {
33
35
41 public:
42 TwoDimensionalIntegral(ext::shared_ptr<Integrator> integratorX,
43 ext::shared_ptr<Integrator> integratorY)
44 : integratorX_(std::move(integratorX)), integratorY_(std::move(integratorY)) {}
45
46 Real operator()(const ext::function<Real (Real, Real)>& f,
47 const std::pair<Real, Real>& a,
48 const std::pair<Real, Real>& b) const {
49 return (*integratorX_)([&](Real x) { return g(f, x, a.second, b.second); },
50 a.first, b.first);
51 }
52
53 private:
54 Real g(const ext::function<Real (Real, Real)>& f,
55 Real x, Real a, Real b) const {
56 return (*integratorY_)([&](Real y) { return f(x, y); }, a, b);
57 }
58
59 const ext::shared_ptr<Integrator> integratorX_, integratorY_;
60 };
61}
62#endif
Integral of a two-dimensional function.
const ext::shared_ptr< Integrator > integratorY_
const ext::shared_ptr< Integrator > integratorX_
TwoDimensionalIntegral(ext::shared_ptr< Integrator > integratorX, ext::shared_ptr< Integrator > integratorY)
Real g(const ext::function< Real(Real, Real)> &f, Real x, Real a, Real b) const
Real operator()(const ext::function< Real(Real, Real)> &f, const std::pair< Real, Real > &a, const std::pair< Real, Real > &b) const
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.