Add Excel-compatible XIRR wrapper#31
Open
Thorium wants to merge 9 commits into
Open
Conversation
Co-authored-by: Thorium <229355+Thorium@users.noreply.github.com>
Co-authored-by: Thorium <229355+Thorium@users.noreply.github.com>
Co-authored-by: Thorium <229355+Thorium@users.noreply.github.com>
…tps://github.com/Thorium/FSharp.Finance.Personal into copilot/fix-f5ce842f-1313-46d7-934a-66cdd703b0ef # Conflicts: # src/FSharp.Finance.Personal.fsproj
There was a problem hiding this comment.
Pull request overview
Adds an Excel-compatible XIRR wrapper to FSharp.Finance.Personal by integrating the ExcelFinancialFunctions dependency, plus tests and docs to demonstrate usage.
Changes:
- Introduces new
Xirrmodule (xirr,xirrG,tryXirr) backed byExcelFinancialFunctions. - Adds unit tests covering basic scenarios and input validation.
- Updates README and adds an example
.fsxscript describing usage/sign conventions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/Xirr.fs |
New XIRR API wrapper with validation and Result-based safe helper. |
src/FSharp.Finance.Personal.fsproj |
Adds Xirr.fs to compilation and references ExcelFinancialFunctions. |
tests/XirrTests.fs |
Adds test coverage for the new XIRR functions and validation paths. |
tests/FSharp.Finance.Personal.Tests.fsproj |
Includes new XirrTests.fs in the test project. |
docs/exampleXirr.fsx |
Adds a usage example script for XIRR. |
README.md |
Documents XIRR functionality and basic usage snippet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
All the finance people (and chatbots) seem to be madly in love with XIRR functions. So here you go...
This PR adds Excel-compatible XIRR (Extended Internal Rate of Return) functionality to the FSharp.Finance.Personal library, enabling calculation of annualized returns for irregular cash flow schedules.
Instead of re-inventing the wheel, this adds a new dependency to fsprojects/ExcelFinancialFunctions.
Features Added
Core XIRR Module (
src/Xirr.fs)Xirr.xirr: Calculate XIRR with Excel's default guess of 0.1 (10%)Xirr.xirrG: Calculate XIRR with custom initial guess parameterXirr.tryXirr: Safe calculation returningResult<decimal, string>for error handlingExcel Compatibility
Uses the
ExcelFinancialFunctionslibrary (v3.2.0) to ensure complete parity with Excel's XIRR function, including:Input Validation
All functions validate that:
ArgumentExceptionfor invalid inputs (excepttryXirrwhich returnsResult.Error)Usage Example
Testing
Comprehensive test suite (
tests/XirrTests.fs) covers:xirrandxirrGwith same guessAll 7 test cases pass successfully when run in isolation.
Documentation
docs/exampleXirr.fsxwith comprehensive usage examplesIntegration Notes
ExcelFinancialFunctionspackage dependencyThe implementation follows the repository's existing patterns and conventions, using
[<RequireQualifiedAccess>]module attributes and consistent error handling approaches.