RayDeCampo / java-xirr

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

Xirr gives org.decampo.xirr.OverflowException: Candidate overflow: {candidate=-Infinity} #24

Open 09nimit opened 2 years ago

09nimit commented 2 years ago

Could not calculate negative Xirr, as below values

new Xirr(new Transaction(-10000d, "2022-01-24"), new Transaction(9800d, "2022-01-28")).xirr();

gives below error

Exception in thread "main" org.decampo.xirr.OverflowException: Candidate overflow: {guess=-1.825, iteration=159, candidate=-Infinity, value=-2.3355275185815405E7, derivative=-1.0631116397667295E-302}
    at org.decampo.xirr.NewtonRaphson$Calculation.setCandidate(NewtonRaphson.java:166)
    at org.decampo.xirr.NewtonRaphson$Calculation.solve(NewtonRaphson.java:213)
    at org.decampo.xirr.NewtonRaphson.inverse(NewtonRaphson.java:89)
    at org.decampo.xirr.NewtonRaphson.findRoot(NewtonRaphson.java:70)
    at org.decampo.xirr.NewtonRaphson$Builder.findRoot(NewtonRaphson.java:136)
    at org.decampo.xirr.Xirr.xirr(Xirr.java:155)
RayDeCampo commented 2 years ago

It's not going to converge for every situation, try giving it a guess to start out.