-
Notifications
You must be signed in to change notification settings - Fork 146
Add IRR function for calculating internal rate of return #1598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Implement the IRR (Internal Rate of Return) function following Excel specification. IRR calculates the internal rate of return for a series of cash flows represented by the numbers in values. Features: - Takes a range of cash flow values and optional guess parameter - Uses Newton-Raphson method for iterative calculation - Returns #NUM! if algorithm does not converge or values lack both positive and negative values - Returns result as NUMBER_PERCENT type - Includes translations for all 17 built-in languages
Performance comparison of head (c4a4933) vs base (7f856be) |
- Add guess <= -1 validation returning #VALUE! (consistent with RATE) - Add Newton's method comment to irr method - Add tests for guess = -1 and guess < -1 edge cases - Add test for empty range - Add test for named ranges
- Add test for minimum valid cash flow (one positive, one negative) - Add test for negative return rate - Add test for IRR close to zero - Add test for IRR of exactly zero - Add test for initial positive followed by negative cash flows - Add test for alternating positive and negative values - Add test for cell reference update propagation
- Remove upfront guess <= -1 check (was returning #VALUE! incorrectly) - Algorithm can find valid IRR even with guess < -1 (e.g., IRR=-200%) - guess = -1 still returns #NUM! (caught by iteration check) - Refactor positive/negative check to use Array.some() for clarity - Update tests to reflect correct behavior
- Add test for derivative too small condition (line 869)
Uses cash flows {-0.5, 2, -1} with guess=0 where dnpv=0 but npv!=0
- Add test for max iterations reached (line 888)
Uses cash flows {-1, 2, -1.0001} with guess=0.9 causing oscillation
budnix
approved these changes
Jan 8, 2026
Member
budnix
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Found some typos only.
Co-authored-by: Krzysztof ‘Budzio’ Budnik <[email protected]>
budnix
approved these changes
Jan 8, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1598 +/- ##
========================================
Coverage 97.17% 97.17%
========================================
Files 170 170
Lines 14747 14785 +38
Branches 3236 3245 +9
========================================
+ Hits 14330 14368 +38
Misses 409 409
Partials 8 8
🚀 New features to boost your workflow:
|
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.
Context
Implemented with the assist of Claude Code + Claude Opus 4.5
How did you test your changes?
Types of changes
Related issues:
Checklist: