Add Finance.Solver.Brent, a derivative-free solver - #23
Merged
Conversation
Brent's method (bracketing secant + inverse-quadratic interpolation + bisection) spends one NPV evaluation per step instead of two, so it is faster on long-horizon flows. Newton stays the default; select Brent with `solver: Finance.Solver.Brent`. Extract the shared bracket and parallel-batch helpers from Newton into Finance.Shared so both solvers reuse them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVibXT2w1dEdVtMHqffFKn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finance.Solver.Brentimplements Brent's method — bracketing secant,inverse-quadratic interpolation, and a bisection safeguard. It uses no
derivative, so each iteration costs a single NPV evaluation rather than the two
(NPV + derivative) that safeguarded Newton spends per step.
That makes it faster on long-horizon flows — long amortization schedules,
bond ladders — where each evaluation is itself expensive. On short series Newton
is quicker, so it stays the default; Brent is opt-in per call
(
solver: Finance.Solver.Brent) or globally (config :finance, solver: ...).The shared bracketing and parallel-batch helpers move from
Finance.Solver.NewtonintoFinance.Shared, so both solvers reuse oneimplementation. Brent is parity-tested against the default across a rate × term
sweep (
assert_in_delta, 1e-7), reproduces the existing xirr anchors, andcovers divergence, arithmetic overflow, negative-zero collapse, and batch
solve_many.Ships as 1.6.0.
🤖 Generated with Claude Code