HP Forums

Full Version: Hp 50g finance program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Hello Hp 50g,

the hp 50g has a built-in modul for payments with constant periodical payments. This works fine.

My proggies here are calculating the cashflow and the internal rate of interest for a certain cashflow. The proggies are not tested with a lot of examples, but with some examples out of the 12c or 17bii manuals.

I like to explain the two proggies in a short way for input and output. Enjoy!

First: the CFLOW-Program:

%%HP: T(3)A(R)F(,);

\<< 100 / { } \-> Co L Z LE

\<< PUSH -3 SF -105 SF Co 1 L SIZE

FOR I L I GET OBJ\-> DROP Z 1 + SWAP NEG ^ 1 SWAP - Z / SWAP Z

1 + SWAP NEG 1 + ^ * * LE SWAP + 'LE' STO

NEXT LE + \GSLIST POP

\>>

\>>

INPUT:

STACK 3: payment "Co", mostly negativ.

STACK 2: a list with lists of three objects

STACK 1: interest rate for that cashflow

a example for the list: {{500 1 2}{400 3 5}{100 9 2}}
I have to explain the objects for example: {400 3 5}
First Value: Payment
Second Value: Payed at the end of third period
Third Value: The payment of 400 bucks for five periods (group of payment with constant value)

interest rate value as percent without percent: 10% -> 10 as Input

OUTPUT: netto present value (NPV).

Second program: IRR Program:

Very important! This program only works when the program CFLOW is in the same directory, too.

%%HP: T(3)A(R)F(,);

\<< 5, 10, \-> Co L XI XI1

\<< PUSH -3, SF -105, SF Co L XI CFLOW Co L XI1 CFLOW DUPDUP ABS

WHILE ,005 \>=

REPEAT 3, PICK - ROT SWAP / XI XI1 2, PICK - ROT * - XI1 'XI'

STO 'XI1' STO Co L XI1 CFLOW DUPDUP ABS

END 3, DROPN XI1 POP

\>>

\>>

INPUT:

STACK 2: payment "Co", mostly negativ.

STACK 1: a list with lists of three objects (explained above).

OUTPUT: the internal interest rate in percent without percent f. e.:
12,5 means 12,5 %

The IRR program works with the regula falsi method. There is a difference which can be zero in a division. The program is simple and has no error handling for this situation. May be the IRR value converges against the wrong value, that could be caused by wrong start values for the rate (here 5 and 10, the first two values in the beginning of the program). IRR terminates, when NPV is zero, that means less then 0,005 Cent.

Sincerely
peacecalc

Edited: 1 Jan 2012, 10:25 a.m.