Skip to content

XIRR returning warnings and incorrect result #1120

@blacknell

Description

@blacknell

This is:

- [X] a bug report
- [ ] a feature request
- [X] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

I would expect the result to be 0.13796 (as calculated using XIRR in Excel)
However, this is because my dates are given in non ascending order and the document is clear that this is wrong. I believe a VALUE error should be returned.

What is the current behavior?

Lots of warnings given

Warning: A non-numeric value encountered in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Financial.php on line 2288

The result given is 0.16448

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
$values = [
	1893.67,
	139947.43,
	52573.25,
	48849.74,
	26369.16,
	-273029.18
];

$dates = [
	43643,
	43636,
	43637,
	43640,
	43643,
	43673,
];

$result = \PhpOffice\PhpSpreadsheet\Calculation\Financial::XIRR($values,$dates);

echo $result;

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.2
Latest PHPSpreadsheet 1.8.2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions