API reference

Methods

FinancialFFT.LewisMethod — Type
LewisMethod(A, N)

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.

Arguments

  • A: half-width of the frequency integration domain (A > 0).
  • N: number of quadrature nodes (N > 2).
source
FinancialFFT.CosMethod — Type
CosMethod(N)

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 compute_chernoff_extrema_bisection), 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.

Arguments

  • N: number of cosine terms (N > 2).
source
FinancialFFT.CarrMadanLewisMethod — Type
CarrMadanLewisMethod(A, Npow)

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 Simpson weights, a single FFT returns the integral on a log-strike grid, and prices at the requested strikes are interpolated on it with six-point Lagrange polynomials. Supports EuropeanOption, BinaryEuropeanOption and their smiles.

Arguments

  • A: upper bound of the frequency integration domain (A > 0).
  • Npow: base-2 logarithm of the number of FFT nodes (2 < Npow < 24).
source
FinancialFFT.CarrMadanMethod — Type
CarrMadanMethod(A, Npow, α = 0.75)

Carr–Madan (1999) FFT method. The damped call transform is integrated with Simpson weights on the frequency grid v ∈ [0, A) with 2^Npow nodes, a single FFT returns call prices on a log-strike grid, and prices at the requested strikes are interpolated on it with six-point Lagrange polynomials. Supports EuropeanOption, BinaryEuropeanOption and their smiles.

Arguments

  • A: upper bound of the frequency integration domain (A > 0). The strike grid has step 2π / A.
  • 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.
source
FinancialFFT.CosDensityMethod — Type
CosDensityMethod(N = 128, M = 2^10)

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.
source
FinancialFFT.FFTDensityInverter — Type
FFTDensityInverter(N = 14, M = 2^10)

Density of the log-return log(S_T / S_0) recovered by inverting the characteristic function with a single FFT on 2^N points, see density. 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.
source

Densities

FinancialFFT.density — Function
density(mcProcess, zero_rate, method, T[, mode])

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 d(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(d(y)); its range is a constant for differentiation. The evaluation of a point runs on the CPU.

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.

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, zero_rate, method, payoff[, mode])

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(S0, d)).
  • 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, zero_rate, method, payoffs).
  • mode: FinancialMonteCarlo.SerialMode() (default) or a CUDA mode when CUDA.jl is loaded.

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

source

Index