Class AlphaFinder
The α of an alpha form, and the multipliers a and b, at which a swap rate's volatilities give a caplet its target variance: by the form's α at the initial guess where it works, by a bisection on the quadratic's turning point otherwise, or, with SolveWithMaxHomogeneity(double, int, ReadOnlySpan<double>, ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double, double, double, double, int, out double, out double, out double, Span<double>), at the α of the most homogeneous volatilities among those that work.
[WorkingType]
public sealed class AlphaFinder
- Inheritance
-
AlphaFinder
- Inherited Members
Remarks
A working type: each solve keeps its inputs, as QuantLib's members, and sets the form's α; the alpha calibration builds one per calibration around its own copy of the form. It isn't thread-safe.
QuantLib's master's finder (#2910; Divergences/AlphaFinderTests.cs), which fixes four of QuantLib 1.44's
defects: the downward bracket search stops at its first acceptable α, testing the value it moves, where 1.44's tests
the upward one's (alphafinder.cpp:372-373); the minimization's feasibility test reads the trial α, where
1.44's reads the objective's value there (:117, :145); the bisection returns at an exact root and
where its point no longer moves; and Solve(double, int, ReadOnlySpan<double>, ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double, double, double, double, int, out double, out double, out double, Span<double>) and SolveWithMaxHomogeneity(double, int, ReadOnlySpan<double>, ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double, double, double, double, int, out double, out double, out double, Span<double>) return their
final part's success, where 1.44's return true where it fails, at α₀ or at the search's α (:335-346,
:405-415, :550-561), the swap rate's last volatility then left as the caller's. Two of nanoql's own:
the searches and the minimization also stop where their point no longer moves, where QuantLib's never end at a
tolerance of 0 (:30-111); and b is NaN where the final part fails, where QuantLib leaves the caller's value.
The alpha calibration's fallback minimizes on 1.44's test of the objective's value. Inputs shorter than the step
index reads, which QuantLib reads past, are refused.
Constructors
AlphaFinder(AlphaForm)
Initializes a new instance of the AlphaFinder class.
public AlphaFinder(AlphaForm parametricForm)
Parameters
parametricFormAlphaFormThe alpha form, whose α each solve sets.
Methods
Solve(double, int, ReadOnlySpan<double>, ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double, double, double, double, int, out double, out double, out double, Span<double>)
The α, a and b at which the second rate's volatilities give the caplet its target variance: the initial α where it works, a bracketed bisection on the quadratic's turning point otherwise.
public bool Solve(double alpha0, int stepIndex, ReadOnlySpan<double> rateOneVols, ReadOnlySpan<double> rateTwoHomogeneousVols, ReadOnlySpan<double> correlations, double w0, double w1, double targetVariance, double tolerance, double alphaMax, double alphaMin, int steps, out double alpha, out double a, out double b, Span<double> rateTwoVols)
Parameters
alpha0doubleThe initial α.
stepIndexintThe caplet's index.
rateOneVolsReadOnlySpan<double>The first rate's volatilities, at least the step index plus one.
rateTwoHomogeneousVolsReadOnlySpan<double>The second rate's homogeneous volatilities, at least the step index plus two.
correlationsReadOnlySpan<double>The two rates' correlations, at least the step index plus one.
w0doubleThe first rate's weight.
w1doubleThe second rate's weight.
targetVariancedoubleThe caplet's target variance.
tolerancedoubleThe bisection's tolerance.
alphaMaxdoubleThe largest α.
alphaMindoubleThe smallest α.
stepsintThe bracket search's steps.
alphadoubleThe α found; NaN where none is.
adoubleThe multiplier of the second rate's volatilities to the caplet's reset.
bdoubleThe multiplier of its volatility after it; NaN where the final part fails.
rateTwoVolsSpan<double>The second rate's new volatilities, written to the step index plus one.
Returns
- bool
Whether an α was found and its final part, the variance left for the second rate's last volatility, succeeded.
Exceptions
- ArgumentException
A vector is shorter than the step index reads.
- ArgumentOutOfRangeException
stepIndexis negative.
SolveWithMaxHomogeneity(double, int, ReadOnlySpan<double>, ReadOnlySpan<double>, ReadOnlySpan<double>, double, double, double, double, double, double, int, out double, out double, out double, Span<double>)
The α, a and b at which the second rate's volatilities give the caplet its target variance, at the α, among those that work, whose volatilities are the closest to the homogeneous ones.
public bool SolveWithMaxHomogeneity(double alpha0, int stepIndex, ReadOnlySpan<double> rateOneVols, ReadOnlySpan<double> rateTwoHomogeneousVols, ReadOnlySpan<double> correlations, double w0, double w1, double targetVariance, double tolerance, double alphaMax, double alphaMin, int steps, out double alpha, out double a, out double b, Span<double> rateTwoVols)
Parameters
alpha0doubleThe initial α.
stepIndexintThe caplet's index.
rateOneVolsReadOnlySpan<double>The first rate's volatilities, at least the step index plus one.
rateTwoHomogeneousVolsReadOnlySpan<double>The second rate's homogeneous volatilities, at least the step index plus two.
correlationsReadOnlySpan<double>The two rates' correlations, at least the step index plus one.
w0doubleThe first rate's weight.
w1doubleThe second rate's weight.
targetVariancedoubleThe caplet's target variance.
tolerancedoubleThe searches' tolerance.
alphaMaxdoubleThe largest α.
alphaMindoubleThe smallest α.
stepsintThe search's steps where no end works.
alphadoubleThe α found; NaN where none is.
adoubleThe multiplier of the second rate's volatilities to the caplet's reset.
bdoubleThe multiplier of its volatility after it; NaN where the final part fails.
rateTwoVolsSpan<double>The second rate's new volatilities, written to the step index plus one.
Returns
- bool
Whether an α was found and its final part, the variance left for the second rate's last volatility, succeeded.
Exceptions
- ArgumentException
A vector is shorter than the step index reads.
- ArgumentOutOfRangeException
stepIndexorstepsis negative.