The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

Difficulties with IRR Program
Message #1 Posted by Jose Gonzalez Divasson on 30 Nov 2013, 11:32 a.m.

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?

      
Re: Difficulties with IRR Program
Message #2 Posted by Michael de Estrada on 30 Nov 2013, 12:11 p.m.,
in response to message #1 by Jose Gonzalez Divasson

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.

            
Re: Difficulties with IRR Program
Message #3 Posted by José González Divasson on 30 Nov 2013, 3:44 p.m.,
in response to message #2 by Michael de Estrada

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!

                  
Re: Difficulties with IRR Program
Message #4 Posted by Tim Wessman on 30 Nov 2013, 3:53 p.m.,
in response to message #3 by José González Divasson

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.

      
Re: Difficulties with IRR Program
Message #5 Posted by cyrille de Brébisson on 2 Dec 2013, 2:34 a.m.,
in response to message #1 by Jose Gonzalez Divasson

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


[ Return to Index | Top of Index ]

Go back to the main exhibit hall