|
QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
|
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< 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... | |
| const Constraint & | constraint () 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... | |
| 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_ |
| Constraint | constraint_ |
| 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 203 of file fittedbonddiscountcurve.hpp.
|
virtualdefault |
|
protected |
constructors
Definition at line 169 of file fittedbonddiscountcurve.cpp.
Here is the call graph for this function:
|
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 333 of file fittedbonddiscountcurve.hpp.
| Integer numberOfIterations | ( | ) | const |
final number of iterations used in the optimization problem
Definition at line 319 of file fittedbonddiscountcurve.hpp.
| Real minimumCostValue | ( | ) | const |
final value of cost function after optimization
Definition at line 324 of file fittedbonddiscountcurve.hpp.
| EndCriteria::Type errorCode | ( | ) | const |
error code of the optimization
Definition at line 329 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 337 of file fittedbonddiscountcurve.hpp.
Here is the caller graph for this function:| Array weights | ( | ) | const |
return weights being used
Definition at line 341 of file fittedbonddiscountcurve.hpp.
| Array l2 | ( | ) | const |
return l2 penalties being used
Definition at line 345 of file fittedbonddiscountcurve.hpp.
| ext::shared_ptr< OptimizationMethod > optimizationMethod | ( | ) | const |
return optimization method being used
Definition at line 350 of file fittedbonddiscountcurve.hpp.
| const Constraint & constraint | ( | ) | const |
return optimization contraint
Definition at line 354 of file fittedbonddiscountcurve.hpp.
| DiscountFactor discount | ( | const Array & | x, |
| Time | t | ||
| ) | const |
open discountFunction to public
Definition at line 358 of file fittedbonddiscountcurve.hpp.
|
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:
|
protectedpure virtual |
discount function called by FittedBondDiscountCurve
Implemented in ExponentialSplinesFitting, NelsonSiegelFitting, SvenssonFitting, CubicBSplinesFitting, SimplePolynomialFitting, and SpreadFittingMethod.
|
private |
Definition at line 239 of file fittedbonddiscountcurve.cpp.
Here is the call graph for this function:
|
friend |
Definition at line 204 of file fittedbonddiscountcurve.hpp.
|
protected |
constrains discount function to unity at \( T=0 \), if true
Definition at line 250 of file fittedbonddiscountcurve.hpp.
|
protected |
internal reference to the FittedBondDiscountCurve instance
Definition at line 252 of file fittedbonddiscountcurve.hpp.
|
protected |
solution array found from optimization, set in calculate()
Definition at line 254 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 259 of file fittedbonddiscountcurve.hpp.
|
protected |
base class sets this cost function used in the optimization routine
Definition at line 261 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 266 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 268 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 270 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 273 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 275 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 277 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 279 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 281 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 283 of file fittedbonddiscountcurve.hpp.
|
private |
Definition at line 283 of file fittedbonddiscountcurve.hpp.