5 ms·
The SEC probably chose Python because it has a reputation of being easy to read and write. For me the deal killer about Python in particular is that it uses na
by btilly 16y ago
The SEC probably chose Python because it has a reputation of being easy to read and write.
For me the deal killer about Python in particular is that it uses native arithmetic, which means that going from machine to machine, and operating system to operating system any program that uses floating point will have unspecified behavior.
I've worked in finance and dealt with programs that use floating point. I've encountered the fact that behavior changes on different machines. Now a 1 or 2 penny difference on a several million bond flow may seem unimportant, but it is unfortunately very important because the first thing anyone in finance does to verify that two numbers match is look at the first digits, the length of the number, and the pennies. If those agree, you move on.
So those insignificant penny differences are unfortunately the first thing that gets noticed. Been there, done that, not fun.
- jacobolus 16y agoIf you want, you can use the decimal module: http://docs.python.org/library/decimal.html http://docs.python.org/library/decimal.html
- btilly 16y agoYes, you can code these things properly in Python. However my point is that random code produced by a random bond issuer may not behave in a consistent way. And this could have unexpected consequences.
- jacobolus 16y agoAre there many popular languages which have easy support for floating point decimal numbers? (As in, number literals are interpreted as decimals?) Or do you just want them to use a language with floating point binary numbers, but with a consistent implementation on every platform? (That seems pretty far from ideal to me, too.) Or perhaps a better generalization of my question: is there any language which won’t be abused horribly by Joe random bond issuer? Python seems like a pretty good choice for minimizing the damage a clueless guy can do, and making it as possible as can be hoped for others reading even awful code to figure out what it does.
- btilly 16y agoFor their purposes, either have a consistent implementation on every platform or have a clearly specified reference platform for resolving any disputes. But if you say, "This program is authoritative" then you're left with problems if that program gives different results for different people.
- parfe 16y agoFloating point cannot represent money.
- btilly 16y agoFloating point cannot represent money. It shouldn't. But you would be amazed how much bad code there is out there. A lot of it just uses floating point arithmetic because it is easy. (Actually for Monte Carlo simulations it isn't even a bad idea. There speed matters over precision.) (Furthermore you get fun issues when you add in the complication of having multiple currencies that vary against each other.)
- tzs 16y agoWhat would you use to represent money?
- binarysoul 16y agowhole numbers, ie cents 100 cents instead of 1.00 dollars
- tzs 16y agoSo basically integers. Floating point can represent integers, and floating point add, subtract, and multiply on integers is exact, so why not use floating point to represent cents? On a 32-bit machine, using native integers limits you to $40 million dollars or less ($20 million or less if you have to use signed integers). Double precision floating point gives you something like 52-bit integers. When dividing, you would have to explicitly use floor, round, or ceil to make the result be an integer.
- MichaelSalib 16y agoDo you regularly run finance code on machines that are not IEEE-754 compliant? If not, how big a deal are the resulting differences?