Home

Daily Speculations The Web Site of Victor Niederhoffer and Laurel Kenner

12-May-2006
Encoding prices as Binary Codes, from Philip J. McDonnell

Claude Shannon's work on information theory demonstrated conclusively that all information could be efficiently represented in binary code. This breakthrough enabled tremendous advances in digital communications. In addition nearly every computer since that time has used some form of binary storage for both numbers and character oriented information.

With recent discussion of information theory it is appropriate to note that price patterns can be conveniently encoded as binary patterns as well. For example if a day was up that would be a 1 (one) bit and if it was down it would be a 0 (zero). Binary representation only has two digits 1 and 0.

Our everyday decimal system is based on powers of 10. Consider the number 123 - one hundred and twenty three. The right most digit 3 is multiplied by 10 to the zero power. Any number to the zero power is equal to 1. So the result is 3 times 1. The 2 is multiplied by 10 and the 1 is multiplied by 10 to the second power or 100. Add it all up and the result is 123.

Now let us convert the number 6 into binary. The powers of two we need are 1, 2, 4, then 8, 16,... To convert we divide the number by the highest power which can divide into it. We divide by 4 and get a remainder of 2. Now divide by 2 and get a remainder of zero - we are finished. The following table shows the powers of two in their places:

8 4 2 1
0 1 1 0  = 6 (decimal)

The order is the same as decimal notation in that the least significant place is the rightmost ones place and the 2 squared, cubed etc going to the left. To convert 6 into binary we only had to divide by 4 and 2 and so those are the only two positions which show a 1 digit in the binary representation of the number 6. The rest are zero.

To use this to construct character codes for price patterns we could take the last 3 days of up down net change and assign 1 if up and 0 if down. The pattern + - + would take on the code 101. Here is a table of the first 8 binary numbers:

decimal      binary
  0           000
  1           001
  2           010
  3           011
  4           100
  5           101
  6           110
  7           111

              421  Binary Place Values

So to convert our pattern + - + to binary we add 4 * 1 plus 2 * 0 plus 1 * 1 to get 5 (=4+1). Because we all think in decimal it is fine to use it as the number 5. The important point is that we are talking about bucket or bin number five. So if we are studying what happens the day after a number 5 pattern we put all those results into bin number five. Thus from the bin 5 results we can calculate the average, standard deviation and probability of being up after that pattern is seen. The same principal applies to the other bins.

Another different use for such bins is to calculate the entropy of all the bins for a recent period. In an earlier study I found that increased entropic diversity tended to be followed by better markets than other periods. One simple measure of this would be to take the last 8 non-overlapping periods of 3 days and set up the bins as described above. We now look at how many fell into each of the 8 bins. The maximum diversity is achieved when each bin contains exactly 1 observation. The minimum is when all observations fall into only one bin. So our resulting statistic is a number from 1 through 8 which can be checked for its relationship to subsequent market performance.

A slight refinement of this would be to do a more sophisticated entropy calculation using a summation of the logs of estimated probabilities per Shannon's original formula.