Skip to content

Add tests for NaturalCubicFitting and reject negative knot times - #3063

Merged
lballabio merged 2 commits into
lballabio:masterfrom
Allan-dq:natural-cubic-fitting-tests
Nov 14, 2026
Merged

lballabio merged 2 commits into
lballabio:masterfrom
Allan-dq:natural-cubic-fitting-tests

Conversation

@Allan-dq

Copy link
Copy Markdown
Contributor

NaturalCubicFitting (#2378) has no tests in the suite. This adds three cases to fittedbonddiscountcurve.cpp:

  • evaluation: with given parameters, the curve starts at 1, passes through the knots, matches CubicNaturalSpline between them and is flat after the last one; knots can be passed unsorted and with duplicates;
  • knot validation: the errors for too few knots and for a negative knot time;
  • calibration: a fit to ten annual bonds priced off a flat 3% curve stays within 1e-3 of that curve's discount factors and reprices the bonds within 0.05.

While writing them I found that a negative knot time was accepted. The constructor adds t = 0, sorts the knots and pins the discount factor at the first one to 1, so with knots {-1, 1, 2} the constraint moved to t = -1 and d(0) became a free parameter. The constructor now rejects negative knot times.

I also updated the class comment: it mentioned a constrainAtZero argument that the class does not have, and did not say that the curve is flat after the last knot.

The calibration tolerances leave room over what I measured (2.7e-4 and 0.011 at most over 450 evaluation dates between 2015 and 2030).

I used an AI assistant while preparing this and have reviewed and run all of it myself.

@boring-cyborg

boring-cyborg Bot commented Nov 12, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! It might take a while before we look at it, so don't worry if there seems to be no feedback. We'll get to it.

@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coveralls

coveralls commented Nov 13, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 80.094%. remained the same — Allan-dq:natural-cubic-fitting-tests into lballabio:master

@Allan-dq
Allan-dq force-pushed the natural-cubic-fitting-tests branch from bc938ae to a49ed03 Compare November 13, 2026 19:15
@lballabio
lballabio merged commit ab984dd into lballabio:master Nov 14, 2026
46 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 14, 2026

Copy link
Copy Markdown

Congratulations on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants