06-12-2020, 08:58 AM
Update: replaced by this newer version that also includes MIRR
Solver program.
CF0 is separate
CFj is an nx2 matrix with the Cash flows (j=1..n) in column 1 and their frequency in column 2
CFj may also be a nx1 matrix, implying all Nj=1
uses subroutine Ni to calculate ((1+i)^N - 1)/i:
example: create the 7x2 matrix
[[1000 1]
[2000 2]
[3000 3]
[4000 4]
[5000 5]
[6000 6]
[7000 7]]
Start the solver: Shift-SOLVER, NPV
store the matrix in CFj
store -100000 in CF0
store 0 in NPV
press IRR% -> 2.0417694...
hope you like it
Werner
Solver program.
CF0 is separate
CFj is an nx2 matrix with the Cash flows (j=1..n) in column 1 and their frequency in column 2
CFj may also be a nx1 matrix, implying all Nj=1
uses subroutine Ni to calculate ((1+i)^N - 1)/i:
Code:
@ X Y
00 { 21-Byte Prgm } i N
01▸LBL "Ni"
02 X=0?
03 GTO 00
04 LN1+X
05 STO× ST Y
06 X<> ST L
07 X<>Y
08 E↑X-1
09 X<>Y
10 ÷
11 RTN
12▸LBL 00
13 +
14 END
Code:
00 { 140-Byte Prgm }
01▸LBL "NPV"
02 MVAR "CF0"
03 MVAR "CFj"
04 MVAR "IRR%"
05 MVAR "NPV"
06 1
07 RCL "IRR%"
08 %
09 LSTO "irr"
10 +
11 LSTO "r"
12 CLX
13 INDEX "CFj"
14 J-
15 J-
16 J+
17 FC? 76
18 GTO 03
19▸LBL 02 @ all Nj=1, use Horner scheme
20 RCLEL
21 +
22 RCL÷ "r"
23 J-
24 FC? 77
25 GTO 02
26 GTO 04
27▸LBL 03 @ CFj Nj, index at Nj
28 RCLEL
29 DSE ST X
30 GTO 00
31 J- @ Nj=1
32 CLX
33 RCLEL
34 +
35 RCL÷ "r"
36 GTO 01
37▸LBL 00 @ Nj>1, group CFj
38 CLX
39 RCL "r"
40 RCLEL
41 Y↑X
42 ÷
43 RCLEL
44 +/-
45 RCL "irr"
46 XEQ "Ni"
47 J-
48 RCLEL
49 ×
50 -
51▸LBL 01
52 J-
53 FC? 77
54 GTO 03
55▸LBL 04
56 RCL+ "CF0"
57 RCL- "NPV"
58 END
example: create the 7x2 matrix
[[1000 1]
[2000 2]
[3000 3]
[4000 4]
[5000 5]
[6000 6]
[7000 7]]
Start the solver: Shift-SOLVER, NPV
store the matrix in CFj
store -100000 in CF0
store 0 in NPV
press IRR% -> 2.0417694...
hope you like it
Werner