RayDeCampo / java-xirr

Java implementation of xirr with bonus Newton-Raphson implementation
MIT License
75 stars 37 forks source link

Error getting xirr #12

Closed MarioK17 closed 5 years ago

MarioK17 commented 5 years ago

Hi, I'm getting error with these values.

SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
double r = new Xirr(
                new Transaction(984290.64, dateFormat.parse("25-10-2019")),
            new Transaction(-156452.14, dateFormat.parse("25-10-2020")),
            new Transaction(-156000.00, dateFormat.parse("25-10-2021")),
            new Transaction(-156000.00, dateFormat.parse("25-10-2022")),
            new Transaction(-319306.62, dateFormat.parse("25-10-2023")),
            new Transaction(-319306.62, dateFormat.parse("25-10-2024")),
            new Transaction(-319306.62, dateFormat.parse("25-10-2025")),
            new Transaction(-319306.62, dateFormat.parse("25-10-2026")),
            new Transaction(-582400.00, dateFormat.parse("25-10-2027"))).xirr();

 System.out.println(r*100);

Error:

Exception in thread "main" java.lang.IllegalArgumentException: Newton-Raphson failed to converge within 10000 iterations.
    at org.decampo.xirr.NewtonRaphson.inverse(NewtonRaphson.java:99)
    at org.decampo.xirr.NewtonRaphson.findRoot(NewtonRaphson.java:67)
    at org.decampo.xirr.NewtonRaphson$Builder.findRoot(NewtonRaphson.java:147)
    at org.decampo.xirr.Xirr.xirr(Xirr.java:106)

It should by 18.84%

MarioK17 commented 5 years ago

I was using version 0.1