31 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
33 const Real minCutoffTime,
34 const Real maxCutoffTime,
36 const Real fixedKappa,
39 minCutoffTime, maxCutoffTime,
std::move(constraint)),
40 numCoeffs_(numCoeffs), fixedKappa_(fixedKappa) {
47 const Array& l2,
const Real minCutoffTime,
const Real maxCutoffTime,
48 const Size numCoeffs,
const Real fixedKappa,
51 minCutoffTime, maxCutoffTime,
52 numCoeffs, fixedKappa, std::move(constraint)) {}
57 const Real fixedKappa,
62 numCoeffs, fixedKappa, std::move(constraint)) {}
64 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
66 return std::make_unique<ExponentialSplinesFitting>(*
this);
84 for (
Size i = 0; i < N - 1; ++i) {
85 d += x[i] * std::exp(-
kappa * (i + 1) *
t);
91 for (
Size i = 0; i < N - 1; i++) {
92 d += x[i] * std::exp(-
kappa * (i + 2) *
t);
96 d += coeff * std::exp(-
kappa *
t);
104 const Array& weights,
105 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
107 const Real minCutoffTime,
108 const Real maxCutoffTime,
111 minCutoffTime, maxCutoffTime,
std::move(constraint)) {}
114 const Array& weights,
116 const Real minCutoffTime,
117 const Real maxCutoffTime,
120 minCutoffTime, maxCutoffTime, std::move(constraint)) {}
122 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
124 return std::make_unique<NelsonSiegelFitting>(*
this);
134 Real zeroRate = x[0] + (x[1] + x[2])*
135 (1.0 - std::exp(-
kappa*
t))/
137 (x[2])*std::exp(-
kappa*
t);
144 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
146 const Real minCutoffTime,
147 const Real maxCutoffTime,
150 minCutoffTime, maxCutoffTime,
std::move(constraint)) {}
154 const Real minCutoffTime,
155 const Real maxCutoffTime,
158 minCutoffTime, maxCutoffTime, std::move(constraint)) {}
160 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
162 return std::make_unique<SvenssonFitting>(*
this);
174 Real zeroRate = x[0] + (x[1] + x[2])*
175 (1.0 - std::exp(-
kappa*
t))/
177 (x[2])*std::exp(-
kappa*
t) +
185 const std::vector<Time>& knots,
186 bool constrainAtZero,
187 const Array& weights,
188 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
190 const Real minCutoffTime,
191 const Real maxCutoffTime,
194 minCutoffTime, maxCutoffTime,
std::move(constraint)),
195 splines_(3, knots.size() - 5, knots) {
198 "At least 8 knots are required" );
199 Size basisFunctions = knots.size() - 4;
202 size_ = basisFunctions-1;
209 "N_th cubic B-spline must be nonzero at t=0");
211 size_ = basisFunctions;
217 const std::vector<Time>& knots,
218 bool constrainAtZero,
219 const Array& weights,
221 const Real minCutoffTime,
222 const Real maxCutoffTime,
225 minCutoffTime, maxCutoffTime, std::move(constraint)) {}
231 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
233 return std::make_unique<CubicBSplinesFitting>(*
this);
260 Real coeff = 1.0 - sum;
271 bool constrainAtZero,
272 const Array& weights,
273 const ext::shared_ptr<OptimizationMethod>& optimizationMethod,
275 const Real minCutoffTime,
276 const Real maxCutoffTime,
279 minCutoffTime, maxCutoffTime,
std::move(constraint)),
280 size_(constrainAtZero ? degree : degree + 1) {}
284 bool constrainAtZero,
285 const Array& weights,
287 const Real minCutoffTime,
288 const Real maxCutoffTime,
291 minCutoffTime, maxCutoffTime, std::move(constraint)) {}
293 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
295 return std::make_unique<SimplePolynomialFitting>(*
this);
319 const Real minCutoffTime,
320 const Real maxCutoffTime)
322 method != nullptr ? method->constrainAtZero() : true,
323 method != nullptr ? method->weights() :
Array(),
324 method != nullptr ? method->optimizationMethod() : ext::shared_ptr<
OptimizationMethod>(),
325 method != nullptr ? method->l2() :
Array(),
328 method_(method), discountingCurve_(
std::move(discountCurve)) {
329 QL_REQUIRE(method,
"Fitting method is empty");
333 std::unique_ptr<FittedBondDiscountCurve::FittingMethod>
335 return std::make_unique<SpreadFittingMethod>(*
this);
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.
DiscountFactor discountFunction(const Array &x, Time t) const override
discount function called by FittedBondDiscountCurve
CubicBSplinesFitting(const std::vector< Time > &knotVector, bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod={}, const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Constraint constraint=NoConstraint())
Exponential-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
ExponentialSplinesFitting(bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod={}, const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Size numCoeffs=9, Real fixedKappa=Null< Real >(), Constraint constraint=NoConstraint())
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={}, const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Constraint constraint=NoConstraint())
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
SimplePolynomialFitting(Natural degree, bool constrainAtZero=true, const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod={}, const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Constraint constraint=NoConstraint())
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
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
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
SvenssonFitting(const Array &weights=Array(), const ext::shared_ptr< OptimizationMethod > &optimizationMethod={}, const Array &l2=Array(), Real minCutoffTime=0.0, Real maxCutoffTime=QL_MAX_REAL, Constraint constraint=NoConstraint())
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