Class SABRInterpolation
The SABR smile fitted to discrete volatilities: SABR's four parameters fitted to the volatilities at the strikes, interpolated by the SABR volatility at the fitted parameters.
public sealed class SABRInterpolation : Interpolation, IXabrInterpolation
- Inheritance
-
SABRInterpolation
- Implements
- Inherited Members
- Extension Methods
Remarks
The fit runs when the interpolation is built: QuantLib's construction followed by its update(), which every
QuantLib user calls at once. A new fit is a new interpolation, so update() isn't ported. The fit minimizes
the (vega-weighted, by default) squared errors from the given guesses, then, while the error stays above
errorAccept, from up to maxGuesses − 1 more guesses drawn from a Halton sequence seeded with
QuantLib's 42, keeping the best; its results are QuantLib's at every step.
As QuantLib's, a restart is kept by the error the cost function's last evaluation gives: the result's under LevenbergMarquardt, the default, which evaluates its result last, but a later trial's under Simplex, which returns its best vertex without evaluating it again. Fixed parameters go through the parameter transforms at every evaluation, as QuantLib's do, so a fixed β of 0.5 is reported as 0.5000000000000001. A fixed or guessed ρ beyond ±0.9999, or α or ν below 1e-7, is taken as the nearest value the transform reaches, where QuantLib's transform flips ρ's sign or fails; and a smile of zero volatilities with vega weights is refused, where QuantLib fits on NaN weights.
Immutable and thread-safe once built: it copies its inputs, and nothing writes the fit after it.
Constructors
SABRInterpolation(ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double?, double?, double?, double?, bool, bool, bool, bool, bool, EndCriteria?, OptimizationMethod?, double, bool, int, double, VolatilityType)
Initializes a new instance of the SABRInterpolation class, and fits it.
public SABRInterpolation(ReadOnlySpan<double> x, ReadOnlySpan<double> y, double t, double forward, double? alpha, double? beta, double? nu, double? rho, bool alphaIsFixed, bool betaIsFixed, bool nuIsFixed, bool rhoIsFixed, bool vegaWeighted = true, EndCriteria? endCriteria = null, OptimizationMethod? optMethod = null, double errorAccept = 0.002, bool useMaxError = false, int maxGuesses = 50, double shift = 0, VolatilityType volatilityType = VolatilityType.ShiftedLognormal)
Parameters
xReadOnlySpan<double>The strikes, sorted.
yReadOnlySpan<double>The volatilities, one per strike.
tdoubleThe time to expiry, positive.
forwarddoubleThe forward.
alphadouble?α's guess, or null for SABR's default, 0.2·(F + shift)1−β.
betadouble?β's guess, or null for 0.5.
nudouble?ν's guess, or null for √0.4.
rhodouble?ρ's guess, or null for 0.
alphaIsFixedboolWhether α is fixed at its guess; a parameter not given is free.
betaIsFixedboolWhether β is fixed at its guess.
nuIsFixedboolWhether ν is fixed at its guess.
rhoIsFixedboolWhether ρ is fixed at its guess.
vegaWeightedboolWhether the errors are weighted by the strikes' Black vegas.
endCriteriaEndCriteriaThe end criteria, or null for QuantLib's
EndCriteria(60000, 100, 1e-8, 1e-8, 1e-8).optMethodOptimizationMethodThe optimizer, or null for QuantLib's
LevenbergMarquardt(1e-8, 1e-8, 1e-8).errorAcceptdoubleThe error at or below which a fit is accepted and the restarts stop.
useMaxErrorboolWhether a fit is scored by its maximum error, not its root-mean-square error.
maxGuessesintThe most minimizations; 0 runs one, as 1 does.
shiftdoubleThe shift of a shifted SABR model.
volatilityTypeVolatilityTypeThe volatilities' type: shifted lognormal or normal.
Exceptions
- ArgumentOutOfRangeException
maxGuessesis negative, orvolatilityTypeisn't a member of its type.- ArgumentException
The sizes differ, there is no strike, the time isn't positive, the forward plus the shift isn't positive, a guess is out of its range, a strike plus the shift isn't positive, the volatilities are all zero with vega weights, or the optimizer refuses the problem.
- NanoQLException
The optimizer fails.
Properties
Alpha
Gets the fitted α.
public double Alpha { get; }
Property Value
Beta
Gets the fitted β.
public double Beta { get; }
Property Value
EndCriteria
Gets the end criteria of the minimization the fit kept; None where it ran none.
public EndCriteriaType EndCriteria { get; }
Property Value
Expiry
Gets the time to expiry.
public double Expiry { get; }
Property Value
Forward
Gets the forward.
public double Forward { get; }
Property Value
MaxError
Gets the largest error of the fit, unweighted.
public double MaxError { get; }
Property Value
Nu
Gets the fitted ν.
public double Nu { get; }
Property Value
Rho
Gets the fitted ρ.
public double Rho { get; }
Property Value
RmsError
Gets the root-mean-square error of the fit, weighted by InterpolationWeights().
public double RmsError { get; }
Property Value
Methods
DerivativeCore(double)
The first derivative at a point, after the range check.
protected override double DerivativeCore(double x)
Parameters
xdoubleThe point.
Returns
- double
The derivative.
Exceptions
- NanoQLException
Always: an XABR interpolation has no derivative.
InterpolationWeights()
The strikes' weights in the fit's errors, normalized.
public ImmutableArray<double> InterpolationWeights()
Returns
- ImmutableArray<double>
The weights, one per strike.
PrimitiveCore(double)
The primitive at a point, after the range check.
protected override double PrimitiveCore(double x)
Parameters
xdoubleThe point.
Returns
- double
The primitive.
Exceptions
- NanoQLException
Always: an XABR interpolation has no primitive.
SecondDerivativeCore(double)
The second derivative at a point, after the range check.
protected override double SecondDerivativeCore(double x)
Parameters
xdoubleThe point.
Returns
- double
The second derivative.
Exceptions
- NanoQLException
Always: an XABR interpolation has no second derivative.
ValueCore(double)
The interpolated value at a point, after the range check.
protected override double ValueCore(double x)
Parameters
xdoubleThe point.
Returns
- double
The value.