Skip to content

Fix notional-dependent implied quotes and the PCHIP/Akima fit seed; add solve_kwargs - #322

Merged
alecloudenback merged 12 commits into
masterfrom
fix/rereview-2026-09-24
Oct 1, 2026
Merged

alecloudenback merged 12 commits into
masterfrom
fix/rereview-2026-09-24

Conversation

@alecloudenback

@alecloudenback alecloudenback commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Merge map (updated 2026-10-01)

Part of the coordinated FinanceCore 2.8, FinanceModels 7.0, ActuaryUtilities 6.0 and MortalityTables 3.0 releases. Merge each stack bottom-up with Create a merge commit. Automatic branch deletion is on, so after each merge GitHub retargets the next PR onto the default branch: check that its base says master and let its CI finish before merging it.

Order Package Merged Open, merge left to right Then
1 FinanceCore #56 — 2.8.0 registered (2026-09-30)
2 FinanceModels #311, #314, #295, #308, #315, #316 #327 → #317 → #318 → #319 → #320 → #322 → #323 → #324 → #325 → #326 (#315 and #316 were merged into stacked branches, not master; #327 lands them) register 7.0.0
3 ActuaryUtilities — #161 (includes #160's change, so #160 is closed; merges after FinanceModels 7.0.0 is registered) register 6.0.0
any MortalityTables #136, #137, #138, #139, #140, #141 #152 → #142 → #143 → #144 → #145 → #146 → #147 → #149 → #151 → #148 (#138–#141 were merged into stacked branches, not master; #152 lands them. Independent of the other three) register 3.0.0

This PR: FinanceModels #322, number 6 of 10 open (base #320; next #323).


Updated 2026-09-27. One commit from the published-stack review (review-artifacts/2026-09-26-published-review/):

  • An empty untyped knot input reaches the grid's own check (f821970). beebe8b removed the duplicate empty-input checks, so fit(spline, [], Fit.Bootstrap()) failed in __owned_float_vector's empty-collection mapreduce before KnotGrid's length check ran. That native error is a MethodError on Julia 1.10 and an ArgumentError on 1.12, so the bootstrap test failed on the minimum-version and Downgrade jobs. Promotion now starts from Bool, which every real type absorbs, so an empty input becomes Float64[], and the grid raises its own ArgumentError on every supported version.

Full suite: 6,294 tests pass on Julia 1.10.10 and 1.12.5.


Updated 2026-09-26. Seven commits follow the 2026-09-25 fixes rereview and a scrub of guards that duplicated or rewrapped natural errors:

  • Primal first-tenor check (dcae235): KnotGrid compares the first tenor by its primal value, as the ordering check already did. A knot at t = 0 carrying a negative partial was rejected as negative.
  • FX fit keywords (f6717e9): fit(::FX.Forwards, quotes, method; kwargs...) passes optimizer, solve_kwargs and extrapolation to the foreign-curve fit. Keyword calls used to fall through to the generic fit and fail in __default_optic.
  • Notional independence of bootstrap (a6c63e9): zero-coupon and coupon quotes scaled by 1e-12, 1 and 1e10 bootstrap to the zero rates they were priced from.
  • One check per invariant (beebe8b): KnotGrid owns the knot-grid rules and __build_tail owns the extrapolation policy.
    • The sampling form of ZeroRateCurve, bootstrap and __owned_float_vector no longer repeat or rewrap them.
    • A sampling tenor of 0 now takes the source curve's zero-rate limit, as the direct form does.
    • Non-numeric knots and non-Symbol policies raise the natural MethodError.
  • Natural misuse errors (04d820d): FlatForwardAt(0.035), patching a derived cache through Accessors, and writing to a knot vector raise Julia's own MethodError or CanonicalIndexError, not custom ArgumentErrors.
  • Documentation (c1c4442): spline order reduction on short grids is documented. The FitConvergenceError example that silently refitted with Spline.Linear() is removed.
  • discount(curve, Inf) under :extension (f84f698): throws a DomainError (unsupported) instead of returning NaN.

The dual-closure check in implied_quote stays. Without it, three of four closing families failed with a cryptic Float64(::Dual) inside Roots. The fourth (a dual maturity) matched finite differences only because AD ran through the solver iterations.


Stacked on #320. Review against fix/interpolation-kinks. These are the fixes from an ecosystem-wide rereview of the FM 7 stack (September 24, 2026).

implied_quote was notional-dependent for nonlinear quotes. The root solvers stopped on an absolute residual, and the new scale-aware check ran only after a root had been accepted. For an annual-effective zero-coupon quote with notional 1e-10, the implied rate was about 1e-5 off; at 1e-14 it came back as the starting guess. The existing notional tests used an affine price quote, which this problem doesn't affect.

  • The residual is now normalized by the quote's size at the guess.
  • __implicit_root checks that the accepted root's residual is at most sqrt(eps) times the scale. The swaption critical rate gets the same check.
  • New tests: two nonlinear families at notionals 1e-14 through 1e10, for both the value and its derivative.

PCHIP/Akima fit seed. Loss fits started from knot rates linear in the knot number. On evenly spaced maturities those are collinear: Akima switches formula there and the loss derivatives are NaN, so fit(Spline.Akima(), CMTYield.(0.02 .+ 0.001 .* t.^2, t)) with t = 1:8 failed to converge.

  • PCHIP and Akima now start from a curve that is strictly increasing and concave in the maturities.
  • A test checks that the seed is away from every kink quantity in Kinks.jl on regular, irregular and zero-first-knot grids, and that the loss has finite gradients and Hessians there. A quadratic seed that is flat at the first knot would have hit PCHIP's d == 0 switch.
  • Other interpolants keep their seeds.

solve_kwargs for fit. The differentiated-fit error told users to tighten the optimizer, but fit couldn't pass solver settings. Optimizer-backed fits now take solve_kwargs = (;), passed verbatim to Optimization.solve, for example (; maxiters = 10_000, g_tol = 1e-12). The error message names it.

Downstream runs ActuaryUtilities' own suite. The job ran only FinanceModels' 12 integration checks. It now also runs Pkg.test("ActuaryUtilities") in the same environment, against this FinanceModels. ActuaryUtilities' FinanceModels compat is set to this version's major instead of being deleted, so its Aqua compat check passes. Locally, both steps pass at this tip.

Smaller fixes:

  • Knot-grid validation compares primal tenors: ForwardDiff orders Duals with equal values by their partials, so a duplicated tenor could pass.
  • The calibration docs no longer put reconstruct in the first-order-only rule. A reconstructed curve has derivatives of any order away from kinks.

🤖 Generated with Claude Code

alecloudenback and others added 11 commits September 25, 2026 08:15
The root solvers stopped on an absolute residual, and the scale-aware check ran only
after a root was accepted. A nonlinear quote with a notional of 1e-10 was implied about
1e-5 off, and at 1e-14 the starting guess came back. implied_quote now solves the
residual relative to the quote's size at the guess, and __implicit_root checks that the
residual at an accepted root is at most sqrt(eps) times the scale (this also covers the
swaption critical rate).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ForwardDiff orders Duals with equal values by their partials, so a duplicated tenor
carrying different partials passed the strictly-increasing check.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… the optimizer

PCHIP and Akima loss fits started from rates linear in the knot number, which are
collinear on evenly spaced maturities: Akima switches formula there and the loss
derivatives are NaN, so a coupon-bearing Akima fit on 1:8 failed to converge. They now
start from a curve strictly increasing and concave in the maturities; a test checks the
seed against every kink quantity on several grids.

The differentiated-fit error told users to tighten the optimizer, but fit could not pass
solver settings. Optimizer-backed fits now take solve_kwargs, passed verbatim to
Optimization.solve, and the error names it.

The calibration docs no longer put reconstruct in the first-order-only rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The job ran only FinanceModels' 12 integration checks. It now also runs ActuaryUtilities'
full suite against this FinanceModels, through the same environment. ActuaryUtilities'
FinanceModels compat is set to this version's major instead of deleted, so its Aqua compat
check passes and a 6.x master still resolves.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The ordering check already compares primal values, because ForwardDiff orders Duals with equal
values by their partials. The first tenor's sign check did not, so a knot at t = 0 carrying a
negative partial was rejected as a negative tenor.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
fit(::FX.Forwards, quotes, method) had no keyword arguments, so a call with optimizer,
solve_kwargs or extrapolation skipped it and failed inside the generic optic fit. Both methods
now pass their keywords to the foreign-curve fit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
Zero-coupon and coupon quotes scaled by 1e-12, 1 and 1e10 bootstrap to the zero rates they were
priced from. implied_quote already has the same notional sweep for its value and derivative.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
KnotGrid owns the knot-grid rules and __build_tail owns the extrapolation policy; the copies
elsewhere are removed:
- the sampling form of ZeroRateCurve re-checked finite, positive and distinct tenors and the knot
  count before KnotGrid checked them again. A tenor of 0 now takes the source curve's zero-rate
  limit, as in the direct form; a curve without one gives a non-finite rate, which KnotGrid
  rejects. This also removes a Dual comparison that accepted Dual(0, 1) as positive;
- bootstrap keeps only its own rule, that quotes mature after t = 0 (a knot there is not
  identified); KnotGrid rejects empty, non-finite and duplicate maturities;
- __owned_float_vector no longer rewraps the conversion's MethodError or InexactError in an
  ArgumentError. KnotGrid checks the knot count first, and the tenors before the rates;
- the extrapolation policy is checked where the tail is built, with one message that also covers
  :extension on MonotoneConvex; a policy of another type is a MethodError;
- the differentiated fit's one-knot-per-quote check could not fail (the knots are the quote
  maturities). Two comments that misdescribed the kink checks are corrected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
…patches and read-only knots

Three errors only restated an error Julia raises on its own:
- FlatForwardAt(::Real) threw an ArgumentError; without the method, the MethodError names the
  FlatForwardAt(::Rate) candidate;
- setproperties rejected unknown keys before calling reconstruct, whose keywords are exactly the
  settable properties, so a cache patch is now reconstruct's MethodError;
- ReadOnlyVector defined setindex! only to throw, and hid its field from getproperty. Without
  them, indexed assignment raises Base's CanonicalIndexError, and _data is an ordinary internal
  field.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
- A polynomial or B-spline on k knots interpolates at order min(n, k - 1), so a cubic fit to two
  quotes is linear and one knot is flat. That rule was only a code comment; it is now in the
  Spline.PolynomialSpline, BSpline, Quadratic and Cubic, ZeroRateCurve and fit docstrings (the
  B-spline's uniform knot vector below three knots too).
- The FitConvergenceError example caught the error and refitted with Spline.Linear(), silently
  changing the curve. The docstring now says to address the cause (model, optimizer,
  solve_kwargs, quotes) and to choose the method deliberately.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
The :extension policy evaluates DataInterpolations' continuation of the last piece at every time,
including Inf, where even a flat extension computes 0 * Inf. discount(curve, Inf) now throws a
DomainError saying infinite-time evaluation is unsupported for that policy (a flat positive
extension does have a limit, 0; the other policies return their tail limits). zero(curve, Inf)
keeps its documented legacy value.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
`__owned_float_vector` promoted a non-concrete input's element types with an
empty-collection `mapreduce`, so `fit(spline, [], Fit.Bootstrap())` failed there
before `KnotGrid`'s length check ran. That native error is a MethodError on
Julia 1.10 and an ArgumentError on 1.12, so the bootstrap test failed on the
minimum-version and Downgrade jobs. Starting the promotion from `Bool`, which
every real type absorbs, gives an empty input `Float64[]`, and the grid's own
check raises its ArgumentError on every supported version.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nw2FiivhYrC16532c1mJQN
Base automatically changed from fix/interpolation-kinks to master October 1, 2026 13:39
@alecloudenback
alecloudenback merged commit a1e6413 into master Oct 1, 2026
9 checks passed
@alecloudenback
alecloudenback deleted the fix/rereview-2026-09-24 branch October 1, 2026 13:41
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.

1 participant