31 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
33 const Real minCutoffTime,
34 const Real maxCutoffTime,
36 const Real fixedKappa)
38 constrainAtZero, weights, optimizationMethod, l2, minCutoffTime, maxCutoffTime),
39 numCoeffs_(numCoeffs), fixedKappa_(fixedKappa)
46 const Array& l2,
const Real minCutoffTime,
const Real maxCutoffTime,
47 const Size numCoeffs,
const Real fixedKappa)
49 minCutoffTime, maxCutoffTime),
50 numCoeffs_(numCoeffs),fixedKappa_(fixedKappa)
57 const Real fixedKappa,
58 const Array& weights )
60 numCoeffs_(numCoeffs), fixedKappa_(fixedKappa)
65 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
67 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
86 for (
Size i = 0; i < N - 1; ++i) {
87 d += x[i] * std::exp(-
kappa * (i + 1) *
t);
93 for (
Size i = 0; i < N - 1; i++) {
94 d += x[i] * std::exp(-
kappa * (i + 2) *
t);
98 d += coeff * std::exp(-
kappa *
t);
106 const Array& weights,
107 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
109 const Real minCutoffTime,
110 const Real maxCutoffTime)
112 true, weights, optimizationMethod, l2, minCutoffTime, maxCutoffTime) {}
116 const Real minCutoffTime,
const Real maxCutoffTime)
118 minCutoffTime, maxCutoffTime) {}
120 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
122 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
133 Real zeroRate = x[0] + (x[1] + x[2])*
134 (1.0 - std::exp(-
kappa*
t))/
136 (x[2])*std::exp(-
kappa*
t);
143 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
145 const Real minCutoffTime,
146 const Real maxCutoffTime)
148 true, weights, optimizationMethod, l2, minCutoffTime, maxCutoffTime) {}
151 const Array& l2,
const Real minCutoffTime,
const Real maxCutoffTime)
153 minCutoffTime, maxCutoffTime) {}
155 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
157 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
170 Real zeroRate = x[0] + (x[1] + x[2])*
171 (1.0 - std::exp(-
kappa*
t))/
173 (x[2])*std::exp(-
kappa*
t) +
181 const std::vector<Time>& knots,
182 bool constrainAtZero,
183 const Array& weights,
184 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
186 const Real minCutoffTime,
187 const Real maxCutoffTime)
189 constrainAtZero, weights, optimizationMethod, l2, minCutoffTime, maxCutoffTime),
190 splines_(3, knots.size() - 5, knots) {
193 "At least 8 knots are required" );
194 Size basisFunctions = knots.size() - 4;
197 size_ = basisFunctions-1;
204 "N_th cubic B-spline must be nonzero at t=0");
206 size_ = basisFunctions;
212 bool constrainAtZero,
213 const Array& weights,
215 const Real minCutoffTime,
const Real maxCutoffTime)
217 minCutoffTime, maxCutoffTime),
218 splines_(3, knots.size() - 5, knots) {
221 "At least 8 knots are required");
222 Size basisFunctions = knots.size() - 4;
225 size_ = basisFunctions - 1;
232 "N_th cubic B-spline must be nonzero at t=0");
235 size_ = basisFunctions;
244 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
246 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
274 Real coeff = 1.0 - sum;
285 bool constrainAtZero,
286 const Array& weights,
287 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
289 const Real minCutoffTime,
290 const Real maxCutoffTime)
292 constrainAtZero, weights, optimizationMethod, l2, minCutoffTime, maxCutoffTime),
293 size_(constrainAtZero ? degree : degree + 1) {}
297 const Real minCutoffTime,
const Real maxCutoffTime)
300 size_(constrainAtZero ? degree : degree + 1) {}
302 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
304 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
329 const Real minCutoffTime,
330 const Real maxCutoffTime)
332 method != nullptr ? method->constrainAtZero() : true,
333 method != nullptr ? method->weights() :
Array(),
334 method != nullptr ? method->optimizationMethod() : ext::shared_ptr<
OptimizationMethod>(),
335 method != nullptr ? method->l2() :
Array(),
338 method_(method), discountingCurve_(
std::move(discountCurve)) {
339 QL_REQUIRE(method,
"Fitting method is empty");
343 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
345 return std::unique_ptr<FittedBondDiscountCurve::FittingMethod>(
1-D array used in linear algebra.
static Real get(Natural i, Natural n, Real x)
CubicSpline B-splines fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
Real basisFunction(Integer i, Time t) const
cubic B-spline basis functions
Natural N_
N_th basis function coefficient to solve for when d(0)=1.
CubicBSplinesFitting(const std::vector< Time > &knotVector, bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod=ext::shared_ptr< OptimizationMethod >(), const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
Exponential-splines fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
ExponentialSplinesFitting(bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod=ext::shared_ptr< OptimizationMethod >(), const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Size numCoeffs=9, Real fixedKappa=Null< Real >())
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
FittedBondDiscountCurve * curve_
internal reference to the FittedBondDiscountCurve instance
virtual void init()
rerun every time instruments/referenceDate changes
bool constrainAtZero() const
return whether there is a constraint at zero
bool constrainAtZero_
constrains discount function to unity at , if true
Discount curve fitted to a set of fixed-coupon bonds.
Shared handle to an observable.
Nelson-Siegel fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
NelsonSiegelFitting(const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod=ext::shared_ptr< OptimizationMethod >(), const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
template class providing a null value for a given type.
Abstract class for constrained optimization method.
Simple polynomial fitting method.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
SimplePolynomialFitting(Natural degree, bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod=ext::shared_ptr< OptimizationMethod >(), const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
Spread fitting method helper.
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
SpreadFittingMethod(const ext::shared_ptr< FittingMethod > &method, Handle< YieldTermStructure > discountCurve, Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
Handle< YieldTermStructure > discountingCurve_
ext::shared_ptr< FittingMethod > method_
void init() override
rerun every time instruments/referenceDate changes
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
SvenssonFitting(const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod=ext::shared_ptr< OptimizationMethod >(), const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL)
std::unique_ptr< FittedBondDiscountCurve::FittingMethod > clone() const override
clone of the current object
Size size() const override
total number of coefficients to fit/solve for
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
nonlinear methods to fit a bond discount function