QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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 <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...
 
const Constraintconstraint () const
 return optimization contraint 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, Constraint constraint=NoConstraint())
 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_
 
Constraint constraint_
 
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 203 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,
Constraint  constraint = NoConstraint() 
)
protected

constructors

Definition at line 169 of file fittedbonddiscountcurve.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ size()

virtual Size size ( ) const
pure virtual

◆ solution()

Array solution ( ) const

output array of results of optimization problem

Definition at line 333 of file fittedbonddiscountcurve.hpp.

◆ numberOfIterations()

Integer numberOfIterations ( ) const

final number of iterations used in the optimization problem

Definition at line 319 of file fittedbonddiscountcurve.hpp.

◆ minimumCostValue()

Real minimumCostValue ( ) const

final value of cost function after optimization

Definition at line 324 of file fittedbonddiscountcurve.hpp.

◆ errorCode()

EndCriteria::Type errorCode ( ) const

error code of the optimization

Definition at line 329 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 337 of file fittedbonddiscountcurve.hpp.

+ Here is the caller graph for this function:

◆ weights()

Array weights ( ) const

return weights being used

Definition at line 341 of file fittedbonddiscountcurve.hpp.

◆ l2()

Array l2 ( ) const

return l2 penalties being used

Definition at line 345 of file fittedbonddiscountcurve.hpp.

◆ optimizationMethod()

ext::shared_ptr< OptimizationMethod > optimizationMethod ( ) const

return optimization method being used

Definition at line 350 of file fittedbonddiscountcurve.hpp.

◆ constraint()

const Constraint & constraint ( ) const

return optimization contraint

Definition at line 354 of file fittedbonddiscountcurve.hpp.

◆ discount()

DiscountFactor discount ( const Array x,
Time  t 
) const

open discountFunction to public

Definition at line 358 of file fittedbonddiscountcurve.hpp.

◆ init()

void init ( )
protectedvirtual

rerun every time instruments/referenceDate changes

Reimplemented in SpreadFittingMethod.

Definition at line 185 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 239 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 204 of file fittedbonddiscountcurve.hpp.

Member Data Documentation

◆ constrainAtZero_

bool constrainAtZero_
protected

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

Definition at line 250 of file fittedbonddiscountcurve.hpp.

◆ curve_

FittedBondDiscountCurve* curve_
protected

internal reference to the FittedBondDiscountCurve instance

Definition at line 252 of file fittedbonddiscountcurve.hpp.

◆ solution_

Array solution_
protected

solution array found from optimization, set in calculate()

Definition at line 254 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 259 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 261 of file fittedbonddiscountcurve.hpp.

◆ weights_

Array weights_
private

Definition at line 266 of file fittedbonddiscountcurve.hpp.

◆ l2_

Array l2_
private

Definition at line 268 of file fittedbonddiscountcurve.hpp.

◆ calculateWeights_

bool calculateWeights_
private

Definition at line 270 of file fittedbonddiscountcurve.hpp.

◆ numberOfIterations_

Integer numberOfIterations_
private

Definition at line 273 of file fittedbonddiscountcurve.hpp.

◆ costValue_

Real costValue_
private

Definition at line 275 of file fittedbonddiscountcurve.hpp.

◆ errorCode_

EndCriteria::Type errorCode_ = EndCriteria::None
private

Definition at line 277 of file fittedbonddiscountcurve.hpp.

◆ optimizationMethod_

ext::shared_ptr<OptimizationMethod> optimizationMethod_
private

Definition at line 279 of file fittedbonddiscountcurve.hpp.

◆ constraint_

Constraint constraint_
private

Definition at line 281 of file fittedbonddiscountcurve.hpp.

◆ minCutoffTime_

Real minCutoffTime_
private

Definition at line 283 of file fittedbonddiscountcurve.hpp.

◆ maxCutoffTime_

Real maxCutoffTime_
private

Definition at line 283 of file fittedbonddiscountcurve.hpp.