diff --git a/ql/termstructures/yield/fittedbonddiscountcurve.cpp b/ql/termstructures/yield/fittedbonddiscountcurve.cpp index f4513700d44..fba963e602e 100644 --- a/ql/termstructures/yield/fittedbonddiscountcurve.cpp +++ b/ql/termstructures/yield/fittedbonddiscountcurve.cpp @@ -19,7 +19,6 @@ */ #include -#include #include #include #include @@ -123,10 +122,11 @@ namespace QuantLib { ext::shared_ptr optimizationMethod, Array l2, const Real minCutoffTime, - const Real maxCutoffTime) + const Real maxCutoffTime, + Constraint constraint) : constrainAtZero_(constrainAtZero), weights_(weights), l2_(std::move(l2)), calculateWeights_(weights.empty()), optimizationMethod_(std::move(optimizationMethod)), - minCutoffTime_(minCutoffTime), maxCutoffTime_(maxCutoffTime) {} + minCutoffTime_(minCutoffTime), maxCutoffTime_(maxCutoffTime), constraint_(constraint) {} void FittedBondDiscountCurve::FittingMethod::init() { // yield conventions @@ -178,7 +178,6 @@ namespace QuantLib { void FittedBondDiscountCurve::FittingMethod::calculate() { FittingCost& costFunction = *costFunction_; - Constraint constraint = NoConstraint(); // start with the guess solution, if it exists Array x(size(), 0.0); @@ -210,7 +209,7 @@ namespace QuantLib { if(!optimization){ optimization = ext::make_shared(curve_->simplexLambda_); } - Problem problem(costFunction, constraint, x); + Problem problem(costFunction, constraint_, x); Real rootEpsilon = curve_->accuracy_; Real functionEpsilon = curve_->accuracy_; diff --git a/ql/termstructures/yield/fittedbonddiscountcurve.hpp b/ql/termstructures/yield/fittedbonddiscountcurve.hpp index eb06165819e..f3ea2b99319 100644 --- a/ql/termstructures/yield/fittedbonddiscountcurve.hpp +++ b/ql/termstructures/yield/fittedbonddiscountcurve.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -203,6 +204,8 @@ namespace QuantLib { Array l2() const; //! return optimization method being used ext::shared_ptr optimizationMethod() const; + //! return constraint of the solution being used + Constraint constraint() const; //! open discountFunction to public DiscountFactor discount(const Array& x, Time t) const; protected: @@ -213,7 +216,8 @@ namespace QuantLib { ext::shared_ptr(), Array l2 = Array(), Real minCutoffTime = 0.0, - Real maxCutoffTime = QL_MAX_REAL); + Real maxCutoffTime = QL_MAX_REAL, + Constraint constraint = NoConstraint{}); //! rerun every time instruments/referenceDate changes virtual void init(); //! discount function called by FittedBondDiscountCurve @@ -253,6 +257,8 @@ namespace QuantLib { ext::shared_ptr optimizationMethod_; // flat extrapolation of instantaneous forward before / after cutoff Real minCutoffTime_, maxCutoffTime_; + // constraint for the solution + Constraint constraint_; }; // inline @@ -323,6 +329,11 @@ namespace QuantLib { return optimizationMethod_; } + inline Constraint + FittedBondDiscountCurve::FittingMethod::constraint() const { + return constraint_; + } + inline DiscountFactor FittedBondDiscountCurve::FittingMethod::discount(const Array& x, Time t) const { if (t < minCutoffTime_) { // flat fwd extrapolation before min cutoff time