Difficulties with IRR Program



#6

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?


#7

Do you have the two programs under separate catalog names ? To treat the NPV program as a subroutine, it needs to be under the same catalog name and come before the calling program IRR:

IRR_and_NPV

EXPORT NPV()
...
END;

EXPORT IRR()
...
END;

Edited: 30 Nov 2013, 12:12 p.m.


#8

Many thanks - it may be one of wrong things, but not the one of that problem: once changed, it gives the same error.

Any other guess? Thank you in advance!


#9

My guess would be using a globally named variable L1 as your function input name. Change it from L1 to somethimg else and see if that makes a difference.

#10

Hello,

Here is a working program:

EXPORT NPV(l, r)
BEGIN // Using sigma list and makelist is WAY cooler than loops :-)
∑LIST(makelist(l(I)/(1+r)^(I-1), I, 1, SIZE(l)));
END;

// OK, here is the trick there...
// fnroot does NOT carry over local variables from 'above'...
// meaning that using a local variable from the containing function
// in a fnroot call will NOT work (althrough locals can be used
// IN the fnroot call).
// This is why we are creating here a LIST Global variable
// which will be used to contain the list and will work with
// fnroot.
export LIST;
export irr(l)
begin
local r;
LIST:= l;
fnroot(NPV(LIST, r), r, 0.001, 1)*100;
end;

cyrille


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 511 11-11-2013, 08:28 PM
Last Post: Davi Ribeiro de Oliveira
  20b IRR "ON [right-arrow] Stop" Error Cinealta 6 473 09-29-2008, 01:45 PM
Last Post: Peter A. Gebhardt
  HP-41 MCODE: Making an MCODE program call another MCODE program Geir Isene 10 666 01-13-2008, 05:58 AM
Last Post: Raymond Del Tondo

Forum Jump: