Reference Every exported name

API reference

Methods

FinancialFFT.LewisMethod — Type
LewisMethod(A, N; mode = SerialMode())
LewisMethod(ε; N_max = 2^20 + 1, mode = SerialMode())

Direct quadrature of the Lewis (2001) formula along the line Im(u) = 1/2: the integrand is evaluated on N equally spaced nodes in [-A, A] and summed. No FFT and no interpolation are involved, so every strike is priced exactly on its own and dual numbers, hyper-dual numbers, TaylorSeries, ForwardDiff, ReverseDiff, Zygote and Mooncake are supported.

With a tolerance ε (a float), A and N are chosen at pricing time, for the model, the maturity and the strikes, so that the price error stays below ε; both come from the characteristic exponent:

  • A (truncation): the tail beyond A of the modulus of the integrand, |φ(v - i/2)| times the Lewis weights, integrated numerically at the parameters of the model, gets ε / 2. It is an estimate (a quadrature of the modulus on [1e-3, 1e6]), not a rigorous bound.
  • the step 2A / (N - 1) (aliasing): the quadrature adds copies of the price at log-strike distances that are multiples of L = 2π (N - 1) / (2A); for vanilla options they are bounded in closed form (no model), for binaries one side needs a Chernoff bound, i.e. the moment generating function E[exp(p X_T)] at real p. Each side gets ε / 4.

The choice evaluates the exponent 2048 times, about one and a half prices with the grid it picks (a Black–Scholes smile: 90 μs against 60 μs); for repeated pricing (a calibration), resolve it once with FinancialFFT.quadrature_grid and pass LewisMethod(A, N). The bounds do not cover the rounding: ε must stay above the floor of the formula, about eps() * max(S0, K) (#40, #99).

Arguments

  • A: half-width of the frequency integration domain (A > 0).
  • N: number of quadrature nodes (N > 2).
  • ε: the price tolerance, an AbstractFloat (ε > 0): an integer argument is never read as a tolerance.
  • N_max (keyword): the largest number of nodes the tolerance may ask for; more throws an ArgumentError.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source
FinancialFFT.CosMethod — Type
CosMethod(N; mode = SerialMode())
CosMethod(ε; N_max = 2^20, mode = SerialMode())

Fourier-cosine expansion method of Fang & Oosterlee (2008). The density of the log-price is expanded on a truncation interval [a, b] with the cosine terms k = 0, …, N; the interval is computed from a Chernoff bound on the tails of the process (see Truncation range), so no range parameter is needed. The expansion is on the put, and calls follow from parity: a call needs no information on the right tail of the process.

With a tolerance ε (a float), the number of terms (and, for a very small ε, the tail probability of the range) is chosen at pricing time, for the model, the maturity and the strikes, so that the price error stays below ε; both come from the characteristic function φ:

  • the range: the mass outside it, weighted by the cosine coefficients of the put, gets ε / 2; the tail probability is never above the 1e-14 of the fixed form, which the derivatives need (see Truncation range).
  • N (series truncation): the terms beyond N are below |φ(u_k)| times an envelope of the cosine coefficients of the put (decaying like 1 / u², like 1 / u for a binary), at the frequencies u_k = k π / (b - a). Their sum is estimated by the integral of this product beyond u_N (at the parameters of the model, an estimate rather than a rigorous bound) and gets ε / 2. A wide range (heavy tails, such as Kou with rare up jumps) or a slowly decaying φ (a short maturity, a small variance) asks for more terms.

The choice costs about one price; for repeated pricing resolve it once with FinancialFFT.cos_range_and_terms and pass CosMethod(N). The bounds do not cover the rounding: ε must stay above the floor of the formula.

Arguments

  • N: number of cosine terms (N > 2).
  • ε: the price tolerance, an AbstractFloat (ε > 0): an integer argument is never read as a tolerance.
  • N_max (keyword): the largest number of terms the tolerance may ask for; more throws an ArgumentError.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source
FinancialFFT.CarrMadanLewisMethod — Type
CarrMadanLewisMethod(A, Npow; mode = SerialMode())
CarrMadanLewisMethod(ε; Npow_max = 23, mode = SerialMode())

FFT evaluation of the Lewis (2001) formula: the integrand along the line Im(u) = 1/2 is sampled on [0, A) with 2^Npow nodes and trapezoidal weights, a single complex-to-real FFT of length 2^(Npow + 1) returns the integral on a log-strike grid of step π / A, and prices at the requested strikes are interpolated on it with six-point Lagrange polynomials. Supports EuropeanOption, BinaryEuropeanOption and their smiles.

With a tolerance ε, A and Npow are chosen at pricing time so that the error of the prices is below ε, as for CarrMadanMethod.

Arguments

  • A: upper bound of the frequency integration domain (A > 0).
  • Npow: base-2 logarithm of the number of FFT nodes (2 < Npow < 24).
  • ε: tolerance on the prices (ε > 0); Npow_max: the largest Npow allowed.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source
FinancialFFT.CarrMadanMethod — Type
CarrMadanMethod(A, Npow, α = 0.75; mode = SerialMode())
CarrMadanMethod(ε; α = 0.75, Npow_max = 23, mode = SerialMode())

Carr–Madan (1999) FFT method. The damped call transform is integrated with the trapezoidal rule on the frequency grid v ∈ [0, A) with 2^Npow nodes, a single complex-to-real FFT of length 2^(Npow + 1) returns call prices on a log-strike grid of step π / A, and prices at the requested strikes are interpolated on it with six-point Lagrange polynomials. Supports EuropeanOption, BinaryEuropeanOption and their smiles.

With a tolerance ε, A and Npow are chosen at pricing time, for the model and the strikes of the payoff, so that the error of the prices is below ε: from bounds on the interpolation, truncation and aliasing errors, computed in the float type of the inputs. The bounds do not cover rounding (ε must be above the rounding floor of that type), the parameters are constants for differentiation, and pricing throws an ArgumentError when more than 2^Npow_max nodes are needed. Choosing them costs about one price: for a model priced many times, compute them once and pass (A, Npow).

Arguments

  • A: upper bound of the frequency integration domain (A > 0). The strike grid has step π / A; since 0.10.2 (whose step is half that of before), (A / 2, Npow - 1) gives the prices of (A, Npow) in earlier versions, faster.
  • Npow: base-2 logarithm of the number of FFT nodes (2 < Npow < 24).
  • α: damping exponent (α > 0). It needs E[S^(1 + α)] to be finite, so it is capped halfway between 1 and the exponential moment bound of the model. The frequency step A / 2^Npow must be small with respect to the capped value.
  • ε: tolerance on the prices (ε > 0); Npow_max: the largest Npow allowed.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source
FinancialFFT.CosDensityMethod — Type
CosDensityMethod(N = 128, M = 2^10; mode = SerialMode())

Density of the log-return expanded on N + 1 cosine terms (Fang & Oosterlee, 2008) on the range of CosMethod, see density. As a pricer, it integrates the payoff against that density by Simpson's rule on M intervals of log-moneyness. Like CosMethod, it prices the put, whose integration domain ends at the strike, so that the kink of the payoff is an endpoint, and recovers the call by parity. Supports EuropeanOption, BinaryEuropeanOption and their smiles.

Arguments

  • N: number of cosine terms of the density (N > 2).
  • M: number of Simpson intervals for each strike (even, M > 2); the density does not use it.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source
FinancialFFT.FFTDensityInverter — Type
FFTDensityInverter(N = 14, M = 2^10; mode = SerialMode())

Density of the log-return log(S_T / S_0) recovered by inverting the characteristic function with a single complex-to-real FFT on 2^N points, see density: the density is real, so the characteristic function is evaluated on the 2^(N-1) + 1 non-negative frequencies only. The grid spans the range of CosMethod, from a Chernoff bound on the tails, so it needs no range parameter for any model, and it narrows with the horizon: the short steps of a Vibrato or likelihood ratio estimator keep the resolution of long ones. Between the nodes the density is interpolated by cubic Lagrange polynomials, written with broadcasts and gathers only, so that every AD back-end, Zygote included, differentiates it, on the CPU and on the GPU.

As a pricer, it integrates the put against this density by Simpson's rule on M intervals of log-moneyness ending at the strike, so that the kink of the payoff is an endpoint, and recovers the call by parity, as CosDensityMethod does. Supports EuropeanOption, BinaryEuropeanOption and their smiles: the strikes of a smile share the density, and their prices are the ones of the single options.

Arguments

  • N: base-2 logarithm of the number of grid points (N > 2).
  • M: number of Simpson intervals for each strike (even, M > 2); the density does not use it.
  • mode (keyword): the execution mode, FinancialMonteCarlo.SerialMode() (default) or FinancialMonteCarlo.CudaMode() with CUDA.jl loaded; FinancialMonteCarlo.with_mode(method, mode) changes it.
source

Densities

FinancialFFT.density — Function
density(mcProcess, underlying, zero_rate, method, T)

Density of the log-return log(S_T / S_0) of mcProcess at the horizon T, under the risk-neutral measure of zero_rate, computed with method (CosDensityMethod or FFTDensityInverter). Returns an AbstractDensity, to be evaluated at any number of points: the setup runs once.

It does not depend on S_0: the density of log(S_T) given S_t is f(x - log(S_t)), with the horizon of the step as T for a Lévy process. For Heston it is the marginal density, not the transition density given the variance. It is generic in the number type of the parameters of the model, so scores such as ∂θ log f(y) come from automatic differentiation of log(f(y)); its range is a constant for differentiation. The evaluation of a point runs on the CPU.

The method carries the execution mode: with FinancialMonteCarlo.CudaMode() (the mode keyword of its constructor, or FinancialMonteCarlo.with_mode(method, mode)) the density is computed and stored on the GPU.

source
FinancialFFT.density_values — Function
FinancialFFT.density_values(f, y)

Values of the density f (an FinancialFFT.AbstractDensity) at the array of log-returns y, with the shape of y. For FFTDensity and CosDensity it uses broadcasts, gathers and reductions only: it runs on the device of y and of the density, and Zygote differentiates it there too. A CosDensity and points on the CPU (Arrays) use the Clenshaw recurrence at each point instead, as f(y) does, which needs no array of terms by points.

source
FinancialFFT.FFTDensity — Type
FFTDensity

Density of the log-return of FFTDensityInverter, returned by density: its values on the grid a, a + dx, …, b of 2^N points, which stay on the device of the mode that computed them, and are interpolated by cubic Lagrange polynomials on four nodes, with an error of order dx⁴. Like the grid values, the interpolated density is floored at the machine epsilon, so that its logarithm, and a score, stay finite in the tails.

Calling it on a number evaluates it on the CPU; FinancialFFT.density_values evaluates it at an array of points, on the GPU too. adapt(Array, f) moves a density computed on the GPU to the CPU.

source
FinancialFFT.CosDensity — Type
CosDensity

Density of the log-return of CosDensityMethod, returned by density. The range [a, b] is the one of CosMethod, from a Chernoff bound on the tails with ε = 1e-14. The expansion converges exponentially for smooth densities: N = 64 already reaches machine precision in Black Scholes. The error is absolute: far in the tails, where the density is below about 1e-14, it can be slightly negative, and its relative error, which is the one of a score, grows.

source

Pricing

FinancialMonteCarlo.pricer — Method
pricer(mcProcess, underlying, zero_rate, method, payoff)

Prices payoff under mcProcess with the Fourier method method (LewisMethod, CosMethod, CarrMadanLewisMethod, CarrMadanMethod, CosDensityMethod or FFTDensityInverter).

Arguments

  • mcProcess: a FinancialMonteCarlo.BaseProcess, e.g. BlackScholesProcess(σ).
  • underlying: the Underlying(S0, d) (spot and dividends) priced under it.
  • zero_rate: a FinancialMonteCarlo.AbstractZeroRateCurve, e.g. ZeroRate(r).
  • method: the configuration of the numerical method.
  • payoff: an EuropeanOption or a BinaryEuropeanOption, a smile (EuropeanOptionSmile, BinaryEuropeanOptionSmile, several strikes sharing the same maturity). Options with different maturities are priced by broadcasting, pricer.(mcProcess, underlying, zero_rate, method, payoffs).

The method carries the execution mode (the mode keyword of its constructor): in FinancialMonteCarlo.CudaMode() the strikes of a smile are moved to the GPU, wherever they are, and its prices stay there.

Returns a price, or a vector of prices for smiles.

source

Index