Post Reply 
HP-41 Internal Rate of Return (IRR)
11-03-2024, 08:02 AM (This post was last modified: 11-05-2024 01:51 PM by Ángel Martin.)
Post: #1
HP-41 Internal Rate of Return (IRR)
Calculation of IRR, Internal Rate of Return
i.e. interest rate for which the Net Present Value (NPV) is zero.

Here's a short FOCAL routine I've used as benchmark while working on a MCODE version of IRR soon to be released.

The routine prompts for the initial Capital investment C0, the number of periods N, and the first cash-flow C1. Based on C1 the remaining cash-flows are calculated using two options,

LBL "IRR+" for the aithmetic: Cn = C1+k*(n-1)
LBL "IRR*" for the geometric: Cn = C1* (1+k)^(n-1)

with k being the ratio also an input prompted by the program.

The program solves for IRR using SOLVE (or FROOT if you use the SandMath).
In his version the Initial guesses are hard-coded to be 0.1 and 0.5

Example: With C0=(250.000,00), C1 = 100.000,00, N=5
arithmetic, k=50.000,000 => IRR = 56.72%
geometric, k=0.05 (5%) => IRR = 32.50%

Code:
1   LBL "IRR+"    
2   CF 03    
3   GTO 03    
4   LBL "IRR*"    
5   SF 03    
6   LBL 03    
7   "N=?"    
8   PROMPT    
9   STO 01      N
10  "C0=?"    
11  PROMPT    
12  STO 04     C0
13  "C1=?"    
14  PROMPT    
15  STO 03     C1
16  "K=?"    
17  PROMPT    
18  STO 05     Cn factor
19  "I+*"     FName
20  0,1       a
21  ENTER^    
22  0,5       b
23  FROOT     do SOLVE
24  RTN    
25  LBL "I+*"    
26  STO 02     irr
27  CLX    
28  STO 06     reset sum
29  RCL 01     N
30   E3    
31   /         0.00N
32   E    
33  +          1,00N
34  STO 00     counter
35  LBL 00    
36  RCL 03     c1
37  RCL 05     k
38  RCL 00     n,00N
39  INT        n
40   E    
41  -          (n-1)
42  FS? 03    
43  GTO 03
44  *          k.(n-1)
45  +          Cn = C1+k.(n-1)
46  GTO 00    
47  LBL 03
48  ISG Y     k+1
49  NOP
49  Y^X        (k+1)^(n-1)
50  *          Cn = C1*(1+k)^(n-1)
51  LBL 00
52  RCL 02     irr
53   E    
54  +          1+irr
55  RCL 00     n,00N
56  INT        n
57  Y^X        (1+irr)^n
58  /          Cn/(1+irr)^n
59  ST+ 06     partial sum
60  ISG 00     increase counter
61  GTO 00     do next term
62  RCL 06     total SUM
63  RCL 04     C0
64  +          SUM + (C0)
65  END

Cheers,
ÁM

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
11-05-2024, 09:27 AM (This post was last modified: 11-05-2024 09:30 AM by Stephan61.)
Post: #2
RE: HP-41 Internal Rate of Return (IRR)
Hi Ángel, three observations:

1. Step 47: "LBL 03" seems obsolete?
2. Step 60: "-" you changed this from "+" to "-" that means C0 has to be entered positiv instead of negative, right?
3. I can't replicate your geometric example: I get 0,2865 (28,65%)

Ciao Stephan

PS: Looking forward to your MCODE-version!
Find all posts by this user
Quote this message in a reply
11-05-2024, 11:41 AM
Post: #3
RE: HP-41 Internal Rate of Return (IRR)
(11-05-2024 09:27 AM)Stephan61 Wrote:  Hi Ángel, three observations:

1. Step 47: "LBL 03" seems obsolete?
indeed it is, sorry I forgot to remove it.

(11-05-2024 09:27 AM)Stephan61 Wrote:  2. Step 60: "-" you changed this from "+" to "-" that means C0 has to be entered positiv instead of negative, right?
Darn typos, I meant to change it to "plus" in the comment and instead I did the opposite. The correct step should be "+", which implies that (c0) needs to be entered as a negative value at the prompt.


(11-05-2024 09:27 AM)Stephan61 Wrote:  3. I can't replicate your geometric example: I get 0,2865 (28,65%)

mmm... it's possible that something got weird in my last editing, let me look at it and will get back to you on this.

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
11-05-2024, 01:54 PM (This post was last modified: 11-05-2024 01:55 PM by Ángel Martin.)
Post: #4
RE: HP-41 Internal Rate of Return (IRR)
Sure enough there was a glitch and a wrong formula used for Cn in the geometric case.
I have corrected the original post, pls. try again and let me know if it works for you.

Note: you can use LBL 10 for the NOP in step 49

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
11-05-2024, 02:09 PM
Post: #5
RE: HP-41 Internal Rate of Return (IRR)
Thanks a lot for this fast action!
Find all posts by this user
Quote this message in a reply
11-19-2024, 07:32 PM
Post: #6
RE: HP-41 Internal Rate of Return (IRR)
Albert,

I was taught by American Jesuits from Boston College. Their motto in sharing information was "Hit the point!". I followed that motto in my carrier as a programming book writer. I humbly sugget you create your own website (as I have done) where you post PDF/ZIP files for each set of calculations you produce. Then you post a single summary/brief thread in this web site to explain the general concepts you are sharing and offer a link to the PDF/ZIP file in your web site. This way folks who are interested can download AND keep your documents for future reference.

Namir
Find all posts by this user
Quote this message in a reply
Yesterday, 08:26 AM
Post: #7
RE: HP-41 Internal Rate of Return (IRR)
(11-19-2024 07:32 PM)Namir Wrote:  I was taught by American Jesuits from Boston College. Their motto in sharing information was "Hit the point!". I followed that motto in my carrier as a programming book writer. I humbly sugget you create your own website (as I have done) where you post PDF/ZIP files for each set of calculations you produce. Then you post a single summary/brief thread in this web site to explain the general concepts you are sharing and offer a link to the PDF/ZIP file in your web site. This way folks who are interested can download AND keep your documents for future reference.

I Fully subscribe to Namir's comments, thank you!

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Yesterday, 01:57 PM
Post: #8
RE: HP-41 Internal Rate of Return (IRR)
Hi, Namir

I have moved IRR calculations using TVM to my TVM thread, where it belongs.
https://www.hpmuseum.org/forum/thread-18359-page-4.html

I had not considered this site might be down. Thanks for the heads up.
If I have time, I shall write it up, 'freeze' as pdf, and post to https://github.com/achan001

https://archiveprogram.github.com/ Wrote:On 02/02/2020 GitHub captured a snapshot of every active public repository. Those millions of repos were then archived to hardened film designed to last for 1,000 years, and stored in the GitHub Arctic Code Vault in a decommissioned coal mine deep beneath an Arctic mountain in Svalbard, Norway.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)