Class SabrFunctions
- Namespace
- NanoQL.TermStructures
- Assembly
- NanoQL.dll
The SABR functions: Hagan's lognormal and normal expansions of the SABR volatility, Le Floc'h and Kennedy's expansion, the parameters' validation and Le Floc'h and Kennedy's initial guess for a calibration.
public static class SabrFunctions
- Inheritance
-
SabrFunctions
- Inherited Members
Remarks
The expansions keep QuantLib's order of operations, so their values are QuantLib's bit for bit wherever the C runtime's functions agree with .NET's. A VolatilityType outside its members is refused on entry, where QuantLib takes any value other than Normal as lognormal.
Methods
SabrFlochKennedyVolatility(double, double, double, double, double, double, double)
Le Floc'h and Kennedy's expansion of the lognormal SABR volatility, with no check of its arguments.
public static double SabrFlochKennedyVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho)
Parameters
strikedoubleThe strike.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
Returns
- double
The volatility; a second-order Taylor expansion where the strike is within 0.25% of the forward.
SabrGuess(double, double, double, double, double, double, double, double, double, double, VolatilityType)
Le Floc'h and Kennedy's initial guess for a SABR calibration (Le Floc'h and Kennedy, "Explicit SABR Calibration through Simple Expansions"): the parameters matching the at-the-money volatility, skew and curvature that three volatilities around the forward give.
public static ImmutableArray<double> SabrGuess(double k_m, double vol_m, double k_0, double vol_0, double k_p, double vol_p, double forward, double expiryTime, double beta, double shift, VolatilityType volatilityType)
Parameters
k_mdoubleThe strike before the one closest to the forward.
vol_mdoubleIts volatility.
k_0doubleThe strike closest to the forward.
vol_0doubleIts volatility.
k_pdoubleThe strike after the one closest to the forward.
vol_pdoubleIts volatility.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
betadoubleSABR's β, which the guess returns as given.
shiftdoubleThe shift.
volatilityTypeVolatilityTypeNormal, or shifted lognormal.
Returns
- ImmutableArray<double>
The guesses α, β, ν and ρ, in that order.
Remarks
A non-finite argument is refused, where QuantLib computes on it: a NaN smile gives ρ the sign of a NaN, which depends on which NaN an operation keeps, so QuantLib's value there isn't a number a caller can use. α is the smallest positive root of the guess's cubic, or its first estimate where the cubic has none, as QuantLib's.
Exceptions
- ArgumentOutOfRangeException
volatilityTypeisn't a member of its type.- ArgumentException
An argument is NaN or infinite.
SabrVolatility(double, double, double, double, double, double, double, VolatilityType)
The SABR volatility of the given type, its arguments checked.
public static double SabrVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho, VolatilityType volatilityType = VolatilityType.ShiftedLognormal)
Parameters
strikedoubleThe strike, positive.
forwarddoubleThe forward, positive.
expiryTimedoubleThe time to expiry, non-negative.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
volatilityTypeVolatilityTypeNormal, or shifted lognormal.
Returns
- double
The volatility.
Exceptions
- ArgumentOutOfRangeException
volatilityTypeisn't a member of its type.- ArgumentException
An argument is out of its range.
ShiftedSabrVolatility(double, double, double, double, double, double, double, double, VolatilityType)
The shifted SABR volatility of the given type, its arguments checked.
public static double ShiftedSabrVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho, double shift, VolatilityType volatilityType = VolatilityType.ShiftedLognormal)
Parameters
strikedoubleThe strike; strike + shift positive.
forwarddoubleThe forward; forward + shift positive.
expiryTimedoubleThe time to expiry, non-negative.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
shiftdoubleThe shift added to the strike and the forward.
volatilityTypeVolatilityTypeNormal, or shifted lognormal.
Returns
- double
The volatility.
Exceptions
- ArgumentOutOfRangeException
volatilityTypeisn't a member of its type.- ArgumentException
An argument is out of its range.
UnsafeSabrLogNormalVolatility(double, double, double, double, double, double, double)
Hagan's lognormal SABR volatility, with no check of its arguments.
public static double UnsafeSabrLogNormalVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho)
Parameters
strikedoubleThe strike.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
Returns
- double
The volatility.
UnsafeSabrNormalVolatility(double, double, double, double, double, double, double)
The normal SABR volatility, with no check of its arguments.
public static double UnsafeSabrNormalVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho)
Parameters
strikedoubleThe strike.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
Returns
- double
The volatility.
Remarks
As QuantLib's: Deloitte's "SABR sensitivities" note.
UnsafeSabrVolatility(double, double, double, double, double, double, double, VolatilityType)
The SABR volatility of the given type, with no check of its arguments.
public static double UnsafeSabrVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho, VolatilityType volatilityType = VolatilityType.ShiftedLognormal)
Parameters
strikedoubleThe strike.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
volatilityTypeVolatilityTypeNormal, or shifted lognormal.
Returns
- double
The volatility.
Exceptions
- ArgumentOutOfRangeException
volatilityTypeisn't a member of its type.
UnsafeShiftedSabrVolatility(double, double, double, double, double, double, double, double, VolatilityType)
The shifted SABR volatility of the given type, with no check of its arguments.
public static double UnsafeShiftedSabrVolatility(double strike, double forward, double expiryTime, double alpha, double beta, double nu, double rho, double shift, VolatilityType volatilityType = VolatilityType.ShiftedLognormal)
Parameters
strikedoubleThe strike.
forwarddoubleThe forward.
expiryTimedoubleThe time to expiry.
alphadoubleSABR's α.
betadoubleSABR's β.
nudoubleSABR's ν.
rhodoubleSABR's ρ.
shiftdoubleThe shift added to the strike and the forward.
volatilityTypeVolatilityTypeNormal, or shifted lognormal.
Returns
- double
The volatility.
Exceptions
- ArgumentOutOfRangeException
volatilityTypeisn't a member of its type.
ValidateSabrParameters(double, double, double, double)
Checks SABR's parameters.
public static void ValidateSabrParameters(double alpha, double beta, double nu, double rho)
Parameters
alphadoubleSABR's α, positive.
betadoubleSABR's β, in [0, 1].
nudoubleSABR's ν, non-negative.
rhodoubleSABR's ρ, in (−1, 1).
Exceptions
- ArgumentException
A parameter is out of its range, or NaN.