Does finance need 128 bit integers?
A blog post yesterday at Marginal Revolution raised the interesting question of whether stock prices should quote in increments of one-hundredth of a cent instead of one cent. That is a very complex question in market micro structure that I do not wish to get into now. But the comment thread on this blog post got into a much more interesting question of how to represent money in a computer.
It is well known that using a floating point number to represent money is a very bad idea – every computer scientist knows that we must use integers for this purpose even if fractions are involved. If we do not have to deal with fractions of a cent, then internally everything should be stored in cents so that a million dollars is represented by 100 million which is well within the range of a 32 bit integer (for example, the long int in ISO C++). If fractions of a cent (say milli-cents) are possible, then everything should be stored in milli-cents and a million dollars is represented by 100 billion which is beyond the range of a 32 bit integer but is well within the range of the more modern 64 bit integer (for example, the long integer in Java).
Dick King commenting at the Marginal Revolution blog post points out that if fractions of one-tenth of a micro-cent are permitted, then a 64 bit integer would allow us to represent up to around a trillion dollars. As he says: “If AAPL ever reaches a market cap of $1 trillion and you decide you want to buy it all you will not be able to place an ordinary order on an ordinary exchange ... sorry about that.” If you really want to be precise about these things, the 64 bit integer takes us only up to a little over $922 billion if you want negative numbers also; if only unsigned quantities are required, then it could take us to $1.8 trillion. But as a rough order of magnitude, we can take one trillion as the upper limit on monetary quantities that can be represented to an accuracy of one micro-cent using 64 bit integers.
I would think that there might be situations where much more than a trillion – perhaps, even a quadrillion – might be needed. In the days before the euro, we used to joke that the word quadrillion was invented to count the Italian public debt (in lire of course). But more seriously, the total open interest in all the global derivative markets is not far short of a quadrillion dollars. Equally, there may be situations where micro cents or nano cents might make sense for micro payments for charging internet transactions. For example, the digital currency Bitcoin (which is valued at approximately one US dollar) allows subdivision up to 8 decimal places or one hundredth of one millionth of a Bitcoin. If we need a single representation for all monetary quantities from 1015 (one quadrillion) to 10-8 (one hundredth of one millionth), the 64 bit integer is simply insufficient. Perhaps, finance will at some point need a 128 bit (16 byte) long integer.
Of course, some people do argue that data structures like Java’s BigInteger that allows arbitrary size of integers should be used. But this arbitrary size comes at a very heavy price. It appears that a Java BigInteger takes about 80 bytes that is five times more than a 128 bit (16 byte) long integer. The performance penalties would also be substantial. While a 128 bit integer would not be sufficient to count the number of protons in the universe, it should be adequate for the full range of monetary quantities that we are likely to encounter for a long time – it will take us from 1021 to 10-15 with a couple of digits to spare.
Posted at 2:04 pm IST on Fri, 25 May 2012 permanent link
Categories: technology
Comments