Post Reply 
Reinventing the TVM wheel
05-12-2014, 08:29 PM (This post was last modified: 05-12-2014 08:33 PM by Ángel Martin.)
Post: #1
Reinventing the TVM wheel
Being an old-school engineer has good and bad things, I 'sppose. Amongst the good ones is keeping a safety distance from the financial stage and associated frills; for instance the TVM implementations. But no more - finally my curiosity was piqued enough to take a peek at the insides of the TVM, with the goal being a full 41 MCODE version (what else...)

I should have known there was a reason not to touch that with a 12-foot pole - no doubt you all know about the intricacies involved in solving for the interest rate the equation, so it won't come as a surprise that after successfully solving the other 4 cases (N, PV, PMT and FV) I'm now stuck.

Not only the Newton convergence is extremely critical, but for the first time ever my trusty 13-digit OS routines are acting up:- either I've completely forgotten how to use it, or there are bugs in them (and either option is equally disturbing)...

There's very valuable information in this thread, but I can't find any follow-up in the archives anymore - even if I remember reading more in the forum. Would you point me in the right direction? I'm hoping somebody has solved the riddle (which is obviously possible, just refer to the HP-12C for the perfect example with a coconut CPU).

Thanks in advance,
'AM

PS. In case you're interested see the blueprint below - it has all five functions but the interest rate is still a FOCAL program... still a work in progress.
Find all posts by this user
Quote this message in a reply
05-12-2014, 08:40 PM
Post: #2
RE: Reinventing the TVM wheel
ok, I found the treasure trove!

Time to read all about them.
Find all posts by this user
Quote this message in a reply
05-12-2014, 09:32 PM
Post: #3
RE: Reinventing the TVM wheel
(05-12-2014 08:40 PM)Ángel Martin Wrote:  ok, I found the treasure trove!

Time to read all about them.

I was just about to point you to that thread. Smile

It kind of trails off at the end, as some health issues have caused me to put the TI-95 aside temporarily. I was getting pretty good results with what was discussed in that thread, but the project stalled at needing to find a better iterative solver routine that doesn't fall apart with overflow/underflow in more extreme scenarios. I was just using a direct port of the simplistic root finder from the HP 20S built-in program "library"; strange that the TI-95 doesn't have any kind of built-in solver routine, because it's got a heck of a lot of other cool stuff. I think the math library module might have one, but it isn't really designed for being called from other programs.
Visit this user's website Find all posts by this user
Quote this message in a reply
05-13-2014, 03:31 AM
Post: #4
RE: Reinventing the TVM wheel
(05-12-2014 08:40 PM)Ángel Martin Wrote:  
Code:

[url=http://www.hpmuseum.org/forum/thread-1012.html?highlight=tvm]treasure trove![/url]

That highlight-feature is nice! However, wadsworth=1 doesn't work unfortunately.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
05-13-2014, 04:11 AM
Post: #5
RE: Reinventing the TVM wheel
Franz contributed the TVM routine for the WP 34S library. Looking Ingo it may help.

d:-)
Find all posts by this user
Quote this message in a reply
05-13-2014, 04:45 PM (This post was last modified: 05-13-2014 08:59 PM by Ángel Martin.)
Post: #6
RE: Reinventing the TVM wheel
I admit that it got me worried but finally the issue is resolved - it turns out I had made a silly *mistake* in the formulas for the derivatives (shame, shame...). Once that was corrected I got the full suite to work in glorious MCODE; hah, the sweet taste of success...

I've tried the few examples from the 15C advanced functions manual as well as the tricky one form the forum posts - with correct results as expected. However it'll be good to test it more, anyone interested?

I cannot post the blueprint (ran out of allotted space it appears) until I delete previous attachments from other posts - so I posted the MOD file in a ZIP container... send me an email if you're up for it.

Thanks to all for your replies and Sylvain for sending the docs in the mail.

PS. Don't sell your HP-12C just yet - found one instance returning wrong results, will work on it soon.

To be continued...
Find all posts by this user
Quote this message in a reply
05-13-2014, 09:39 PM
Post: #7
RE: Reinventing the TVM wheel
Be sure to look at the PPC Journal FIN program write-up. Had lots of examples of tricky situations.

Don't stop with TVM. :-) How about CashFlow as well ? IRR and NPV?
Find all posts by this user
Quote this message in a reply
05-15-2014, 05:34 AM (This post was last modified: 05-15-2014 05:36 AM by Ángel Martin.)
Post: #8
RE: Reinventing the TVM wheel
(05-13-2014 09:39 PM)Gene Wrote:  Be sure to look at the PPC Journal FIN program write-up. Had lots of examples of tricky situations.

Thanks for reminding me of FI's documentation - a wealth and always a joy to read the PPC Manual. In fact that gave me the idea to round off the TVM module with both the Advantage's and the PPC's versions added to it, as well as the application programs from the manuals.

(05-13-2014 09:39 PM)Gene Wrote:  Don't stop with TVM. :-) How about CashFlow as well ? IRR and NPV?

Nice try Gene but I won't pick up the gantlet :-) We know MCODE is unforgiving but for some reason this mini-project has been surprisingly sticky, what a bear to handle with those finicky issues: every change I made to the code to optimize the accuracy resulted in worse results, It's beyond me at this point so I will leave it as is - after all, "the better is the enemy of the good", right?

Cheers,
'AM
Find all posts by this user
Quote this message in a reply
05-15-2014, 05:37 AM (This post was last modified: 05-15-2014 05:49 AM by Ángel Martin.)
Post: #9
RE: Reinventing the TVM wheel
(05-14-2014 12:57 PM)fhub Wrote:  Have you seen my TVM & CashFlow program on my webite? Wink
http://fhub.jimdo.com/

No I haven't yet - thanks for the pointer... but I won't promise a 41MCODE version of it any time soon!

Do you have any documentation on approach used, formulas, etc?

Cheers,
'AM
Find all posts by this user
Quote this message in a reply
05-15-2014, 11:50 PM
Post: #10
RE: Reinventing the TVM wheel
Actually, I meant the FIN program (a refinement of the PPC ROM FI program). I have put it here for you. :-)

FIN Documentation
Find all posts by this user
Quote this message in a reply
05-18-2014, 06:02 PM (This post was last modified: 05-18-2014 08:39 PM by Ángel Martin.)
Post: #11
RE: Reinventing the TVM wheel
Got it... and have added it to the TVM Module as per your request :-) See the attached.

The "-PPC FIN" section includes both the "original "FI" and the enhanced "FIN"; as well as the application programs "LPAS" and "FAST". I haven't tried the examples, I'm hoping someone else will...

Also in there new MCODe versions of CJ and JC - what a drag those two have been, devilish formulas that got much more difficult in MCODE but... just to prove that it can be done.

The re-invented TMV functions all have a "$" sign as last character of the name - so you can tell them apart from the Advantage versions. Both sets use compatible registers so you can use them interchangeably (nice to compare speed and accuracy).

They use the data entry flag (F22) to control whether it's an input or it's a command to calculate the value. If you have a 12C you'll be immediately comfortable with the new set.

A new idea is the launcher version - TVM$ - which prompts for the function to execute: 1-5 are the classic functions; 0 is to toggle B/E, and 6 gives you a listing of all values.

A QRG should follow... in a few days or so.

Cheers,
'AM
Find all posts by this user
Quote this message in a reply
05-18-2014, 06:26 PM
Post: #12
RE: Reinventing the TVM wheel
Just to add my usual Thank you, Ángel

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
05-18-2014, 08:21 PM
Post: #13
RE: Reinventing the TVM wheel
Agreed, the TVM module is a great addition! Many thanks!
Find all posts by this user
Quote this message in a reply
05-18-2014, 08:43 PM (This post was last modified: 05-19-2014 05:40 AM by Ángel Martin.)
Post: #14
RE: Reinventing the TVM wheel
Here's the module again, now with XROM 22 (same as the 41-advantage's) and an auto-assignment of the main functions upon the ON event. Note that they're assigned to the SHIFTED keys to avoid conflicts with the Advantage's TVM and the PPC FI & FIN...

PS. see post below for the updated revision 1D
Find all posts by this user
Quote this message in a reply
05-19-2014, 12:37 AM (This post was last modified: 05-19-2014 01:37 AM by Sylvain Cote.)
Post: #15
RE: Reinventing the TVM wheel
Hello Angel,

Thank you for keeping the 41 alive! Smile

I have downloaded your new TVM ROM.
I then burn-it into a Clonix-D (it's the only ROM inside the module).
The setup for this test was: HP-41CX-HN, 2-X-MEM, Clonix-D

When I do a CAT 2 this is what I see (partial listing)

-TVM$ 1C
%T
B/E
CORR
COV
,*` , ,s a [not a valid label here]
FV$
I$
...
CJ
`CP
`FAST
`FI
`'e)B::(CX(B [not a valid label either]
JDAY
...

There seems to be something wrong with the CAT 2 listing.
I will do more tests with the 41CL, the i41CX (iOS) and Genesis-41 (OSX)

The auto assign works, the TVM calculation seems to works with very basic tests.
I should have some time tomorrow for more testing ...

Best regards,

Sylvain

Edit: I have the same CAT 2 behaviour on the Genesis-41 simulator.
Find all posts by this user
Quote this message in a reply
05-19-2014, 05:39 AM (This post was last modified: 05-19-2014 11:16 AM by Ángel Martin.)
Post: #16
RE: Reinventing the TVM wheel
(05-19-2014 12:37 AM)Sylvain Cote Wrote:  Hello Angel,

I have downloaded your new TVM ROM.
I then burn-it into a Clonix-D (it's the only ROM inside the module).

There seems to be something wrong with the CAT 2 listing.

Sorry for the trouble Sylvain - the customary glitches in the most visible part: the FAT! (I was totally exhausted last night, but it's pretty embarrassing). Here's the 1D version with hopefully all solved.

Still a few areas for improvement, like perhaps using an optimized initial guess for the interest solver.

BTW the format for the date functions (JDAY and DAYS) is MM,DDYYYY - regardless of the time module settings if you have one. The function DAYS is taken from the HP Securities Pac (labeled JDAY there, very confusing I know). It isn't documented in the manual but it calculates the number of days between two dates in X and Y, also in the same MM,DDYYYY format. Or I should say it gets close to it, since the value returned isn't correct! (maybe that's why it wasn't documented :-).

On the other hand function CJ keeps the compatibility with the PPC ROM for data input, i.e. uses Year, Month, and Day in stack registers {Z,Y,X}. To clarify:

CDAY = JC, Julian to Calendar Date
JDAY = CJ, Calendar to Julian day NUMBER

Thanks for taking the time to try it and sorry about the stupid glitch.

Cheers,
'AM


Attached File(s)
.zip  TVM Module_1D.ZIP (Size: 9.49 KB / Downloads: 12)
Find all posts by this user
Quote this message in a reply
Post Reply 




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