Class HestonCos
The idea: the density of y = ln(S_T/K) is replaced by a cosine
series on a finite interval [a, b], whose coefficients are read off
the characteristic function, and the payoff's cosine coefficients are known
in closed form. For a put (eq. 30 and 33 of the paper),
put = K e^{-rT} sum'_{k=0}^{N-1} Re[ phi(u_k) e^{i u_k (x - a)} ] V_k, u_k = k pi / (b - a)
V_k = 2/(b - a) (psi_k(a, 0) - chi_k(a, 0)), x = ln(S/K)
where the prime halves the k = 0 term and chi, psi are the exponential
and unit cosine integrals of eq. 22-23. The call follows from put-call
parity, which avoids the cancellation the paper reports for calls with a
wide interval. phi is the Heston characteristic function of
ln(S_T/S_0) in the paper's eq. 32 form,
phi(w) = exp(i w (r-q) T + v0/sigma^2 (1 - e^{-DT})/(1 - G e^{-DT}) (kappa - i rho sigma w - D))
* exp(kappa theta/sigma^2 [T (kappa - i rho sigma w - D) - 2 ln((1 - G e^{-DT})/(1 - G))])
D = sqrt((kappa - i rho sigma w)^2 + (w^2 + i w) sigma^2), G = (kappa - i rho sigma w - D)/(kappa - i rho sigma w + D)
which is the "little Heston trap" form (Albrecher et al. 2007) and needs
no branch tracking with the principal square root and logarithm. The
interval is [x + c1 - L sqrt(c2), x + c1 + L sqrt(c2)] with the
first two cumulants of the paper's Table 11, c4 omitted as the paper does
for Heston. The paper's L = 12 truncates the fat left tail of
parameter sets far from the Feller condition: on its own section 5.2 test
case it leaves an error of 4.5e-5. The default here is L = 32 with
N = 1024, which agrees with the Simpson pricer in Heston to 2e-9 and with the published value 5.785155450 to 2e-8
(tested); both are arguments to price(OptionType, double, double, double, double, double, Heston.Params, int, double).
Greeks: with the interval held fixed, the expansion is an explicit
function of x and of the five parameters. Delta and gamma
differentiate e^{i u_k x}; the parameter gradient differentiates
phi by forward-mode automatic differentiation over complex dual
numbers, so every derivative is exact for the truncated series (no bump
size). The interval itself moves with spot and parameters; at the default
N the price is converged far below the size of that effect, and the
tests check the analytic values against central differences of the full
pricer. Research lane; allocates a few small objects per call.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault number of cosine terms.static final doubleDefault truncation width in standard deviations. -
Method Summary
Modifier and TypeMethodDescriptionstatic doubledelta(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Delta dV/dS from the expansion (analytic in x = ln(S/K)).static doublegamma(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Gamma d2V/dS2 (same for calls and puts).static double[]parameterGradient(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Gradient of the price with respect to (kappa, theta, sigmaV, rho, v0), identical for calls and puts since parity does not involve the model.static doubleprice(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) European price with the default number of terms and truncation.static doubleprice(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p, int terms, double truncation) European price.static doublevegaV0(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Sensitivity to the initial variance, dV/dv0 (same for calls and puts).
-
Field Details
-
DEFAULT_TERMS
public static final int DEFAULT_TERMSDefault number of cosine terms.- See Also:
-
DEFAULT_TRUNCATION
public static final double DEFAULT_TRUNCATIONDefault truncation width in standard deviations.- See Also:
-
-
Method Details
-
price
public static double price(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) European price with the default number of terms and truncation. -
price
public static double price(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p, int terms, double truncation) European price.- Parameters:
terms- number of cosine terms N, at least 8truncation- interval half-width L in units of sqrt(c2), positive
-
delta
public static double delta(BlackScholes.OptionType type, double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Delta dV/dS from the expansion (analytic in x = ln(S/K)). -
gamma
public static double gamma(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Gamma d2V/dS2 (same for calls and puts). -
vegaV0
public static double vegaV0(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Sensitivity to the initial variance, dV/dv0 (same for calls and puts). Multiply by2 sqrt(v0)for the sensitivity to initial volatility. -
parameterGradient
public static double[] parameterGradient(double spot, double strike, double rate, double divYield, double timeYears, Heston.Params p) Gradient of the price with respect to (kappa, theta, sigmaV, rho, v0), identical for calls and puts since parity does not involve the model. Returns a new array of length 5.
-