HP Forums
(15C) Simple? NPV, XNPV, IRR & XIRR - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (15C) Simple? NPV, XNPV, IRR & XIRR (/thread-8322.html)



(15C) Simple? NPV, XNPV, IRR & XIRR - Vtile - 05-09-2017 08:22 PM

This program relates to:

(15C) Simple NPV
(15C) MM.DDYYYY or DD.MMYYYY to Julian Day [Stack-Only] Not used, but will ease up using XIRR & XNPV features.

The idea using solver for a IRR were copied from the The Calculator Store page, which SlideRule provided in Simple NPV thread. I weren't too impressed of the nine periods limitation (I do have DM15 with ~210 registers vs. ~65 in original 15C) so I'm not as limited, put this my smallish program should still work on original 15C (although barely) with combination of some other financial and date tools.

My almost simple NPV, XNPV, IRR & XIRR program is capable of calculate those mentioned with up to 32 periods (if your device have memory).

Registers in use:
R0 - internal, matrix
R1 - internal, matrix
R2 - internal
R3 - internal
Matrix:
A: 1 to 32 periods.
Labels:
2
Lines:
33

Provided as is, use at your own risk for anything that matters.
The program might have a few unnecessary lines here and there, but my experience on RPN is too limited to get every unnecessary lines of code out.

Code:

1    LBL 1
2    1
3    %
4    1                // PERCENTAGE TO multiplier
5    +        
6    STO 3         // i TO R3
7    f MATRIX 1  // MATRIX SETTINGS R0&R1 to 1
8    RCL DIM A
9    R↓
10    STO R0
11    CLx              // CLEAR R2 (NPV)
12    STO 2          // CLEAR R2 (NPV)
13    LBL .1          // n ROUTINE
14    RCL 3           // (1+i)    
15    RCL A           // RCL PERIOD NUMBER n
16    Y^X
17    1/X
18    1
19    STO+ R1       // INC. MATRIX COL.
20    *                 // STACK manipulation only.
21    RCL A           // RCL CL_n    
22    *                 // CLn* 1/(1+i)^n
23    STO+ 2         // Sum periods of NPV
24    1
25    STO-0          // DEC R0 IF NOT ZERo
26    STO 1
27    RCL 0
28    g TEST 1      // IF R0 > 0    
29    GTO .1         // ..THEN REPEAT
30    f MATRIX 1   // RESET MATRIX COUNTERS
31    RCL 3          // FILL STACK
32    RCL 2           //FILL STACK
33    RTN

How to use:

I use program label XYZ for above simple program in this chapter.

Let say you have four periods and initial investment. (example copied from ISBN:951-37-4788-3)
1.1.2000: $-78696.25
1.7.2000: $1420
1.7.2001: $2130
1.7.2002: $1775
1.7.2003: $2662.50
1.1.2004: 99652.81


First you need to declare a matrix,
5 Enter (ROWS IN Y REGISTER)
2 f DIM A

Now you have matrix with 5 rows and 2 colums.

Reset matrix counters (Registers 0 and 1) for just in case,
f MATRIX 1

Press
f USER

Type in (yyy/365 are delta days from 1.1.2000):

0 STO A
-78696.25 STO A

182/365 STO A
1420 STO A

547/365 STO A
2130 STO A

912/365 STO A
1775 STO A

1277/365 STO A
2662.50 STO A

At this point Oops, you just noticed that your matrix isn't properly dimensioned...
Lets type,
[b]6 ENTER
2 DIM A
5 STO 0
2 STO 1
RCL A
RCL A


1461/365 STO A
99625.81 STO A[/b]


(IF you do make mistake, note that matrix for this program must have period exponent in column 1 (R1=1) and money in column 2 (R1=2) look the explanation of matrix operations from the manual if not sure. You can use STO 1, STO 2 and RCL 1, RCL0 or RCL A for error checking if needed.)

f USER

Now program XYZ needs a percentage in the X register so lets give it a 9% and run it to find XNPV.
9 ENTER
GSB XYZ


Result: $1502.6570

We definedly need to know XIRR..

2 Enter
f SOLVE XYZ

(some times later..)
Result: 8.4542%

... Enjoy Big Grin

EDIT. TVMs to NPVs