Decimal arithmetic, was Re: Python GUI app to impress the boss?

Robin Becker robin at jessikat.fsnet.co.uk
Sat Sep 21 04:50:10 EDT 2002


In article <7xwupf52jx.fsf at ruckus.brouhaha.com>, Paul Rubin <phr-
n2002b at NOSPAMnightsong.com> writes
>Christopher Browne <cbbrowne at acm.org> writes:
>> REALITY CHECK for a moment.
>> 
>> What do you think A Real Live bank uses to compute interest?
>
>If I had to guess, I'd guess they use floating point.
>
>I do know that financial modelling software I worked on that was sold
>to banks used floating point.  Also, spreadsheets use floating point.
>
>But it's possible (likely even) that some bookkeeping applications use
>BCD.  One that I worked on actually used exact, multi-precision
>rational arithmetic, but I think that's unusual.
>
>Note that the x86/x87 still supports BCD arithmetic in microcode.  In
>reality, though, programs that use BCD to keep track of money don't do
>all that much arithmetic, so software emulation is plenty fast enough.
Well I also worked in finance/research and I agree with Paul and
Christopher. Most trading/research software uses FP, most transactions
are computed using BCD.

The thing about most real financial instruments is that they use fairly
complicated sets of rules to calculate the actual interest and since the
rules evolved before modern computers are mostly computable using
fingers and counting. In particular almost all the calculations have to
be with pre-specified precision and rounding rules.

EG a bond pays fixed amounts of money at pre-specified intervals, no
calculations are involved at all. Of course when I want to compute the
yield or npv I need to do some arithmetic and FP is usually easiest and
faster as well.

Anyhow it seems to me that BCD is pretty good only for additive type
calculations. I can't see that BCD is any better than FP at representing
1/3 unless we go fully rational, but that's another story.
-- 
Robin Becker



More information about the Python-list mailing list