Class BlackFormulaRepository
- java.lang.Object
-
- com.opengamma.strata.pricer.impl.option.BlackFormulaRepository
-
public final class BlackFormulaRepository extends Object
The primary repository for Black formulas, including the price, common greeks and implied volatility.Other classes that have higher level abstractions (e.g. option data bundles) should call these functions. As the numeraire (e.g. the zero bond p(0,T) in the T-forward measure) in the Black formula is just a multiplication factor, all prices, input/output, are forward prices, i.e. (spot price)/numeraire. Note that a "reference value" is returned if computation comes across an ambiguous expression.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
crossGamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless cross gamma.static double
delta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the forward driftless delta.static double
driftlessTheta(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward driftless theta.static double
dualDelta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the driftless dual delta.static double
dualGamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless dual gamma.static double
dualVanna(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless dual vanna.static double
gamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward driftless gamma.static double
impliedStrike(double delta, boolean isCall, double forward, double time, double volatility)
Computes the implied strike from delta and volatility in the Black formula.static double
impliedStrike(double delta, boolean isCall, double forward, double time, double volatility, double[] derivatives)
Computes the implied strike and its derivatives from delta and volatility in the Black formula.static double
impliedVolatility(double price, double forward, double strike, double timeToExpiry, boolean isCall)
Computes the log-normal implied volatility.static double
impliedVolatility(double otmPrice, double forward, double strike, double timeToExpiry, double volGuess)
Computes the log-normal (Black) implied volatility of an out-the-money European option starting from an initial guess.static ValueDerivatives
impliedVolatilityAdjoint(double price, double forward, double strike, double timeToExpiry, boolean isCall)
Computes the log-normal implied volatility and its derivative with respect to price.static ValueDerivatives
impliedVolatilityAdjoint(double otmPrice, double forward, double strike, double timeToExpiry, double volGuess)
Computes the log-normal (Black) implied volatility of an out-the-money European option starting from an initial guess and the derivative of the volatility w.r.t.static double
impliedVolatilityFromNormalApproximated(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the log-normal implied volatility from a normal volatility using an approximate initial guess and a root-finder.static double
impliedVolatilityFromNormalApproximated2(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the normal implied volatility from a normal volatility using an approximate explicit formula.static ValueDerivatives
impliedVolatilityFromNormalApproximatedAdjoint(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the log-normal implied volatility from a normal volatility using an approximate initial guess and a root-finder and compute the derivative of the log-normal volatility with respect to the input normal volatility.static double
price(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the forward price.static ValueDerivatives
priceAdjoint(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the price without numeraire and its derivatives.static Pair<ValueDerivatives,double[][]>
priceAdjoint2(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the price without numeraire and its derivatives of the first and second order.static double
simpleDelta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the simple delta.static double
strikeForDelta(double forward, double forwardDelta, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the strike for the delta.static double
theta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall, double interestRate)
Computes the theta (non-forward).static double
thetaMod(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall, double interestRate)
Computes the theta (non-forward).static double
vanna(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless vanna.static double
vega(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward vega.static double
volga(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless volga (aka vomma).static double
vomma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless vomma (aka volga).
-
-
-
Method Detail
-
price
public static double price(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the forward price.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the forward price
-
priceAdjoint
public static ValueDerivatives priceAdjoint(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the price without numeraire and its derivatives.The derivatives are in the following order:
- [0] derivative with respect to the forward
- [1] derivative with respect to the strike
- [2] derivative with respect to the time to expiry
- [3] derivative with respect to the volatility
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the forward price and its derivatives
-
priceAdjoint2
public static Pair<ValueDerivatives,double[][]> priceAdjoint2(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the price without numeraire and its derivatives of the first and second order.The first order derivatives are in the following order:
- [0] derivative with respect to the forward
- [1] derivative with respect to the strike
- [2] derivative with respect to the time to expiry
- [3] derivative with respect to the volatility
The second order derivatives are in the following order:
- [0] derivative with respect to the forward
- [1] derivative with respect to the strike
- [2] derivative with respect to the volatility
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the forward price and its derivatives
-
delta
public static double delta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the forward driftless delta.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the forward driftless delta
-
strikeForDelta
public static double strikeForDelta(double forward, double forwardDelta, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the strike for the delta.- Parameters:
forward
- the forward value of the underlyingforwardDelta
- the forward deltatimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the strike
-
dualDelta
public static double dualDelta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the driftless dual delta.This is the first derivative of option price with respect to strike.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the driftless dual delta
-
simpleDelta
public static double simpleDelta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall)
Computes the simple delta.Note that this is not the standard delta one is accustomed to. The argument of the cumulative normal is simply
d = Math.log(forward / strike) / sigmaRootT
.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for put- Returns:
- the simple delta
-
gamma
public static double gamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward driftless gamma.This is the second order sensitivity of the forward option value to the forward.
$\frac{\partial^2 FV}{\partial^2 f}$
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the forward driftless gamma
-
dualGamma
public static double dualGamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless dual gamma.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless dual gamma
-
crossGamma
public static double crossGamma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless cross gamma.This is the sensitity of the delta to the strike.
$\frac{\partial^2 V}{\partial f \partial K}$.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless cross gamma
-
theta
public static double theta(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall, double interestRate)
Computes the theta (non-forward).This is the sensitivity of the present value to a change in time to maturity.
$\-frac{\partial * V}{\partial T}$.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for putinterestRate
- the interest rate- Returns:
- theta
-
thetaMod
public static double thetaMod(double forward, double strike, double timeToExpiry, double lognormalVol, boolean isCall, double interestRate)
Computes the theta (non-forward).This is the sensitivity of the present value to a change in time to maturity
$\-frac{\partial * V}{\partial T}$.
This is consistent with
BlackScholesFormulaRepository
.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatilityisCall
- true for call, false for putinterestRate
- the interest rate- Returns:
- theta
-
driftlessTheta
public static double driftlessTheta(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward driftless theta.- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless theta
-
vega
public static double vega(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the forward vega.This is the sensitivity of the option's forward price wrt the implied volatility (which is just the spot vega divided by the numeraire).
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the forward vega
-
vanna
public static double vanna(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless vanna.This is the second order derivative of the option value, once to the underlying forward and once to volatility.
$\frac{\partial^2 FV}{\partial f \partial \sigma}$.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless vanna
-
dualVanna
public static double dualVanna(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless dual vanna.This is the second order derivative of the option value, once to the strike and once to volatility.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless dual vanna
-
vomma
public static double vomma(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless vomma (aka volga).This is the second order derivative of the option forward price with respect to the implied volatility.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless vomma
-
volga
public static double volga(double forward, double strike, double timeToExpiry, double lognormalVol)
Computes the driftless volga (aka vomma).This is the second order derivative of the option forward price with respect to the implied volatility.
- Parameters:
forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expirylognormalVol
- the log-normal volatility- Returns:
- the driftless volga
-
impliedVolatility
public static double impliedVolatility(double price, double forward, double strike, double timeToExpiry, boolean isCall)
Computes the log-normal implied volatility.- Parameters:
price
- The forward price, which is the market price divided by the numeraire, for example the zero bond p(0,T) for the T-forward measureforward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expiryisCall
- true for call, false for put- Returns:
- log-normal (Black) implied volatility
-
impliedVolatilityAdjoint
public static ValueDerivatives impliedVolatilityAdjoint(double price, double forward, double strike, double timeToExpiry, boolean isCall)
Computes the log-normal implied volatility and its derivative with respect to price.- Parameters:
price
- The forward price, which is the market price divided by the numeraire, for example the zero bond p(0,T) for the T-forward measureforward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expiryisCall
- true for call, false for put- Returns:
- log-normal (Black) implied volatility and tis derivative w.r.t. the price
-
impliedVolatility
public static double impliedVolatility(double otmPrice, double forward, double strike, double timeToExpiry, double volGuess)
Computes the log-normal (Black) implied volatility of an out-the-money European option starting from an initial guess.- Parameters:
otmPrice
- The forward price, which is the market price divided by the numeraire, for example the zero bond p(0,T) for the T-forward measure This MUST be an OTM price, i.e. a call price for strike >= forward and a put price otherwise.forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expiryvolGuess
- a guess of the implied volatility- Returns:
- log-normal (Black) implied volatility
-
impliedVolatilityAdjoint
public static ValueDerivatives impliedVolatilityAdjoint(double otmPrice, double forward, double strike, double timeToExpiry, double volGuess)
Computes the log-normal (Black) implied volatility of an out-the-money European option starting from an initial guess and the derivative of the volatility w.r.t. the price.- Parameters:
otmPrice
- The forward price, which is the market price divided by the numeraire, for example the zero bond p(0,T) for the T-forward measure This MUST be an OTM price, i.e. a call price for strike >= forward and a put price otherwise.forward
- the forward value of the underlyingstrike
- the striketimeToExpiry
- the time to expiryvolGuess
- a guess of the implied volatility- Returns:
- log-normal (Black) implied volatility and derivative with respect to the price
-
impliedStrike
public static double impliedStrike(double delta, boolean isCall, double forward, double time, double volatility)
Computes the implied strike from delta and volatility in the Black formula.- Parameters:
delta
- The option deltaisCall
- true for call, false for putforward
- The forward.time
- The time to expiry.volatility
- The volatility.- Returns:
- the strike.
-
impliedStrike
public static double impliedStrike(double delta, boolean isCall, double forward, double time, double volatility, double[] derivatives)
Computes the implied strike and its derivatives from delta and volatility in the Black formula.- Parameters:
delta
- The option deltaisCall
- true for call, false for putforward
- the forwardtime
- the time to expiryvolatility
- the volatilityderivatives
- the mutated array of derivatives of the implied strike with respect to the input Derivatives with respect to: [0] delta, [1] forward, [2] time, [3] volatility.- Returns:
- the strike
-
impliedVolatilityFromNormalApproximated
public static double impliedVolatilityFromNormalApproximated(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the log-normal implied volatility from a normal volatility using an approximate initial guess and a root-finder.The forward and the strike must be positive.
Reference: Hagan, P. S. Volatility conversion calculator. Technical report, Bloomberg.
- Parameters:
forward
- the forward rate/pricestrike
- the option striketimeToExpiry
- the option time to expirationnormalVolatility
- the normal implied volatility- Returns:
- the Black implied volatility
-
impliedVolatilityFromNormalApproximatedAdjoint
public static ValueDerivatives impliedVolatilityFromNormalApproximatedAdjoint(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the log-normal implied volatility from a normal volatility using an approximate initial guess and a root-finder and compute the derivative of the log-normal volatility with respect to the input normal volatility.The forward and the strike must be positive.
Reference: Hagan, P. S. Volatility conversion calculator. Technical report, Bloomberg.
- Parameters:
forward
- the forward rate/pricestrike
- the option striketimeToExpiry
- the option time to expirationnormalVolatility
- the normal implied volatility- Returns:
- the Black implied volatility and its derivative
-
impliedVolatilityFromNormalApproximated2
public static double impliedVolatilityFromNormalApproximated2(double forward, double strike, double timeToExpiry, double normalVolatility)
Compute the normal implied volatility from a normal volatility using an approximate explicit formula.The formula is usually not good enough to be used as such, but provide a good initial guess for a root-finding procedure. Use
impliedVolatilityFromNormalApproximated(double, double, double, double)
for more precision.The forward and the strike must be positive.
Reference: Hagan, P. S. Volatility conversion calculator. Technical report, Bloomberg.
- Parameters:
forward
- the forward rate/pricestrike
- the option striketimeToExpiry
- the option time to expirationnormalVolatility
- the normal implied volatility- Returns:
- the Black implied volatility
-
-