Discussion:
Cash Flow and Internal Rate of Return Program (IRR & NPV)
(too old to reply)
RicoM
2005-06-22 12:06:53 UTC
Permalink
I'm taking a class now that the professor advised everyone to buy a $40
financial TI calculator...being the stubborn 49g+ owner that I am I
thought I'd just program what I needed....well it was working fine
until I stumbled onto the IRR and the Cash Flow requirements (Cash flow
was programmed in, but instead of finding the NPV for a list of flows,
you have to find the NPV for each year individually and sum it...which
is a pain).

Anyway, I did a search on this group and found the PROOT command...also
found some other programs but I couldn't get it to work on my 49g+. SO
I finally just broke down and wrote my own program...

Now this program uses the "inform" command (which I like using a lot).
And as a disclaimer...I AM NOT a programmer! I didn't care about
slimming this program down and making it run better....I was only
concerned about making it work! I finished writing this thing around
10:00 last night and I was just tired of messing with it. I'm sure the
majority of users on this news group could make this more
efficient....but at least I laid the groundwork for you. It'll work,
but I use Global variables and purge them at the end. I'm sure I could
have eliminated some of the variables completely, but I didn't have
time to "tidy" it up after I finished and honestly the final exam is
next Monday and after that, I'm not sure I'll EVER get around to
cleaning it up. Hope this helps someone! Oh, also, the initial value
was chosen because that was the sample problem given in class. I used
it so because I knew what the answer was beforehand.

« « "Operation Cancelled" DOERR »
->
e @error
« "Cash Flow Inputs"
{ { "CF" "Cash Flow {CF0 CF1...CFn}" 5}
{ "i" "Interest Rate" 0 } }
{ 1 2 }
{ { -5000 800 800 800 800 800 800 800} .06 }
{ { -5000 800 800 800 800 800 800 800} .06 }

INFORM
DROP
OBJ->
DROP
'INTEREST' STO
'JLIST' STO
JLIST @Find IRR

LIST->
->ARRY
PROOT
OBJ->
OBJ-> DROP
'ILIST' STO

IF 'ILIST' 1 > THEN
WHILE 'ILIST' 1 >
REPEAT
SWAP
DROP
ILIST 1 -
'ILIST' STO
END
OBJ->
DROP
1 - 100 *
'IRR' STO
ELSE
e
END

CLEAR

JLIST
OBJ->
'NLIST' STO

WHILE 'NLIST' 1 > @Finding Present Value
REPEAT
INTEREST 1 +
NLIST 1 - ^
/
NLIST 1 -
ROLLD
NLIST 1 -
'NLIST' STO
END

DEPTH @Adding them together
'NLIST' STO
WHILE 'NLIST' 1 >
REPEAT
+
NLIST 1 -
'NLIST' STO
END
2 RND
"NPV ($)" ->TAG
IRR
5 RND
"IRR (%)" ->TAG
SWAP

'NLIST' PURGE
'IRR' PURGE
'INTEREST' PURGE
'JLIST' PURGE
'ILIST' PURGE
» »
BobLogan
2005-06-26 20:08:06 UTC
Permalink
Post by RicoM
It'll work,
but I use Global variables and purge them at the end. I'm sure I could
have eliminated some of the variables completely, but I didn't have
time to "tidy" it up after I finished and honestly the final exam is
next Monday and after that, I'm not sure I'll EVER get around to
cleaning it up.
Use local variables instead. The simplest (but not the most efficient) way
is to put

0 5 NDUPN DROP -> NLIST IRR INTEREST JLIST ILIST

at the beginning of your program. Then insert extra program delimiters (<<
Post by RicoM
) around the rest of your program and get rid of the purging at the end.
The program will end more quickly and you wont have to purge anything if
you interrupt it.

Bob
John H Meyers
2005-06-30 02:54:53 UTC
Permalink
On Wed, 22 Jun 2005 07:06:53 -0500, for RicoM:

Re-discovering some simple cash flow stuff for 48G, 49G,
including both some basic UserRPL for NPV/IRR/TVM
and pointers to MacDonald R. Phillips' excellent "fin421b"
financial package (48G/49G); search http://www.hpcalc.org
for any fancier financial applications:

http://groups-beta.google.com/group/comp.sys.hp48/msg/fba69b8f240340d4
http://groups-beta.google.com/group/comp.sys.hp48/msg/14cedf9f3cba00e3
http://groups-beta.google.com/group/comp.sys.hp48/msg/3b6c33f33e86f218

You use INFORM for yourself?

Why not INMENU?
http://groups-beta.google.com/group/comp.sys.hp48/msg/a367367015b209b0

The above version of INMENU has a built-in default prompt,
but it can be modified to accept a user string on level 2,
by simply omitting the built-in default prompt string.


Subtle INPUT bug in 49G version 1.19-6 (is it in 49G+ ???)

If you have used ECHO during INPUT, then cancel INPUT via ON ON,
the last arguments to INPUT will not be returned to the stack
(whereas on the 48G the args are returned as expected
when flag -55 is clear).

This can mess up 49G programs which use IFERR and expect
the arguments of INPUT to be returned if INPUT is canceled,
as they normally would be if only you had never used ECHO.

[r->][OFF]
Veli-Pekka Nousiainen
2005-06-30 06:11:07 UTC
Permalink
"John H Meyers" <***@miu.edu> wrote in message news:***@news.cis.dfn.de...
X
Post by John H Meyers
Subtle INPUT bug in 49G version 1.19-6 (is it in 49G+ ???)
If you have used ECHO during INPUT, then cancel INPUT via ON ON,
the last arguments to INPUT will not be returned to the stack
(whereas on the 48G the args are returned as expected
when flag -55 is clear).
This can mess up 49G programs which use IFERR and expect
the arguments of INPUT to be returned if INPUT is canceled,
as they normally would be if only you had never used ECHO.
I'm becoming so cynical that I will not even bother to check this
Old bugs like this will remain and new bugs are added...
V-P

Continue reading on narkive:
Loading...