Skip to content

Improve NPV summation accuracy and validate discount rates - #11

Merged
dylanjm merged 1 commit into
mainfrom
cancellation-error-handling
Jul 22, 2026
Merged

Improve NPV summation accuracy and validate discount rates#11
dylanjm merged 1 commit into
mainfrom
cancellation-error-handling

Conversation

@j-bryan

@j-bryan j-bryan commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator
  • Use math.fsum in dcaf.metrics.npv() to preserve small residuals when large offsetting cashflows cause cancellation.
  • Validate discount rates as finite and greater than -1, and document the shared contract for CashFlowStream.npv() and GenerationStream.discounted_sum().
  • Cover cancellation, supported negative rates, domain boundaries, and non-finite inputs across the shared primitive and public stream APIs.

Validation lives in the shared NPV primitive so every consumer enforces the same real-valued rate domain. math.fsum improves reduction accuracy without introducing decimal arithmetic or removing support for finite rates above -1.

Closes #4
Closes #8

@j-bryan
j-bryan requested a review from dylanjm July 22, 2026 18:32

@dylanjm dylanjm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good, documentation is updated, and will catch edge cases with discount rates. Approved to merge.

@dylanjm
dylanjm merged commit 15ad764 into main Jul 22, 2026
1 check passed
@dylanjm
dylanjm deleted the cancellation-error-handling branch July 22, 2026 18:40
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.

Define and validate the supported NPV discount-rate domain Improve NPV accumulation accuracy under cancellation

2 participants