📜 ⬆️ ⬇️

32nd format (thirty seconds)

In working with trading systems, I stumbled upon an unusual format for representing numbers representing quotations of securities, in particular for US government bonds. For example, the price represented as 100-31 does not mean 100 dollars and 31 cents, or 100-127 makes little sense at all, since there is only 100 cents in a single dollar, not 1000, and there is no need to reserve three signs for the fractional part after comma.

The whole trick here is that this is not a familiar decimal notation. For example, 100-31 in decimal form is 100.97265625 , and 100-127 corresponds to 100.40234375 .

So, this format for recording fractional numbers is called “thirty seconds” or 32nd . For visual convenience and a clear difference from the decimal form, a small dash is used as a separator instead of a dot. And the number itself has the following general format:

AAA.XXY

where AAA is the integer part of the number, which has the same meaning as in the decimal system. XX is the number of 1/32 of the fractional part, and Y is the number of eighties ( 1/8 ) in the last 1/32 fraction. Despite the vague description, the formula for converting the number AAA.XXY in 32nd format to decimal format is quite simple:
')
D = AAA + (XX + Y * 1/8) * 1/32

or

D = AAA + XX * (1/32) + Y * (1/256)

that is, for the number 100-127 AAA = 100, XX = 12, Y = 7, therefore:

D = 100 + 12/32 + 7/256 = 100.40234375

For the formula to be correct, XX can take values ​​only from "00" to "31" , and Y from "0" to "7" . Also, when writing Y number 4 can be replaced by + , and the "0" by a space. That is, 100-31 in the complete record form is 100-310 , and 100-12+ equivalent to 100-124 .

It can be seen that in three fractional digits not 1000 parts are encoded, as in the decimal system, but only 256 (32 * 8).

So again: if 100-12+ is written, then this is 100.39062500 in the decimal system.

The formula for reverse translation from decimal representation to 32nd format is not much more complicated. Let D decimal number:

A = TRUNC(D)
XX = TRUNC((D - A) * 32)
Y = ((D - A) * 32 - XX) * 8

TRUNC is the function of taking the whole part.

If Y is 0, then you can not write this bit, and if 4, you can replace with + .

Component Y should turn out necessarily integer. Otherwise, the presence of the fractional part of Y is a sign that the original decimal number D has no mapping to 32nd format (only 256 fractional part values ​​out of all 1000 possible can have a match in 32nd format).

No matter how bizarrely this way of recording money looks, it is used by traders (not to be confused with raiders), for example, when trading US government bonds. I can assume that this is just a legacy of the times when not everyone knew fractional decimal numbers, and the recording of parts of the whole in the form of natural fractions is much closer to the nature of man. Divide the pile into two, three, etc. parts can even be a child untrained by decimals.

The format is strange, but you have to know it.

Source: https://habr.com/ru/post/83967/


All Articles