QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
|
Base fitting method used to construct a fitted bond discount curve. More...
#include <ql/termstructures/yield/fittedbonddiscountcurve.hpp>
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< FittingMethod > | clone () 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< OptimizationMethod > | optimizationMethod () 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... | |
FittedBondDiscountCurve * | curve_ |
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< OptimizationMethod > | optimizationMethod_ |
Real | minCutoffTime_ |
Real | maxCutoffTime_ |
Friends | |
class | FittedBondDiscountCurve |
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.
Definition at line 180 of file fittedbonddiscountcurve.hpp.
|
virtualdefault |
|
protected |
constructors
Definition at line 120 of file fittedbonddiscountcurve.cpp.
|
pure virtual |
total number of coefficients to fit/solve for
Implemented in ExponentialSplinesFitting, NelsonSiegelFitting, SvenssonFitting, CubicBSplinesFitting, SimplePolynomialFitting, and SpreadFittingMethod.
Array solution | ( | ) | const |
output array of results of optimization problem
Definition at line 305 of file fittedbonddiscountcurve.hpp.
Integer numberOfIterations | ( | ) | const |
final number of iterations used in the optimization problem
Definition at line 291 of file fittedbonddiscountcurve.hpp.
Real minimumCostValue | ( | ) | const |
final value of cost function after optimization
Definition at line 296 of file fittedbonddiscountcurve.hpp.
EndCriteria::Type errorCode | ( | ) | const |
error code of the optimization
Definition at line 301 of file fittedbonddiscountcurve.hpp.
|
pure virtual |
clone of the current object
Implemented in ExponentialSplinesFitting, NelsonSiegelFitting, SvenssonFitting, CubicBSplinesFitting, SimplePolynomialFitting, and SpreadFittingMethod.
bool constrainAtZero | ( | ) | const |
return whether there is a constraint at zero
Definition at line 309 of file fittedbonddiscountcurve.hpp.
Array weights | ( | ) | const |
return weights being used
Definition at line 313 of file fittedbonddiscountcurve.hpp.
Array l2 | ( | ) | const |
return l2 penalties being used
Definition at line 317 of file fittedbonddiscountcurve.hpp.
ext::shared_ptr< OptimizationMethod > optimizationMethod | ( | ) | const |
return optimization method being used
Definition at line 322 of file fittedbonddiscountcurve.hpp.
DiscountFactor discount | ( | const Array & | x, |
Time | t | ||
) | const |
open discountFunction to public
Definition at line 326 of file fittedbonddiscountcurve.hpp.
|
protectedvirtual |
rerun every time instruments/referenceDate changes
Reimplemented in SpreadFittingMethod.
Definition at line 131 of file fittedbonddiscountcurve.cpp.
|
protectedpure virtual |
discount function called by FittedBondDiscountCurve
Implemented in ExponentialSplinesFitting, NelsonSiegelFitting, SvenssonFitting, CubicBSplinesFitting, SimplePolynomialFitting, and SpreadFittingMethod.
|
private |
Definition at line 178 of file fittedbonddiscountcurve.cpp.
|
friend |
Definition at line 181 of file fittedbonddiscountcurve.hpp.
|
protected |
constrains discount function to unity at \( T=0 \), if true
Definition at line 224 of file fittedbonddiscountcurve.hpp.
|
protected |
internal reference to the FittedBondDiscountCurve instance
Definition at line 226 of file fittedbonddiscountcurve.hpp.
|
protected |
solution array found from optimization, set in calculate()
Definition at line 228 of file fittedbonddiscountcurve.hpp.
|
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.
|
protected |
base class sets this cost function used in the optimization routine
Definition at line 235 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 240 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 242 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 244 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 247 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 249 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 251 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 253 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 255 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 255 of file fittedbonddiscountcurve.hpp.