Thursday, March 27, 2014

HP Prime Program: Net Present Value

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


This blog is property of Edward Shore. 2014

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...