QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
FittedBondDiscountCurve::FittingMethod Class Referenceabstract

Base fitting method used to construct a fitted bond discount curve. More...

#include <ql/termstructures/yield/fittedbonddiscountcurve.hpp>

+ Inheritance diagram for FittedBondDiscountCurve::FittingMethod:
+ Collaboration diagram for FittedBondDiscountCurve::FittingMethod:

Public Member Functions

virtual ~FittingMethod ()=default
 
virtual Size size () const =0
 total number of coefficients to fit/solve for More...
 
Array solution () const
 output array of results of optimization problem More...
 
Integer numberOfIterations () const
 final number of iterations used in the optimization problem More...
 
Real minimumCostValue () const
 final value of cost function after optimization More...
 
EndCriteria::Type errorCode () const
 error code of the optimization More...
 
virtual std::unique_ptr< FittingMethodclone () const =0
 clone of the current object More...
 
bool constrainAtZero () const
 return whether there is a constraint at zero More...
 
Array weights () const
 return weights being used More...
 
Array l2 () const
 return l2 penalties being used More...
 
ext::shared_ptr< OptimizationMethodoptimizationMethod () const
 return optimization method being used More...
 
DiscountFactor discount (const Array &x, Time t) const
 open discountFunction to public More...
 

Protected Member Functions

 FittingMethod (bool constrainAtZero=true, const Array &weights=Array(), ext::shared_ptr< OptimizationMethod > optimizationMethod=ext::shared_ptr< OptimizationMethod >(), Array l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
 constructors More...
 
virtual void init ()
 rerun every time instruments/referenceDate changes More...
 
virtual DiscountFactor discountFunction (const Array &x, Time t) const =0
 discount function called by FittedBondDiscountCurve More...
 

Protected Attributes

bool constrainAtZero_
 constrains discount function to unity at \( T=0 \), if true More...
 
FittedBondDiscountCurvecurve_
 internal reference to the FittedBondDiscountCurve instance More...
 
Array solution_
 solution array found from optimization, set in calculate() More...
 
Array guessSolution_
 optional guess solution to be passed into constructor. More...
 
ext::shared_ptr< FittingCost > costFunction_
 base class sets this cost function used in the optimization routine More...
 

Private Member Functions

void calculate ()
 

Private Attributes

Array weights_
 
Array l2_
 
bool calculateWeights_
 
Integer numberOfIterations_
 
Real costValue_
 
EndCriteria::Type errorCode_ = EndCriteria::None
 
ext::shared_ptr< OptimizationMethodoptimizationMethod_
 
Real minCutoffTime_
 
Real maxCutoffTime_
 

Friends

class FittedBondDiscountCurve
 

Detailed Description

Base fitting method used to construct a fitted bond discount curve.

This base class provides the specific methodology/strategy used to construct a FittedBondDiscountCurve. Derived classes need only define the virtual function discountFunction() based on the particular fitting method to be implemented, as well as size(), the number of variables to be solved for/optimized. The generic fitting methodology implemented here can be termed nonlinear, in contrast to (typically faster, computationally) linear fitting method.

Optional parameters for FittingMethod include an Array of weights, which will be used as weights to each bond. If not given or empty, then the bonds will be weighted by inverse duration

An optional Array may be provided as an L2 regularizor in this case a L2 (gaussian) penalty is applied to each parameter starting from the initial guess. This is the same as giving a Gaussian prior on the parameters

\[ d(t) = \sum_{i=0} c_i b_i(t) \]

i.e., linear in the unknown coefficients \( c_i \). Such a fitting can be reduced to a linear algebra problem \( Ax = b \), and for large numbers of bonds, would typically be much faster computationally than the generic non-linear fitting method.

Warning:
some parameters to the Simplex optimization method may need to be tweaked internally to the class, depending on the fitting method used, in order to get proper/reasonable/faster convergence.

Definition at line 180 of file fittedbonddiscountcurve.hpp.

Constructor & Destructor Documentation

◆ ~FittingMethod()

virtual ~FittingMethod ( )
virtualdefault

◆ FittingMethod()

FittingMethod ( bool  constrainAtZero = true,
const Array weights = Array(),
ext::shared_ptr< OptimizationMethod optimizationMethod = ext::shared_ptr<OptimizationMethod>(),
Array  l2 = Array(),
Real  minCutoffTime = 0.0,
Real  maxCutoffTime = QL_MAX_REAL 
)
protected

constructors

Definition at line 120 of file fittedbonddiscountcurve.cpp.

Member Function Documentation

◆ size()

virtual Size size ( ) const
pure virtual

◆ solution()

Array solution ( ) const

output array of results of optimization problem

Definition at line 305 of file fittedbonddiscountcurve.hpp.

◆ numberOfIterations()

Integer numberOfIterations ( ) const

final number of iterations used in the optimization problem

Definition at line 291 of file fittedbonddiscountcurve.hpp.

◆ minimumCostValue()

Real minimumCostValue ( ) const

final value of cost function after optimization

Definition at line 296 of file fittedbonddiscountcurve.hpp.

◆ errorCode()

EndCriteria::Type errorCode ( ) const

error code of the optimization

Definition at line 301 of file fittedbonddiscountcurve.hpp.

◆ clone()

virtual std::unique_ptr< FittingMethod > clone ( ) const
pure virtual

◆ constrainAtZero()

bool constrainAtZero ( ) const

return whether there is a constraint at zero

Definition at line 309 of file fittedbonddiscountcurve.hpp.

+ Here is the caller graph for this function:

◆ weights()

Array weights ( ) const

return weights being used

Definition at line 313 of file fittedbonddiscountcurve.hpp.

◆ l2()

Array l2 ( ) const

return l2 penalties being used

Definition at line 317 of file fittedbonddiscountcurve.hpp.

◆ optimizationMethod()

ext::shared_ptr< OptimizationMethod > optimizationMethod ( ) const

return optimization method being used

Definition at line 322 of file fittedbonddiscountcurve.hpp.

◆ discount()

DiscountFactor discount ( const Array x,
Time  t 
) const

open discountFunction to public

Definition at line 326 of file fittedbonddiscountcurve.hpp.

◆ init()

void init ( )
protectedvirtual

rerun every time instruments/referenceDate changes

Reimplemented in SpreadFittingMethod.

Definition at line 131 of file fittedbonddiscountcurve.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ discountFunction()

virtual DiscountFactor discountFunction ( const Array x,
Time  t 
) const
protectedpure virtual

◆ calculate()

void calculate ( )
private

Definition at line 178 of file fittedbonddiscountcurve.cpp.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ FittedBondDiscountCurve

friend class FittedBondDiscountCurve
friend

Definition at line 181 of file fittedbonddiscountcurve.hpp.

Member Data Documentation

◆ constrainAtZero_

bool constrainAtZero_
protected

constrains discount function to unity at \( T=0 \), if true

Definition at line 224 of file fittedbonddiscountcurve.hpp.

◆ curve_

FittedBondDiscountCurve* curve_
protected

internal reference to the FittedBondDiscountCurve instance

Definition at line 226 of file fittedbonddiscountcurve.hpp.

◆ solution_

Array solution_
protected

solution array found from optimization, set in calculate()

Definition at line 228 of file fittedbonddiscountcurve.hpp.

◆ guessSolution_

Array guessSolution_
protected

optional guess solution to be passed into constructor.

The idea is to use a previous solution as a guess solution to the discount curve, in an attempt to speed up calculations.

Definition at line 233 of file fittedbonddiscountcurve.hpp.

◆ costFunction_

ext::shared_ptr<FittingCost> costFunction_
protected

base class sets this cost function used in the optimization routine

Definition at line 235 of file fittedbonddiscountcurve.hpp.

◆ weights_

Array weights_
private

Definition at line 240 of file fittedbonddiscountcurve.hpp.

◆ l2_

Array l2_
private

Definition at line 242 of file fittedbonddiscountcurve.hpp.

◆ calculateWeights_

bool calculateWeights_
private

Definition at line 244 of file fittedbonddiscountcurve.hpp.

◆ numberOfIterations_

Integer numberOfIterations_
private

Definition at line 247 of file fittedbonddiscountcurve.hpp.

◆ costValue_

Real costValue_
private

Definition at line 249 of file fittedbonddiscountcurve.hpp.

◆ errorCode_

EndCriteria::Type errorCode_ = EndCriteria::None
private

Definition at line 251 of file fittedbonddiscountcurve.hpp.

◆ optimizationMethod_

ext::shared_ptr<OptimizationMethod> optimizationMethod_
private

Definition at line 253 of file fittedbonddiscountcurve.hpp.

◆ minCutoffTime_

Real minCutoffTime_
private

Definition at line 255 of file fittedbonddiscountcurve.hpp.

◆ maxCutoffTime_

Real maxCutoffTime_
private

Definition at line 255 of file fittedbonddiscountcurve.hpp.