Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finance.IRR causes "Cannot convert undefined or null to object" error #43

Open
noff opened this issue Mar 17, 2019 · 2 comments
Open

finance.IRR causes "Cannot convert undefined or null to object" error #43

noff opened this issue Mar 17, 2019 · 2 comments

Comments

@noff
Copy link

noff commented Mar 17, 2019

The example:

finance.IRR(-500000, 200000, 300000, 200000);

Result:

    Uncaught TypeError: Cannot convert undefined or null to object
    at slice (<anonymous>)
    at Finance.IRR (finance.self-e3a7ba8fd778d256a438ea068bd511733e341d18b95ce0cda6e89071e7a0edb2.js?body=1:51)
    at <anonymous>:1:9

Here:

    Finance.prototype.IRR = function(cfs) {
    var depth = cfs.depth;
    var args = cfs.cashFlow;
    var numberOfTries = 1;
    // Cash flow values must contain at least one positive value and one negative value
    var positive, negative;
    Array.prototype.slice.call(args).forEach(function (value) { // <<<<< Right here
        if (value > 0) positive = true;
        if (value < 0) negative = true;
    })

image

@StickmanNinja
Copy link

I'm having the same issue.

@l1qu1d
Copy link

l1qu1d commented Jun 18, 2019

@SethConnell @noff The example in the README.md for IRR won't work. In the image of the IRR function that noff provided, you see that it wants an object with two keys named "depth" and "cashFlow".

For the sake of familiarity I'll use the numbers given in the readme.

Try finance.IRR({depth: 100, cashFlow:[-500000, 200000, 300000, 200000]}) which outputs (at least in my environment) 18.83 and NOT 18.82 as the example in the readme shows.

I'm not really sure what "depth" is, but from the code, its a limiter on how many times the internal NPV function is ran. For cashFlow it needs to be an array of the integers you want you want to run the function against.

I haven't given this library a good looking at, but just from this function I'd either write your own or go somewhere else. When it comes to financing or other peoples money you want to be 100% accurate and understand what is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants