Table of Contents

Struct GlobalBootstrap

Namespace
NanoQL.TermStructures
Assembly
NanoQL.dll

The global bootstrapper, with additional restrictions: the curve's nodes are solved together, by an optimizer that minimizes the helpers' quote errors and any additional penalties.

public readonly struct GlobalBootstrap : IBootstrap
Implements
Inherited Members

Remarks

A configuration struct (IBootstrap): its zero value is QuantLib's default construction. QuantLib's three constructors are one, with optional parameters. An optimizer or end criteria not given is QuantLib's default, built when a curve is built: a LevenbergMarquardt method and EndCriteria of 1000 iterations and 10 stationary ones, each tolerance the accuracy, which is the curve's when not given.

The curve's nodes are its first date, the pillars of its helpers alive at that date and the additional dates after it, sorted, each once. The additional dates are a collection, where QuantLib's are a functor of the evaluation date, since a curve is built once. The error terms are the alive helpers' quote errors, each times its instrument weight, then the additional penalties: together they must be at least as many as the nodes after the first. The additional helpers are bound to the curve as its helpers are, but add no pillar or error term of their own: the penalties price them. The penalties and the initial-guess function receive the curve's working state (IBootstrapState), whose helpers and additional helpers are bound to the curve, and the context, where QuantLib's reach the helpers through the user's own pointers, which the bootstrap has linked to the curve. In a multicurve the members' curves are set up in the order they were added, before any is optimized, so a guess function that prices a helper on a bootstrapped member added after its own curve, or on a curve that reads one, meets that member's refusal, "curve not set up yet"; the penalties run once every member is set up. QuantLib's guess function takes the times and data, and prices nothing.

The additional variables (AdditionalVariables) are optimized beside the nodes, the argument's values for the nodes first and then the variables', from their guesses. The helpers that read them are built by VariableHelpers from their values: once at their guesses when the curve is built, which gives their pillars and latest relevant dates, and again at each evaluation of the cost function, as QuantLib's helpers read their quotes then. They follow the curve's helpers, in the order the function returns them: the alive ones add their pillars and their quote errors, after the curve's helpers' and before the penalties, and the instrument weights cover the curve's helpers and then these, one weight each, as QuantLib's error vector reads its instruments in their order, the variables' helpers among them. A later build whose helpers' pillars differ from the first's is refused, as QuantLib fixes the pillars when the bootstrap starts. The curve keeps the variables' values at the optimum (AdditionalVariables), where QuantLib leaves them in its quotes.

The guess is the initial-guess function's when given, which is called once per curve built and sees no data, as QuantLib's sees none on a curve with no previous state; otherwise the traits' guess for the whole curve (GlobalGuess(BootstrapState<TTermStructure>, bool)) when they give one, or each node's guess in turn. The traits' transforms (TransformDirect(double, int, BootstrapState<TTermStructure>) and its inverse), when they have them, map the nodes to the unconstrained values the optimizer works on. The curve's nodes are the optimizer's last evaluation, its optimum.

QuantLib builds the target interpolation over every node without updating it, and refuses, with no fallback to linear interpolation, a configuration its construction refuses for that many points (CheckPoints(int)); here it is then built over the first data, so a guess function that prices a helper reads the curve at the traits' initial value, where QuantLib's reads an interpolation it hasn't updated. A curve is always built afresh, so its bootstrap starts from the guess, where QuantLib re-bootstraps a curve whose quotes changed from its previous state: a documented divergence.

Constructors

GlobalBootstrap(double?, OptimizationMethod?, EndCriteria?, IEnumerable<double>?, IEnumerable<IBootstrapHelper>?, IEnumerable<Date>?, Func<IBootstrapState, EvaluationContext, Vector>?, Func<IBootstrapState, EvaluationContext, Vector>?, AdditionalBootstrapVariables?, Func<ImmutableArray<double>, EvaluationContext, ImmutableArray<IBootstrapHelper>>?)

Initializes a new instance of the GlobalBootstrap struct.

public GlobalBootstrap(double? accuracy = null, OptimizationMethod? optimizer = null, EndCriteria? endCriteria = null, IEnumerable<double>? instrumentWeights = null, IEnumerable<IBootstrapHelper>? additionalHelpers = null, IEnumerable<Date>? additionalDates = null, Func<IBootstrapState, EvaluationContext, Vector>? additionalPenalties = null, Func<IBootstrapState, EvaluationContext, Vector>? initialGuessFn = null, AdditionalBootstrapVariables? additionalVariables = null, Func<ImmutableArray<double>, EvaluationContext, ImmutableArray<IBootstrapHelper>>? variableHelpers = null)

Parameters

accuracy double?

The accuracy of the default optimizer and end criteria; null takes the curve's.

optimizer OptimizationMethod

The optimization method; null for Levenberg–Marquardt at the accuracy.

endCriteria EndCriteria

The end criteria; null for 1000 iterations and 10 stationary ones at the accuracy.

instrumentWeights IEnumerable<double>

The weights of the curve's helpers' quote errors, one per helper, alive or not; null or empty for weights of 1.

additionalHelpers IEnumerable<IBootstrapHelper>

Helpers bound to the curve that add no pillar or error term of their own, for the penalties to price; of the curve's kind of term structure.

additionalDates IEnumerable<Date>

Dates added to the curve's nodes; those not after the curve's first date are dropped.

additionalPenalties Func<IBootstrapState, EvaluationContext, Vector>

The additional error terms, from the curve's working state and the context, after the helpers' quote errors.

initialGuessFn Func<IBootstrapState, EvaluationContext, Vector>

The guess for the nodes after the first, from the curve's working state (with no data) and the context, before the traits' inverse transform; it must give a value for every such node. In a multicurve, a helper it prices can't reference a bootstrapped member added after its own curve, or a curve that reads one, whose curve isn't set up yet.

additionalVariables AdditionalBootstrapVariables

The variables optimized beside the nodes, or null for none.

variableHelpers Func<ImmutableArray<double>, EvaluationContext, ImmutableArray<IBootstrapHelper>>

The helpers that read the variables, from their values and the context, after the curve's helpers; of the curve's kind of term structure. null for none.

Exceptions

ArgumentException

An additional helper is null, or an additional date is default(Date).

Properties

AdditionalVariables

Gets the variables optimized beside the nodes, or null for none.

public AdditionalBootstrapVariables? AdditionalVariables { get; }

Property Value

AdditionalBootstrapVariables

VariableHelpers

Gets the function building the helpers that read the variables, from their values and the context, or null for none.

public Func<ImmutableArray<double>, EvaluationContext, ImmutableArray<IBootstrapHelper>>? VariableHelpers { get; }

Property Value

Func<ImmutableArray<double>, EvaluationContext, ImmutableArray<IBootstrapHelper>>

Methods

Calculate<TTermStructure, TTraits, TInterpolator>(BootstrapState<TTermStructure>, TInterpolator, EvaluationContext)

Fills the working state: the dates, times and data of the curve's nodes, its interpolation and maximum date, so that each helper reprices its quote.

public void Calculate<TTermStructure, TTraits, TInterpolator>(BootstrapState<TTermStructure> state, TInterpolator interpolator, EvaluationContext context) where TTermStructure : TermStructure where TTraits : struct, IBootstrapTraits<TTermStructure> where TInterpolator : struct, IInterpolator

Parameters

state BootstrapState<TTermStructure>

The working state of the curve under construction.

interpolator TInterpolator

The curve's interpolator.

context EvaluationContext

The evaluation context the helpers are priced in.

Type Parameters

TTermStructure

The kind of term structure bootstrapped.

TTraits

The curve's traits.

TInterpolator

The curve's interpolator.

Exceptions

ArgumentNullException

An argument is null.

NanoQLException

The instrument weights don't match the curve's helpers and the variables' helpers in number, the curve has fewer nodes than the interpolation requires, the guess function gives fewer values than the curve has nodes after the first, the variables moved a helper's pillar, or the optimizer fails to minimize to the required accuracy.

InvalidCastException

An additional helper or a variable helper isn't a helper of the curve's kind of term structure.