QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
twodimensionalintegral.hpp
Go to the documentation of this file.
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
20/*! \file twodimensionalintegral.hpp
21 \brief two dimensional integration
22*/
23
24#ifndef quantlib_two_dimensional_integral_2d_hpp
25#define quantlib_two_dimensional_integral_2d_hpp
26
28#include <ql/shared_ptr.hpp>
29#include <ql/functional.hpp>
30#include <utility>
31
32namespace QuantLib {
33
34 //! Integral of a two-dimensional function
35 /*! The integral of a two dimensional function\f$ f(x,y) \f$
36 * between \f$ (a_x, a_y) \f$ and \f$ (b_x, b_y) \f$
37 is calculated by means of two nested integrations
38 */
39
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
ext::function< Real(Real)> b
Maps function, bind and cref to either the boost or std implementation.
QL_REAL Real
real number
Definition: types.hpp:50
Integrators base class definition.
Definition: any.hpp:35
STL namespace.
Maps shared_ptr to either the boost or std implementation.