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
//! Convergence-controlled quadrature for characteristic-function inversion.
//!
//! The Heston, Gil-Pelaez, Lewis and Carr-Madan pricers all invert a
//! characteristic function by integrating an oscillatory-but-decaying integrand
//! over `[a, ∞)`. The integrand's envelope only becomes negligible once `φ` is
//! past its decay length, which grows like `1/√(v·τ)` as the maturity `τ` or
//! the variance `v` shrink. A hardcoded finite upper limit therefore truncates
//! a non-negligible tail for short-dated or low-variance options, which
//! under-prices them by 15-35% and can even return arbitrage-violating negative
//! call prices.
//!
//! [`integrate_to_convergence`] replaces the fixed bound: it accumulates
//! tanh-sinh panels of geometrically growing width and stops once the tail
//! contribution is negligible, so the effective upper limit adapts to the
//! actual decay length for any `(τ, v, moneyness)`.
use double_exponential;
/// Integrate `f` over `[a, ∞)` to a relative tolerance `tol`.
///
/// Successive tanh-sinh panels of geometrically growing width are summed until
/// two consecutive panels each add less than `tol` relative to the running
/// integral. `tol` is also the per-panel tanh-sinh target. Requiring two
/// negligible panels (not one) guards against a panel that integrates to near
/// zero by oscillatory cancellation while the envelope is still significant.
pub