Skip to content

Conversation

@sequba
Copy link
Contributor

@sequba sequba commented Jan 7, 2026

Context

  • Implement the IRR (Internal Rate of Return) function following the Excel specification
  • IRR calculates the internal rate of return for a series of cash flows
  • Uses Newton-Raphson method for iterative calculation
  • Add translations for all 17 built-in languages
  • Add comprehensive unit tests covering edge cases and error handling

Implemented with the assist of Claude Code + Claude Opus 4.5

How did you test your changes?

  • All existing unit tests pass
  • New IRR function tests pass
  • Test argument validation (wrong number of arguments)
  • Test error conditions (#NUM! for non-convergence, missing positive/negative values)
  • Test value type (returns NUMBER_PERCENT)
  • Test handling of text, logical, and empty values in ranges
  • Test various calculation scenarios including Microsoft documentation examples
  • Test guess parameter behavior
  • Test edge cases (very small/large values, zero values, many periods)
  • Test different range orientations (vertical, horizontal, 2D)

Types of changes

  • Breaking change (a fix or a feature because of which an existing functionality doesn't work as expected anymore)
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues:

  1. Fixes Function IRR #1591

Checklist:

  • I have reviewed the guidelines about Contributing to HyperFormula and I confirm that my code follows the code style of this project.
  • I have signed the Contributor License Agreement.
  • My change is compliant with the OpenDocument standard.
  • My change is compatible with Microsoft Excel.
  • My change is compatible with Google Sheets.
  • I described my changes in the CHANGELOG.md file.
  • My changes require a documentation update.
  • My changes require a migration guide.

sequba added 4 commits January 2, 2026 16:55
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
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

Performance comparison of head (c4a4933) vs base (7f856be)

                                     testName |   base |   head | change
------------------------------------------------------------------------
                                      Sheet A | 494.24 | 502.79 | +1.73%
                                      Sheet B | 160.47 | 161.62 | +0.72%
                                      Sheet T |  143.1 | 141.71 | -0.97%
                                Column ranges | 501.93 | 504.73 | +0.56%
Sheet A:  change value, add/remove row/column |  14.08 |  13.89 | -1.35%
 Sheet B: change value, add/remove row/column | 125.42 | 124.05 | -1.09%
                   Column ranges - add column | 142.39 | 139.92 | -1.73%
                Column ranges - without batch |  437.2 |  430.7 | -1.49%
                        Column ranges - batch | 116.13 | 115.07 | -0.91%

sequba and others added 7 commits January 7, 2026 13:16
- 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
@sequba sequba self-assigned this Jan 7, 2026
Copy link
Member

@budnix budnix left a 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]>
@sequba sequba merged commit e8f338c into develop Jan 8, 2026
31 checks passed
@sequba sequba deleted the feature/issue-1591 branch January 8, 2026 09:11
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (7f856be) to head (c4a4933).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           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           
Files with missing lines Coverage Δ
src/i18n/languages/csCZ.ts 100.00% <ø> (ø)
src/i18n/languages/daDK.ts 100.00% <ø> (ø)
src/i18n/languages/deDE.ts 100.00% <ø> (ø)
src/i18n/languages/enGB.ts 100.00% <ø> (ø)
src/i18n/languages/esES.ts 100.00% <ø> (ø)
src/i18n/languages/fiFI.ts 100.00% <ø> (ø)
src/i18n/languages/frFR.ts 100.00% <ø> (ø)
src/i18n/languages/huHU.ts 100.00% <ø> (ø)
src/i18n/languages/itIT.ts 100.00% <ø> (ø)
src/i18n/languages/nbNO.ts 100.00% <ø> (ø)
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants