Re: WP 34s: Trying to understand SLV Message #8 Posted by Dieter on 28 Oct 2011, 7:21 a.m., in response to message #5 by Miguel Toro
For the record: here is your program with a few modifications. It is the same algorithm with a numeric improvement using ln1+x and e^x1 as well as the changes discussed before. You may use this as a basic version for your own, better and even more reliable program. ;)
The result of the solver now is checked in three ways. Does the solver think it has found a solution? If not, do the last two guesses agree in their first six decimals? If not, is at least the NPV for this result less than half a cent? If not, throw an error, else display the result.
Since I prefer the hotkeys A...D I used these instead of alpha labels. I also prefer to enter an interest rate and then simply press [B] instead of XEQ"NPV", then being prompted for the interest rate and finally get a result.
So here's my current, unfinished and experimental version. Use it at your own risk. BTW it's the first time I used the (dis)assembler  very nice. ;)
001 LBL A
002 SSIZE4
003 CLSTK
004 STO I
005 STO J
006 STO K
007 ALL 03
008 LBL 00
009 CLx
010 CL[alpha]
011 [alpha]'CF'
012 [alpha]IP J
013 [alpha]'[^]n'
014 [alpha]IP J
015 PROMPT
016 x=0?
017 GTO 01
018 STO+ I
019 [cmplx]STO[>]K
020 INC J
021 INC K
022 INC K
023 GTO 00
024 LBL 01
025 RCL K
026 x=0?
027 ERR 15
028 2
029 
030 EEX
031 3
032 /
033 2
034 EEX
035 +/
036 5
037 +
038 STO K
039 RCL I
040 CL[alpha]
041 [alpha] #
042 [alpha]'CF'
043 [alpha] =
044 VW[alpha]+ X
045 RTN
046 LBL B
047 SSIZE4
048 XEQ 02
049 FIX 02
050 CL[alpha]
051 [alpha]'NPV'
052 [alpha] =
053 VW[alpha]+ X
054 RTN
055 LBL C
056 SSIZE4
057 FIX 06
058 CLSTK
059 EEX
060 2
061 SLV 02
062 GTO 05
063 x[approx]? Y
064 GTO 05
065 RCL Z
066 FIX 02
067 ROUND
068 x[!=]0?
069 ERR 20
070 R[v]
071 LBL 05
072 FIX 02
073 CL[alpha]
074 [alpha]'IRR'
075 [alpha] %
076 [alpha] =
077 VW[alpha]+ X
078 RTN
079 LBL 02
080 1
081 STO A
082 %
083 STO I
084 STO B
085 INC B
086 CLx
087 STO C
088 RCL K
089 STO J
090 LBL 03
091 [cmplx]RCL[>]J
092 RCL I
093 x=0?
094 GTO 04
095 LN1+x
096 +/
097 [times]
098 e[^x]1
099 STO A
100 INC A
101 +/
102 RCL/ I
103 RCL[times] B
104 ENTER[^]
105 LBL 04
106 R[v]
107 [times]
108 STO+ C
109 RCL A
110 STO[times] B
111 ISG J
112 GTO 03
113 RCL C
114 RTN
A B C
Start i%=>NPV =>IRR%
Here's the example from the 15C Advanced Solutions Handbook p. 43:
Keys Display
[A] CF0^n0
0.
80000 [ENTER] 1
[R/S] CF1^n1
0.
600 [ENTER] 1
[R/S] CF2^n2
0.
6500 [ENTER] 1
[R/S] CF3^n3
0.
8000 [ENTER] 2
[R/S] CF4^n4
0.
7500 [ENTER] 2
[R/S] CF5^n5
0.
91000 [ENTER] 1
[R/S] CF6^n6
0.
[R/S] #CF=
8.
There are 8 cashflows in total.
Now let's determine the NPV for an interest rate of 9%.
9 [B] NPV=
4108.06
Since the NPV is negative the IRR has to be less than 9%.
What is its value?
[C] IRR%=
8.04
Dieter
