Table of Contents

Class SABRInterpolation

Namespace
NanoQL.Numerics
Assembly
NanoQL.dll

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

x ReadOnlySpan<double>

The strikes, sorted.

y ReadOnlySpan<double>

The volatilities, one per strike.

t double

The time to expiry, positive.

forward double

The forward.

alpha double?

α's guess, or null for SABR's default, 0.2·(F + shift)1−β.

beta double?

β's guess, or null for 0.5.

nu double?

ν's guess, or null for √0.4.

rho double?

ρ's guess, or null for 0.

alphaIsFixed bool

Whether α is fixed at its guess; a parameter not given is free.

betaIsFixed bool

Whether β is fixed at its guess.

nuIsFixed bool

Whether ν is fixed at its guess.

rhoIsFixed bool

Whether ρ is fixed at its guess.

vegaWeighted bool

Whether the errors are weighted by the strikes' Black vegas.

endCriteria EndCriteria

The end criteria, or null for QuantLib's EndCriteria(60000, 100, 1e-8, 1e-8, 1e-8).

optMethod OptimizationMethod

The optimizer, or null for QuantLib's LevenbergMarquardt(1e-8, 1e-8, 1e-8).

errorAccept double

The error at or below which a fit is accepted and the restarts stop.

useMaxError bool

Whether a fit is scored by its maximum error, not its root-mean-square error.

maxGuesses int

The most minimizations; 0 runs one, as 1 does.

shift double

The shift of a shifted SABR model.

volatilityType VolatilityType

The volatilities' type: shifted lognormal or normal.

Exceptions

ArgumentOutOfRangeException

maxGuesses is negative, or volatilityType isn'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

double

Beta

Gets the fitted β.

public double Beta { get; }

Property Value

double

EndCriteria

Gets the end criteria of the minimization the fit kept; None where it ran none.

public EndCriteriaType EndCriteria { get; }

Property Value

EndCriteriaType

Expiry

Gets the time to expiry.

public double Expiry { get; }

Property Value

double

Forward

Gets the forward.

public double Forward { get; }

Property Value

double

MaxError

Gets the largest error of the fit, unweighted.

public double MaxError { get; }

Property Value

double

Nu

Gets the fitted ν.

public double Nu { get; }

Property Value

double

Rho

Gets the fitted ρ.

public double Rho { get; }

Property Value

double

RmsError

Gets the root-mean-square error of the fit, weighted by InterpolationWeights().

public double RmsError { get; }

Property Value

double

Methods

DerivativeCore(double)

The first derivative at a point, after the range check.

protected override double DerivativeCore(double x)

Parameters

x double

The 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

x double

The 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

x double

The 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

x double

The point.

Returns

double

The value.