Repository navigation
Deprecate fitting-method constructors taking constrainAtZero - #3086
Conversation
|
I agree that the curve should be constrained at 1 for t=0, but people might still be getting decent unconstrained curves by passing a L2 term or an additional constraint that makes them well behaved. Instead of starting to reject them via the QL_REQUIRE, I would add constructors that don't take the |
constrainAtZero
|
Thanks, that makes sense. I checked the L2 case and you're right: with an L2 term and a guess that has d(0) = 1, the unconstrained polynomial fit from my example gives d(0) = 0.9991 and a 5-year zero rate of 3.02%, so the check would have broken curves that work. I reworked the PR as you suggested and renamed it:
I left the I also merged master into the branch. |
|
Thanks. I would do the same with the |
|
Done: The fitting methods that always passed |
|
Thanks. I also deprecated the data member and the inspector, let's see what the CI builds say (different compilers might issue warnings in different places, unfortunately). |
With
constrainAtZero = false, fitting aFittedBondDiscountCurvecan't give a usable curve. Bond prices only depend on ratios of discount factors (the NPV is divided by the discount at settlement), so the level of an unconstrained discount function is not determined by the fit. What happens today, on every release I tried from 1.28 to 1.44:SimplePolynomialFitting(3, false)with guess(1, 0, 0, 0)givesd(0) = 3.4875and a 5-year zero rate of -22%, whiled(5)/d(0) = 0.8607is correct.This PR makes the fit raise an error in that case and says why in the class docs. Building a curve from given parameters with
constrainAtZero = falseis not affected (the fixed-kappa test added in #3056 does that and still passes).I went for an error because, once the level is normalized, an unconstrained fit spans the same curves as the constrained one, so nothing is lost by requiring the constraint. If you'd rather keep unconstrained fits working, the alternative is to divide the fitted discount function by its value at t = 0 and to start from a non-null curve; I can change the PR to do that.
A short Python script that reproduces the numbers above:
I used an AI assistant while preparing this and have reviewed and run all of it myself.