XIRR.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. // result, message, values, dates, guess
  3. return [
  4. [
  5. '#NUM!',
  6. 'If values and dates contain a different number of values, returns the #NUM! error value',
  7. [4000, -46000],
  8. ['2015-01-04'],
  9. 0.1,
  10. ],
  11. [
  12. '#NUM!',
  13. 'Expects at least one positive cash flow and one negative cash flow; otherwise returns the #NUM! error value',
  14. [-4000, -46000],
  15. ['2015-01-04', '2019-06-27'],
  16. 0.1,
  17. ],
  18. [
  19. '#NUM!',
  20. 'Expects at least one positive cash flow and one negative cash flow; otherwise returns the #NUM! error value',
  21. [4000, 46000],
  22. ['2015-01-04', '2019-06-27'],
  23. 0.1,
  24. ],
  25. [
  26. '#VALUE!',
  27. 'If any number in dates is not a valid date, returns the #VALUE! error value',
  28. [4000, -46000],
  29. ['2015-01-04', '2019X06-27'],
  30. 0.1,
  31. ],
  32. [
  33. '#VALUE!',
  34. 'If any entry in values is not numeric, returns the #VALUE! error value',
  35. ['y', -46000],
  36. ['2015-01-04', '2019-06-27'],
  37. 0.1,
  38. ],
  39. [
  40. '#NUM!',
  41. 'If values is not an array, returns the #NUM! error value',
  42. -46000,
  43. ['2015-01-04', '2019-06-27'],
  44. 0.1,
  45. ],
  46. [
  47. '#NUM!',
  48. 'If dates is not an array but values is, returns the #NUM! error value',
  49. [4000, -46000],
  50. '2015-01-04',
  51. 0.1,
  52. ],
  53. [
  54. '#N/A',
  55. 'If neither dates nor values is an array, returns the #N/A error value',
  56. 4000,
  57. '2015-01-04',
  58. 0.1,
  59. ],
  60. [
  61. '#VALUE!',
  62. 'Return VALUE error if guess is non-numeric',
  63. [1893.67, 139947.43, 52573.25, 48849.74, 26369.16, -273029.18],
  64. ['2019-06-27', '2019-06-20', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  65. 'XYZ',
  66. ],
  67. [
  68. 0.137963527441025,
  69. 'Dates can be in any order after all',
  70. [1893.67, 139947.43, 52573.25, 48849.74, 26369.16, -273029.18],
  71. ['2019-06-27', '2019-06-20', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  72. 0.1,
  73. ],
  74. [
  75. 0.77868869226873,
  76. 'XIRR calculation #0 is incorrect',
  77. [4000, -46000],
  78. ['2015-04-01', '2019-06-27'],
  79. 0.1,
  80. ],
  81. [
  82. 0.137963527441025,
  83. 'XIRR calculation #1 is incorrect',
  84. [139947.43, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18],
  85. ['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  86. 0.1,
  87. ],
  88. [
  89. 0.09999999,
  90. 'XIRR calculation #2 is incorrect',
  91. [100.0, -110.0],
  92. ['2019-06-12', '2020-06-11'],
  93. 0.1,
  94. ],
  95. [
  96. 3235.159644,
  97. 'XIRR calculation #3 is incorrect',
  98. [1.0, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18],
  99. ['2019-06-27', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  100. ],
  101. [
  102. 0.15467888,
  103. 'XIRR calculation #4 is incorrect',
  104. [1893.67, 139947.43, 52573.25, 48849.74, 26369.16, -273029.18],
  105. ['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  106. ],
  107. [
  108. -0.197387315,
  109. 'XIRR calculation #5 is incorrect',
  110. [-100, 20, 40, 25],
  111. ['2010-01-01', '2010-04-01', '2010-10-01', '2011-02-01'],
  112. ],
  113. [
  114. 3.434984565,
  115. 'XIRR calculation #6 is incorrect',
  116. [-10000, 2750, 4250, 3250, 2750, 46000],
  117. ['2008-01-01', '2008-03-01', '2008-10-30', '2009-02-15', '2009-04-01', '2009-06-01'],
  118. ],
  119. [
  120. 0.13796353,
  121. 'Substitute for guess=0',
  122. [139947.43, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18],
  123. ['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  124. 0.00000,
  125. ],
  126. [
  127. 0.13796353,
  128. 'Substitute when guess is empty cell',
  129. [139947.43, 1893.67, 52573.25, 48849.74, 26369.16, -273029.18],
  130. ['2019-06-20', '2019-06-27', '2019-06-21', '2019-06-24', '2019-06-27', '2019-07-27'],
  131. 'C1',
  132. ],
  133. [
  134. '#NUM!',
  135. 'Can\'t find a result2 that works after FINANCIAL_MAX_ITERATIONS tries, the #NUM! error value is returned',
  136. [-10000, 10000, -10000, 5],
  137. ['2010-01-15', '2010-04-16', '2010-07-16', '2010-10-15'],
  138. ],
  139. [
  140. -0.642307613,
  141. 'See issue #2469 - non-convergence with initial guess',
  142. [55600, -51094.83],
  143. ['2021-11-24', '2021-12-24'],
  144. ],
  145. [
  146. -0.642307613,
  147. 'See issue #2469 - non-convergence with initial guess equal to correct answer',
  148. [55600, -51094.83],
  149. ['2021-11-24', '2021-12-24'],
  150. -0.642307613,
  151. ],
  152. [
  153. 'exception',
  154. 'Only one argument should cause exception',
  155. ['2021-11-24', '2021-12-24'],
  156. ],
  157. [
  158. 'exception',
  159. 'No argument should cause exception',
  160. ],
  161. [
  162. 0,
  163. 'DeCampo One year no growth',
  164. [-1000, 1000],
  165. ['2010-01-01', '2011-01-01'],
  166. ],
  167. [
  168. 0.1,
  169. 'DeCampo One year growth',
  170. [-1000, 1100],
  171. ['2010-01-01', '2011-01-01'],
  172. ],
  173. [
  174. -0.1,
  175. 'DeCampo One year decline',
  176. [-1000, 900],
  177. ['2010-01-01', '2011-01-01'],
  178. ],
  179. [
  180. 0.1212676,
  181. 'DeCampo vs spreadsheet',
  182. [-1000, -1000, -1000, -1000, 4300],
  183. ['2010-01-01', '2010-04-01', '2010-07-01', '2010-10-01', '2011-01-01'],
  184. ],
  185. [
  186. 0.1212676,
  187. 'DeCampo vs spreadsheet reordered',
  188. [-1000, 4300, -1000, -1000, -1000],
  189. ['2010-10-01', '2011-01-01', '2010-07-01', '2010-01-01', '2010-04-01'],
  190. ],
  191. [
  192. 2.0,
  193. 'DeCampo Over 100% growth',
  194. [-1000, 3000],
  195. ['2010-01-01', '2011-01-01'],
  196. ],
  197. [
  198. '#NUM!', // -1.0, DeCampo accounts for this case, Excel doesn't
  199. 'DeCampo Total loss one year, agree with Excel not DeCampo',
  200. [-1000, 0],
  201. ['2010-01-01', '2011-01-01'],
  202. ],
  203. [
  204. '#NUM!', // -1.0, DeCampo accounts for this case, Excel doesn't
  205. 'DeCampo Total loss two years, agree with Excel not DeCampo',
  206. [-1000, 0],
  207. ['2010-01-01', '2012-01-01'],
  208. ],
  209. [
  210. 0.2504234710540838,
  211. 'DeCampo Readme example',
  212. [-1000, -2500, -1000, 5050],
  213. ['2016-01-15', '2016-02-08', '2016-04-17', '2016-08-24'],
  214. ],
  215. [
  216. 0.2126861,
  217. 'DeCampo from nodejs',
  218. [-10000, 3027.25, 630.68, 2018.2, 1513.62, 1765.89, 4036.33, 4036.33, 1513.62, 1513.62, 2018.16, 1513.62, 1009.08, 1513.62, 1513.62, 1765.89, 1765.89, 22421.55],
  219. ['2000-05-24', '2000-06-05', '2001-04-09', '2004-02-24', '2005-03-18', '2006-02-15', '2007-01-10', '2007-11-14', '2008-12-17', '2010-01-15', '2011-01-14', '2012-02-03', '2013-01-18', '2014-01-24', '2015-01-30', '2016-01-22', '2017-01-20', '2017-06-05'],
  220. ],
  221. [
  222. '#NUM!', //-0.7640294,
  223. 'DeCampo issue5a, agree with Excel not DeCampo',
  224. [-2610, -2589, -5110, -2550, -5086, -2561, -5040, -2552, -2530, 29520],
  225. ['2001-06-22', '2001-07-03', '2001-07-05', '2001-07-06', '2001-07-09', '2001-07-10', '2001-07-12', '2001-07-13', '2001-07-16', '2001-07-17'],
  226. ],
  227. [
  228. '#NUM!', //-0.8353404,
  229. 'DeCampo issue5b, agree with Excel not DeCampo',
  230. [-2610, -2589, -5110, -2550, -5086, -2561, -5040, -2552, -2530, -9840, 38900],
  231. ['2001-06-22', '2001-07-03', '2001-07-05', '2001-07-06', '2001-07-09', '2001-07-10', '2001-07-12', '2001-07-13', '2001-07-16', '2001-07-17', '2001-07-18'],
  232. ],
  233. [
  234. 412461.6383,
  235. 'Python XIRR test line 20',
  236. [-100, 1000],
  237. ['2019-12-31', '2020-03-05'],
  238. ],
  239. [
  240. 1.223853529e16,
  241. 'Python XIRR test line 21',
  242. [-2236.3994659663, -47.3417585212, -46.52619316339632, 10424.74612565936, -13.077972551952],
  243. ['2017-12-16', '2017-12-26', '2017-12-29', '2017-12-31', '2017-12-20'],
  244. ],
  245. [
  246. '#NUM!', //-1,
  247. 'Python XIRR test line 39, agree with Excel not Python',
  248. [18902, 83600, -5780, -4080, -56780, -2210, -2380, 33975, 23067.98, -1619.57],
  249. ['2016-04-06', '2016-05-04', '2016-05-12', '2017-05-08', '2017-07-03', '2018-05-07', '2019-05-06', '2019-10-01', '2020-03-13', '2020-05-07'],
  250. ],
  251. ];