Saturday, August 22, 2009

Electronic mind reader

I am reading Fortune's Formula: The Untold Story of the Scientific Betting System that Beat the Casinos and Wall Street It is a simply amazing book for anyone interested in the intersection of information theory and investing.

Claude Shannon plays a major role in this book, and I've been researching him on the side. He wrote an internal Bell Labs paper called "A Mind-Reading (?) Machine" in 1953. It is freely available here.

The first paragraph reads:
This machine is a somewhat simplified model of a machine designed by D.W. Hagelbarger. It plays what is essentially the old game of matching pennies or "odds and evens." This game has been discussed from the game theoretic angle by von Neumann and Morgenstern, and from the psychological point of view by Edgar Allen Poe in the "The Purloined Letter." Oddly enough, the machine is aimed more nearly at Poe's method of play than von Neumann's.
Before going further, you may wish to try out an online implementation of Shannon's mind-reading device yourself. You can find it here:

"The Purloined Letter" is definitely a good story to read in thinking about this subject... The "odds and evens" game is much like Rock, Paper, Scissors, in that I have also heard of people who were able to model their opponent's though processes (based on the patterns played in the game to that point) and then anticipate their next move. This is all that Shannon's machine is doing. Except that it looks at patterns only three moves long.

The part of the story Shannon refers is this excerpt:
"The measures, then," he continued, "were good in their kind, and well executed; their defect lay in their being inapplicable to the case, and to the man. A certain set of highly ingenious resources are, with the Prefect, a sort of Procrustean bed, to which he forcibly adapts his designs. But he perpetually errs by being too deep or too shallow, for the matter in hand; and many a schoolboy is a better reasoner than he. I knew one about eight years of age, whose success at guessing in the game of 'even and odd' attracted universal admiration. This game is simple, and is played with marbles. One player holds in his hand a number of these toys, and demands of another whether that number is even or odd. If the guess is right, the guesser wins one; if wrong, he loses one. The boy to whom I allude won all the marbles of the school. Of course he had some principle of guessing; and this lay in mere observation and admeasurement of the astuteness of his opponents. For example, an arrant simpleton is his opponent, and, holding up his closed hand, asks, 'are they even or odd?' Our schoolboy replies, 'odd,' and loses; but upon the second trial he wins, for he then says to himself, the simpleton had them even upon the first trial, and his amount of cunning is just sufficient to make him have them odd upon the second; I will therefore guess odd'; --he guesses odd, and wins. Now, with a simpleton a degree above the first, he would have reasoned thus: 'This fellow finds that in the first instance I guessed odd, and, in the second, he will propose to himself upon the first impulse, a simple variation from even to odd, as did the first simpleton; but then a second thought will suggest that this is too simple a variation, and finally he will decide upon putting it even as before. I will therefore guess even' guesses even, and wins. Now this mode of reasoning in the schoolboy, whom his fellows termed "lucky," --what, in its last analysis, is it?"

"It is merely," I said, "an identification of the reasoner's intellect with that of his opponent."

"It is," said Dupin;" and, upon inquiring of the boy by what means he effected the thorough identification in which his success consisted, I received answer as follows: 'When I wish to find out how wise, or how stupid, or how good, or how wicked is any one, or what are his thoughts at the moment, I fashion the expression of my face, as accurately as possible, in accordance with the expression of his, and then wait to see what thoughts or sentiments arise in my mind or heart, as if to match or correspond with the expression.' This response of the schoolboy lies at the bottom of all the spurious profundity which has been attributed to Rochefoucauld, to La Bougive, to Machiavelli, and to Campanella."

"And the identification," I said, "of the reasoner's intellect with that of his opponent, depends, if I understand you aright upon the accuracy with which the opponent's intellect is admeasured."
Back to the online version of Shannon's Mind Reader. Not knowing how it worked, I was still able to beat the machine for a while (until I went off to figure out how it worked). A snapshot from the end of my game is shown. The black bar on the bottom indicates the percentage of games won by the machine.

Then, as a control case, I tried a comparable number of clicks, using a sequence of random numbers generated from Octave (admittedly, these are pseudo-random, but they should be good enough). The results was actually a bit worse, implying that this simple Mind Reader can be outsmarted. The corresponding snapshot indicates a score closer to 50%.

I did suspect one thing before playing against the Mind Reader: It was based on human predictability, which I tried to avoid. It's like the classic statistics course demonstration where the professor asks the students to generate a random sequence (ones and zeros, heads and tails), and he can tell if it was generated by an actual random process or by a student trying to do an impression of a random process. Humans tend to avoid long strings of ones or zeros, incorrectly assuming that 1010110 is more random than 1111000. Knowing this, I tried to avoid obvious patterns.
A mathematical analysis of the strategy used in this machine shows that it can be beaten by the best possible play in the ratio 3:1. To do this it is necessary to keep track of the contents of all the memory cells in the machine. The player should repeat a behavior pattern twice, and then when the machine is prepared to follow this pattern the player should alter it. It is extremely difficult to carry out this program mentally because of the amount of memory and calculation necessary.

All of the above seems to have a lot of relevance to trying to predict how the average person will invest money. I intend to look into the work of von Neumann and Morgenstern to understand their approach to the problem.

Sunday, August 9, 2009

Is it possible to succeed through day-trading?

I am reading Beat the Market by Ed Thorp and Sheen Kassouf, which has the subtitle "A Scientific Stock Market System".

In the first few pages, he discusses "chartists" which sound very much like what we now call "day traders".
Chartists, or technicians, believe that patterns of past price performance predict future performance. They rely solely on price and volume statistics from the ticker tape, claiming that insiders have already acted by the time statistics such as sales, earnings, orders, and dividends are published. Technicians claim that various configurations on their charts, such as heads and shoulders, triangles, wedges, and fans, repeat themselves over and over again, signaling the start and the reversal of price trends. Thus by studying price charts, they believe they can detect trends soon enough to profit from them.

Chart reading seems scientific but it isn't. For instance, the most celebrated of all technical theories is the Dow Theory. Richard Durant's What Is the Dow Theory? asserts that $100 invested in the Dow-Jones industrial average in 1897 would have grown to $11,237 by 1956 if these stocks were sold and repurchased whenever the Dow Theory gave the appropriate signal. This is equivalent to 8.3% compounded annually. By comparison, the University of Chicago's Center for Research in Security Prices found that random buying and selling of stock from 1926 to 1960 would have averaged a 9% gain per annum, about what the Dow Theory claims to have earned by design.

My doubts about chart reading were strengthened by a test I gave to people who claimed to be able to "read" charts. I selected pages at random from a chart book, covered the name of the corporation and the last half of the chart, and asked what price change the "pattern" indicated. Their "predictions" were no better than those of someone making random guesses!
It seems that most day-traders lose money... 80 to 90 percent, if this Slate article Day Trading is for Suckers is to be believed. And worse:
The thing that is most remarkable about day trading, though, is the almost complete absence of a coherent investment theory that could justify the practice. If you read Warren Buffett or Peter Lynch or John Burr Williams, you get a clear sense of the principles that guide their investing. But if you talk to day traders and try to figure out why they believe they can beat the market, you don't get any real ideas. You just get a host of anecdotes about great trades.

I had mostly dismissed the idea of day-trading as my understanding of investing has come from proponents of index funds and long-term investments, but a friend had recently suggested that long-term investing is hard because you need to know things about companies to be successful (which may be true if you define success as beating the index funds), whereas short-term investing is a game you can potentially win at just by studying price movements. From all of the above and because there is friction in the form of high transaction fees to overcome, I tend to conclude that, assuming it can be done at all, this is a very hard thing to do.

Ernie Chan's blog discusses quantitative and algorithmic trading and investment schemes. There seems to be a lot of sound analysis from the standpoint of information theory. Skimming through the posts, I did not immediately find evidence that such strategies can be successful. The closest I have found so far is a post called In praise of day-trading which ends this way:
Let me tell you a little secret: in my years working for hedge funds and prop-trading groups in investment banks, I have seen all kinds of trading strategies. In 100% of the cases, traders who have achieved spectacularly high Sharpe ratio (like 6 or higher), with minimal drawdown, are day-traders.
The Sharpe ratio is defined to be (the rate of return minus the rate of return of some risk-free investment (like CDs)) divided by the standard deviation of this value. It is essentially the signal-to-noise ratio of the extra return you get from taking risk on a particular investment. There is no indication of what kind of strategies these successful day-traders were using, nor over what period they were able to sustain such high returns, but the implication is that, for some people, day-trading can work.