I cannot get my IRR program to work.
First I have created the Net Present Value program. It uses a list and a discount rate:
EXPORT NPV(L1,R)
BEGIN
LOCAL PV,I,R1;
R1:=R/100;
FOR I FROM SIZE(L1) DOWNTO 2 DO
PV:=(PV+L1(I))/(1+R1);
END;
PV:=PV+L1(1);
RETURN PV;
END;
And it works fine for all cases I have tried - not the ones that will produce errors, of course.
But when using it to create the IRR, it does not work:
First the program
EXPORT IRR(L1)
BEGIN
LOCAL R;
RETURN FNROOT(NPV(L1,R),R,0.1);
END;
Now the message (seems to be at the input):
X IRR({-100,12,12,12,12,112})
Can anyone of you help me?