1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2013, 2022 Klaus Spanderen
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<https://www.quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#ifndef quantlib_segment_integral_i
#define quantlib_segment_integral_i
%include common.i
%include types.i
%include functions.i
%{
using QuantLib::SegmentIntegral;
using QuantLib::TrapezoidIntegral;
using QuantLib::Default;
using QuantLib::MidPoint;
using QuantLib::SimpsonIntegral;
using QuantLib::GaussKronrodAdaptive;
using QuantLib::GaussKronrodNonAdaptive;
using QuantLib::GaussLobattoIntegral;
using QuantLib::GaussLaguerreIntegration;
using QuantLib::GaussHermiteIntegration;
using QuantLib::GaussJacobiIntegration;
using QuantLib::GaussHyperbolicIntegration;
using QuantLib::GaussLegendreIntegration;
using QuantLib::GaussChebyshevIntegration;
using QuantLib::GaussChebyshev2ndIntegration;
using QuantLib::GaussGegenbauerIntegration;
using QuantLib::TanhSinhIntegral;
using QuantLib::ExpSinhIntegral;
%}
%define INTEGRATION_METHODS
Size numberOfEvaluations() const;
%extend {
#if defined(SWIGPYTHON)
Real __call__(PyObject* pyFunction, Real a, Real b) {
UnaryFunction f(pyFunction);
return (*self)(f, a, b);
}
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
Real calculate(UnaryFunctionDelegate* f, Real a, Real b) {
return (*self)(UnaryFunction(f), a, b);
}
#endif
}
%enddef
class SegmentIntegral {
public:
SegmentIntegral(Size intervals);
INTEGRATION_METHODS;
};
template <class IntegrationPolicy>
class TrapezoidIntegral {
public:
TrapezoidIntegral(Real accuracy, Size maxIterations);
INTEGRATION_METHODS;
};
%template(TrapezoidIntegralDefault) TrapezoidIntegral<Default>;
%template(TrapezoidIntegralMidPoint) TrapezoidIntegral<MidPoint>;
class SimpsonIntegral {
public:
SimpsonIntegral(Real accuracy, Size maxIterations);
INTEGRATION_METHODS;
};
class GaussKronrodAdaptive {
public:
GaussKronrodAdaptive(Real tolerance,
Size maxFunctionEvaluations = Null<Size>());
INTEGRATION_METHODS;
};
class GaussKronrodNonAdaptive {
public:
GaussKronrodNonAdaptive(Real absoluteAccuracy,
Size maxEvaluations,
Real relativeAccuracy);
INTEGRATION_METHODS;
};
class GaussLobattoIntegral {
public:
GaussLobattoIntegral(Size maxIterations,
Real absAccuracy,
Real relAccuracy = Null<Real>(),
bool useConvergenceEstimate = true);
INTEGRATION_METHODS;
};
%{
using QuantLib::GaussianQuadrature;
%}
class GaussianQuadrature {
private:
GaussianQuadrature();
public:
Size order() const;
%extend {
Array weights() {
return self->weights();
}
Array x() {
return self->x();
}
#if defined(SWIGPYTHON)
Real __call__(PyObject* pyFunction) {
UnaryFunction f(pyFunction);
return (*self)(f);
}
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
Real calculate(UnaryFunctionDelegate* f) {
return (*self)(UnaryFunction(f));
}
#endif
}
};
class GaussLaguerreIntegration: public GaussianQuadrature {
public:
GaussLaguerreIntegration(Size n, Real s = 0.0);
};
class GaussHermiteIntegration: public GaussianQuadrature {
public:
GaussHermiteIntegration(Size n, Real mu = 0.0);
};
class GaussJacobiIntegration: public GaussianQuadrature {
public:
GaussJacobiIntegration(Size n, Real alpha, Real beta);
};
class GaussHyperbolicIntegration: public GaussianQuadrature {
public:
GaussHyperbolicIntegration(Size n);
};
class GaussLegendreIntegration: public GaussianQuadrature {
public:
GaussLegendreIntegration(Size n);
};
class GaussChebyshevIntegration: public GaussianQuadrature {
public:
GaussChebyshevIntegration(Size n);
};
class GaussChebyshev2ndIntegration: public GaussianQuadrature {
public:
GaussChebyshev2ndIntegration(Size n);
};
class GaussGegenbauerIntegration: public GaussianQuadrature {
public:
GaussGegenbauerIntegration(Size n, Real lambda);
};
class TanhSinhIntegral {
public:
explicit TanhSinhIntegral(
Real relTolerance = std::sqrt(std::numeric_limits<Real>::epsilon()),
Size maxRefinements = 15,
Real minComplement = std::numeric_limits<Real>::min() * 4
);
INTEGRATION_METHODS;
};
class ExpSinhIntegral {
public:
explicit ExpSinhIntegral(
Real relTolerance = std::sqrt(std::numeric_limits<Real>::epsilon()),
Size maxRefinements = 9
);
%extend {
#if defined(SWIGPYTHON)
Real integrate(PyObject* pyFunction) {
UnaryFunction f(pyFunction);
return self->integrate(f);
}
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
Real integrate(UnaryFunctionDelegate* f) {
return self->integrate(UnaryFunction(f));
}
#endif
}
INTEGRATION_METHODS;
};
#endif
|