-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate XIRR inputs and return correct error values
Fix: Return #NUM! if values and dates contain a different number of values Fix: Return #NUM! if there is not at least one positive cash flow and one negative cash flow Fix: Return #NUM! if any number in dates precedes the starting date Fix: Return #NUM! if a result that works cannot be found after max iteration tries Fix: Correct DocBlocks for XIRR & XNPV Add: Validate XIRR with unit tests
- Loading branch information
Showing
4 changed files
with
95 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,62 @@ | ||
<?php | ||
|
||
// values, dates, guess, Result | ||
// result, message, values, dates, guess | ||
|
||
return [ | ||
[ | ||
[ | ||
-10000, | ||
[ | ||
2750, | ||
4250, | ||
3250, | ||
2750, | ||
46000, | ||
], | ||
], | ||
[ | ||
'2008-01-01', | ||
[ | ||
'2008-03-01', | ||
'2008-10-30', | ||
'2009-02-15', | ||
'2009-04-01', | ||
], | ||
], | ||
0.10000000000000001, | ||
0.373362535, | ||
'#NUM!', | ||
'If values and dates contain a different number of values, returns the #NUM! error value', | ||
[4000, -46000], | ||
['01/04/2015'], | ||
0.1 | ||
], | ||
[ | ||
[ | ||
-100, | ||
[ | ||
20, | ||
40, | ||
25, | ||
], | ||
], | ||
[ | ||
'2010-01-01', | ||
[ | ||
'2010-04-01', | ||
'2010-10-01', | ||
'2011-02-01', | ||
], | ||
], | ||
-0.3024, | ||
'#NUM!', | ||
'Expects at least one positive cash flow and one negative cash flow; otherwise returns the #NUM! error value', | ||
[-4000, -46000], | ||
['01/04/2015', '2019-06-27'], | ||
0.1 | ||
], | ||
[ | ||
[ | ||
-100, | ||
[ | ||
20, | ||
40, | ||
25, | ||
8, | ||
15, | ||
], | ||
], | ||
[ | ||
'2010-01-01', | ||
[ | ||
'2010-04-01', | ||
'2010-10-01', | ||
'2011-02-01', | ||
'2011-03-01', | ||
'2011-06-01', | ||
], | ||
], | ||
0.20949999999999999, | ||
'#NUM!', | ||
'Expects at least one positive cash flow and one negative cash flow; otherwise returns the #NUM! error value', | ||
[4000, 46000], | ||
['01/04/2015', '2019-06-27'], | ||
0.1 | ||
], | ||
[ | ||
'#VALUE!', | ||
'If any number in dates is not a valid date, returns the #VALUE! error value', | ||
[4000, -46000], | ||
['01/04/2015', '2019X06-27'], | ||
0.1 | ||
], | ||
[ | ||
'#NUM!', | ||
'If any number in dates precedes the starting date, XIRR returns the #NUM! error value', | ||
[1893.67, 139947.43, 52573.25, 48849.74, 26369.16, -273029.18], | ||
['2019-06-27', '2019-06-20', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'], | ||
0.1 | ||
], | ||
[ | ||
0.137963527441025, | ||
'XIRR calculation #1 is incorrect', | ||
[139947.43, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18], | ||
['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'], | ||
0.1 | ||
], | ||
[ | ||
0.09999999, | ||
'XIRR calculation #2 is incorrect', | ||
[100.0, -110.0], | ||
['2019-06-12', '2020-06-11'], | ||
0.1 | ||
], | ||
[ | ||
'#NUM!', | ||
'Can\'t find a result that works after FINANCIAL_MAX_ITERATIONS tries, the #NUM! error value is returned', | ||
[139947.43, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18], | ||
['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'], | ||
0.00000 | ||
], | ||
]; |