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.
Summary
This PR resolves 2 issues in the MIRR function implementation:
Formula Calculation Issue
The current MIRR implementation produces inaccurate results due to an error in the present value calculation.
Let's take an example from Wikipedia: Modified internal rate of return
Input data:
Calculation result:
The discrepancy appears due to including finance and reinvestment rates in the present value calculation. Only the finance rate should be considered.
Here is a related code fragment:
Input Parameter Order
The current implementation uses a non-standard order for finance and reinvestment rates, unlike common spreadsheet applications (Excel, Google Sheets).
Current order: (values, reinvestRate, financeRate).
Proposed order: (values, financeRate, reinvestRate).
I.e. to calculate the MIRR for the formula mentioned above one have pass the following values to
Mirr#evaluate(double[] values)
function:-1000D, -4000D, 5000D, 2000D, 0.12D, 0.1D
however more the order according to most popular spreadsheet applications would be:
-1000D, -4000D, 5000D, 2000D, 0.1D, 0.12D
Testing
A test from Wikipedia has been added to verify the formula accuracy.
All other tests are left intact except for parameter order.