PC-1211, PC-1250, etc. TVM
|
06-12-2024, 12:29 AM
Post: #41
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-11-2024 10:32 PM)dm319 Wrote:(06-11-2024 07:13 PM)robve Wrote: An improved version of the TVM program for SHARPs. Thanks. I still want to give the Albert's suggested modified Newton's method a try to compare efficiency of TVM rate calculations, but haven't had the time yet. Working in non-IEEE754 is a pain. Some things just don't work out numerically as we're stuck with 10 digits to store in variables (internal calculations are 12 digits). Results and behaviors of the C implementation don't necessarily translate, as can be expected, hence the challenge. The current method finds the root with a few NPMT evaluations. I was surprised that some roots are found in just 3 evaluations as you can see in the results. Now, I'm curious how the SHARP PC-1421 fares on these TVM problems. I don't have access to one at the moment, but could try an emulator. It's a machine that supports TVM operations on the keypad but also directly within BASIC, i.e. setting TVM variable PV=x is just an assignment. Computing is done with e.g. COMP PMT that updates the PMT variable. It also has cash flow and IRR calculations. This should be very handy to write specialized financial applications (which is not my thing). It seems that the PC-1421 was not popular, perhaps because financial people don't write BASIC? Wrong target audience? The machine is a bit weird and that's why it intrigues me. - Rob "I count on old friends to remain rational" |
|||
06-12-2024, 05:20 AM
Post: #42
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-09-2024 01:22 PM)rprosperi Wrote:(06-08-2024 09:21 PM)robve Wrote: [snip] Prime v1 with latest firmware also returns -50 |
|||
06-12-2024, 12:45 PM
Post: #43
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-12-2024 12:29 AM)robve Wrote: Working in non-IEEE754 is a pain. Some things just don't work out numerically as we're stuck with 10 digits to store in variables (internal calculations are 12 digits). I'm curious - can you elaborate on this? In C I am presuming you are using binary rather than decimal. When you mean IEEE754 do you mean floating point binary or decimal? I've always thought doing maths stuff in binary is a pain as we generally view the results in decimal, which makes it hard to determine accuracy in terms of the number of decimal points. (06-09-2024 01:22 PM)rprosperi Wrote: Using an HP-27S, I get -50 exactly. In keeping with the emulated HP-30b I guess. I suspect the HP-27s is similar to the HP-17b and onwards, but I wouldn't mind more data... (06-12-2024 05:20 AM)nickapos Wrote: Prime v1 with latest firmware also returns -50 Exactly? That is a little disappointing. |
|||
06-12-2024, 04:25 PM
(This post was last modified: 06-13-2024 05:16 PM by Albert Chan.)
Post: #44
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(07-11-2022 09:08 PM)Albert Chan Wrote: I just realized there is no financial function called NPMT (we do have NPV, NFV) Just want to clear up meaning of NPMT. It is not "Net Payment" ... more like "N Payments". Function used for rate search is f = NPMT/n (sometimes refer as npmt function) Technically, time-symmetry is exactly what you expected when viewing film backwards: {n,i,pv,pmt,fv} ↔ {-n,i,fv,-pmt,pv} NPMT is time-symmetrical (same value with time-symmetry transform) npmt is not. Because of n denominator, we had to negate it to preserve the same result. {n,i,pv,pmt,fv} ↔ {-n,i,fv,-pmt,pv} --> negate --> {-n,i,-fv,pmt,-pv} Warning: To count sign changes for possible solutions, we should use (n*pmt) Time symmetry will give same sign changes either way, even if negated. {pv,n*pmt,fv} ↔ {fv,(-n)*(-pmt),pv} = {fv,n*pmt,pv} |
|||
06-12-2024, 04:58 PM
Post: #45
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-12-2024 12:45 PM)dm319 Wrote:(06-12-2024 12:29 AM)robve Wrote: Working in non-IEEE754 is a pain. Some things just don't work out numerically as we're stuck with 10 digits to store in variables (internal calculations are 12 digits). It's about the internals. IEEE754 binary representations and operations must meet a set of requirements to ensure accuracy and to support +/-0 +/-inf and subnormals, guard and sticky bits/digits. That is not the case for 10 or 12 BCD vintage calculators (they may use one to three guard digits, but not consistently). Also, repeated internal rounding is not beneficial, actually it is "evil". Rounding problems lead to all sorts of numerical problems, hence IEEE754 offers a set of rounding flags to control this. IEEE754 also defines decimal representations that must meet this set of requirements. IEEE754 operations in an implementation must be correctly rounded. When considering implementations, implementing IEEE754 surely takes more effort. I did this in Z80 for Forth850 to support IEEE754 single precision with all requirements including rounding modes (but statically) except for subnormals (maybe sometime...). To determine accuracy, I don't tend to think in the number of decimal places, but epsilon relative or absolute error. Decimal places do offer a quick insight, but it is useless otherwise. A silly example is 1.499999999 and 1.500000000 which only differ in 1E-9 but share no common digits except the first 1. Now 1.499999999 and 1.49999999 are further apart (9E-9). One benefit of BCD is for accurate financial calculations perhaps, because amounts such as $0.01 are represented exactly whereas it is not in binary float (it's not 0.01 exactly but 0.010000000000000000208 in double precision). This matters for long running sums and in accumulation loops and when comparing totals. On the other hand, why people claim this but don't scale amounts by a factor 100 to avoid this is beyond me. - Rob "I count on old friends to remain rational" |
|||
06-12-2024, 05:01 PM
Post: #46
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-12-2024 12:45 PM)dm319 Wrote: I've always thought doing maths stuff in binary is a pain as we generally view the results in decimal, Actually, error analysis is simpler if algorithm use binary math. Example, decimal with 3 digits precision: 0.999 --> 1 ULP = relative error 0.001 / 0.999 ≈ 0.001 0.100 --> 1 ULP = relative error 0.001 / 0.100 ≈ 0.010 With possible 10 fold difference in relative error, some algorithm may not work at all! For binary, factor is at most 2 (only in extreme case), and we may ignore this. Regarding bin ↔ dec ↔ bin conversion errors, if you stick with integers, there is no difference. For money, instead of using dollars as unit, use cents! https://www.lua.org/pil/2.3.html Wrote:There is a widespread misconception about floating-point arithmetic errors and some people fear that even a simple increment can go weird with floating-point numbers. The fact is that, when you use a double to represent an integer, there is no rounding error at all (unless the number is greater than 100,000,000,000,000). Specifically, a Lua number can represent any long integer without rounding problems. Moreover, most modern CPUs do floating-point arithmetic as fast as (or even faster than) integer arithmetic. And, for equivalent precision, binary setup tends to run much, much faster. This is the reason mpmath choose Python integer type, over Decimal type https://fredrikj.net/blog/2017/10/mpmath...ospective/ Wrote:When I started sympy.numerics, Python already had the arbitrary-precision Decimal type in the standard library, but I found that it was a lot more efficient to emulate binary floating-point arithmetic using Python's arbitrary-precision long integers. It was especially fast to do fixed-point arithmetic this way: an addition is just an addition, and a multiplication (a * b) >> shift requires just one extra operation, whereas a floating-point operation with rounding requires something like 50 Python bytecode instructions. Implementing core operations (like elementary functions) mostly using fixed-point arithmetic internally made it possible to achieve reasonable performance ... BTW, Decimal type may "cheat" using binary math! Example, IntelDecimal128, used in Free42/Plus42 https://www.cl.cam.ac.uk/~jrh13/slides/a...slides.pdf |
|||
06-22-2024, 12:12 PM
Post: #47
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
Very intereting Rob and Albert.
That's a good point about using cents. I only realised yesterday that Excel and LO Calc use double binary rather than decimal, which surprised me because I know Excel is established in finance. It looks like the display value is rounded, so I'm sure most accountants wouldn't notice this. Also interesting re: the rounding. Is the rounding done beyond the last digit? I.e. if you're rounding to the precision available, that implies you've calculated to beyond that? I'm still slightly unsure I get the concept of ULP 'accuracy'. Whereas, as you mention Rob, absolute and relative error seems a sensible approach. |
|||
06-22-2024, 12:47 PM
Post: #48
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
(06-22-2024 12:12 PM)dm319 Wrote: I only realised yesterday that Excel and LO Calc use double binary rather than decimal ... Do you really know how your spreadsheet works? Oops, XL did it again Quote:Also interesting re: the rounding. Is the rounding done beyond the last digit? I.e. if you're rounding to the precision available, that implies you've calculated to beyond that? Not sure about decimal, but for binary, all you need is 3 extra bits: guard, round, and sticky |
|||
06-22-2024, 08:39 PM
(This post was last modified: 06-23-2024 08:07 PM by robve.)
Post: #49
|
|||
|
|||
RE: PC-1211, PC-1250, etc. TVM
Updated Newton and Hybrid implementations with SHARP PC-1403H TVM test results.
The improved and combined SHARP BASIC TVM program listing includes both parts for the Hybrid and Newton rate solver methods: Code: ' Switch begin mode on/off: DEF-B The Hybrid version executes faster on this machine and its overall accuracy is at least as good as Newton or better (for the set of test cases and other tests that were not included in the results because of similarity). Add these four lines to compute amortization with <period> DEF-A: Code: 50 "A" AREAD A : J=.01*I,R=P-F,T=0,V=0 - Rob "I count on old friends to remain rational" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)