Skip to content

Add function XIRR#1701

Open
sequba wants to merge 3 commits into
developfrom
feature/HF-76
Open

Add function XIRR#1701
sequba wants to merge 3 commits into
developfrom
feature/HF-76

Conversation

@sequba

@sequba sequba commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the Excel XIRR function (HF-76).

  • Adds XIRR(Values, Dates[, Guess]) to FinancialPlugin — returns the internal rate of return for a schedule of cash flows that is not necessarily periodic
  • Optional Guess defaults to 0.1; solver uses Newton–Raphson with day-based discounting on a 365-day year
  • Validates aligned value/date ranges (≥2 flows, mixed signs, date ordering), coerces empty value cells to 0, and returns #NA! for single-cell or scalar arguments
  • Registers XIRR in all language packs, updates built-in-functions.md and CHANGELOG.md
  • Unit tests added in the private test suite (function-xirr.spec.ts)

Test plan

  • npm test — lint + unit + browser
  • Microsoft XIRR example, XNPV consistency, range layouts, date edge cases, error paths, guess handling, non-convergence

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

Note

Low Risk
Additive built-in function in FinancialPlugin with localized names and documentation; no changes to auth, persistence, or core engine APIs.

Overview
Adds Excel-compatible XIRR(Values, Dates[, Guess]) for irregular cash-flow schedules, alongside existing IRR and XNPV.

Implementation lives in FinancialPlugin: aligned value/date ranges are sanitized (empty value cells → 0, errors propagated, non-numeric → #VALUE!), with checks for length match, at least two flows, mixed signs, valid dates, and Guess > -1. The rate is solved with Newton–Raphson on day-based discounting using a 365-day year, including overshoot clamping when the iterate would fall at or below -1.

XIRR is registered in all language packs, documented in built-in-functions.md, noted in CHANGELOG.md, and AGENTS.md gains a reminder to keep PR descriptions up to date.

Reviewed by Cursor Bugbot for commit 36c1465. Bugbot is set up for automated code reviews on this repo. Configure here.

@sequba sequba self-assigned this Jul 7, 2026
@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for hyperformula-dev-docs ready!

Name Link
🔨 Latest commit 36c1465
🔍 Latest deploy log https://app.netlify.com/projects/hyperformula-dev-docs/deploys/6a4cd74a4233ed0008f52cfc
😎 Deploy Preview https://deploy-preview-1701--hyperformula-dev-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@qunabu

qunabu commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Task linked: HF-76 Implement function XIRR

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7827c1e. Configure here.

Comment thread src/interpreter/plugin/FinancialPlugin.ts
@sequba sequba requested a review from marcin-kordas-hoc July 7, 2026 10:39
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Performance comparison of head (36c1465) vs base (4e302ff)

                                     testName |   base |   head | change
------------------------------------------------------------------------
                                      Sheet A | 493.36 | 495.03 | +0.34%
                                      Sheet B | 153.21 | 159.03 | +3.80%
                                      Sheet T | 140.23 | 143.68 | +2.46%
                                Column ranges | 473.74 | 466.87 | -1.45%
Sheet A:  change value, add/remove row/column |  16.05 |  15.64 | -2.55%
 Sheet B: change value, add/remove row/column | 134.66 | 131.55 | -2.31%
                   Column ranges - add column | 150.42 | 148.42 | -1.33%
                Column ranges - without batch |    453 | 454.27 | +0.28%
                        Column ranges - batch | 116.24 | 115.97 | -0.23%

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.15%. Comparing base (4e302ff) to head (36c1465).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1701      +/-   ##
===========================================
+ Coverage    97.14%   97.15%   +0.01%     
===========================================
  Files          176      176              
  Lines        15333    15404      +71     
  Branches      3390     3409      +19     
===========================================
+ Hits         14895    14966      +71     
  Misses         438      438              
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/idID.ts 100.00% <ø> (ø)
src/i18n/languages/itIT.ts 100.00% <ø> (ø)
... and 8 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.

2 participants