I finally managed to solve this using the finance function The problem was that I had some cashflows missing. I usually completed missing values with an amount=0 and date=0. Date=0 is 01JAN1960. This works in most of the cases, but when the IRR is too high or too close to -100%, it fails to converge. Workaround: complete missing values with a date closer to other cashflows. Below is a simplified version of my code. The two calls to finance() only differ in the date used. data irr;
format d1-d3 d4_v1 d4_v2 DATE9.;
v1 = 44.77;
v2 = -1080.59;
v3 = -151.61;
v4 = 0;
d1 = '31Mar2019'd;
d2 = '12Jun2019'd;
d3 = '30Jun2019'd;
d4_v1 = 0;
d4_v2 = '31Mar2019'd;
irr_doesnt_converge = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v1);
irr_converges = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v2);
run;
proc print data=irr; run; Note that if v1 changes to, for instance, 1444.7, in both cases the finance() call converges: data irr;
format d1-d3 d4_v1 d4_v2 DATE9.;
v1 = 1444.77;
v2 = -1080.59;
v3 = -151.61;
v4 = 0;
d1 = '31Mar2019'd;
d2 = '12Jun2019'd;
d3 = '30Jun2019'd;
d4_v1 = 0;
d4_v2 = '31Mar2019'd;
irr_converges_v1 = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v1);
irr_converges_v2 = finance('xirr', v1, v2, v3, v4, d1, d2, d3, d4_v2);
run;
proc print data=irr; run; Thanks everybody for your comments!!
... View more