HP Forums
Net Present Value - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Net Present Value (/thread-987.html)



Net Present Value - Eddie W. Shore - 03-28-2014 03:34 AM

HP Net Present Value
2014-03-28

Arguments:
NPV(periodical rate, list of cash flows)
or
NPV(periodical rate, [ cash flow, frequency ] )

Program:
EXPORT NPV(r, flows)
BEGIN
LOCAL t:=0, k, s;
r:=1+0.01*r;

CASE
// list
IF TYPE(flows)==6 THEN
s:=SIZE(flows);
FOR k FROM 1 TO s DO
t:=t+flows(k)/(r^(k-1));
END;
END;

// matrix
IF TYPE(flows)==4 THEN

LOCAL j, n;
s:=SIZE(flows);
k:=0;

FOR j FROM 1 TO s(1) DO
FOR n FROM 1 TO flows(j,2) DO
t:=flows(j,1)/(r^k)+t;
k:=k+1;
END;
END;

END;

DEFAULT
MSGBOX("NPV(rate, list) or NPV(rate, [flow, freq])");
KILL;
END;

RETURN t;
END;


--- Examples:

NPV(5, {-1000, 100, 250, 500, 750, 500}) returns 762.704203447

NPV(3, [[-1000, 1],[0, 5],[500, 5],[1500, 1]]) returns 2058.87973969


RE: Net Present Value - salvomic - 05-17-2015 09:15 AM

(03-28-2014 03:34 AM)Eddie W. Shore Wrote:  HP Net Present Value
2014-03-28

...

Nice, Eddie!
I hope you would like to develop also a function to calc IRR (Internal Rate of Return: see here) for the cash flow...

thank you
Salvo


RE: Net Present Value - shuhei - 03-05-2019 06:10 AM

if returned an error, when enter NPV(3, [100, 5])

It cannot accept matrix 1x2 as an input. Can someone help? Thanks