java-xirr icon indicating copy to clipboard operation
java-xirr copied to clipboard

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

Open 09nimit opened this issue 4 years ago • 1 comments

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)

09nimit avatar Jan 28 '22 17:01 09nimit

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

RayDeCampo avatar Jan 28 '22 19:01 RayDeCampo