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.

Saturday, July 18, 2009

On the non-Gaussianness of finanical markets

In 2002, Malcolm Gladwell published an essay in the New Yorker called Blowing Up: How Nassim Taleb turned the inevitability of disaster into an investment strategy.

It is sort of a soft profile of 1) Victor Niederhoffer and 2) Nassim Taleb and his hedge fund (Empirica). Taleb's investment strategy begins by noting that people tend to be risk-averse in an asymmetric way (favoring smaller but steady gains and erratic but larger losses (which, I am inferring, shows up in the behavior of the stock market)) [as shown by Kahneman and Tversky]. Also stock market fluctuations do not really follow a normal distribution/Gaussian distribution/bell curve (which describes the statistics of a bunch of identical but independent things...This was one of the assumptions of the Markowitz model.). If you look at the tails (where the largest fluctuations occur), you find that these large fluctuations are much more likely than a Gaussian distribution would predict (as in, they happen perhaps once every few years rather than once very few millennia). This is referred to casually as "fat tails". Eugene Fama first discovered this, and the mathematician Benoit "Fractal Guy" Mandelbrot wrote a book analyzing this discrepancy and proposing an alternative model of financial markets.

Mandelbrot's calculations show that a Cauchy distribution (a.k.a, Lorentzian distribution) is a better model for such market fluctuations. But is there something better? Probably there are more sophisticated models that require more computation. Fama's collaborator French talks about performing calculations without assuming a distribution. I am looking at academic papers to try to learn more.

Today, Fama argues though that the average passive investor really needs only to know that the Cauchy fat tails mean that market crashes and surges are more likely than many expect. Unfortunately, many non-passive investors operating in the fat tails without understanding them are believed to be responsible for the collapses of Long Term Capital Management, and more recently, AIG.

According to posts on the Bogleheads forum, Taleb's hedge fund had to close because (back in 2004) the excess market volatility that they were betting on was simply not there to earn sufficient profit from.

Saturday, July 11, 2009

The statistics of bombshells and the efficient-market hypothesis

Justin Fox has been promoting his book The Myth of the Rational Market. In this piece for Time Magazine, he summarizes the historical development of the efficient-market hypothesis.

This tantalizing excerpt from the piece, talks about the connection between solving an optimization problem and the mathematics of the market:
A key figure in the revival was the University of Chicago's Milton Friedman... [who] convinced himself and other economists (without much evidence) that speculators tended to stabilize markets rather than unbalance them.

But Friedman was a scientist too. During World War II, he used his mathematical and statistical skills to help determine the optimal degree of fragmentation of artillery shells. Officers flew back to the U.S. in the middle of the Battle of the Bulge to get his advice on the trade-off between the likelihood of hitting the target (the more fragments, the better) and the likelihood of doing serious damage (the fewer and bigger the fragments, the better).

Emboldened by this work, economists began to apply their number-crunching skills to the postwar market. Chicago graduate student Harry Markowitz devised a model for picking stocks that was, in Friedman's estimation, "identical" to his artillery-shell-fragmentation trade-off. And in the late 1950s, scholars at Chicago and the Massachusetts Institute of Technology became enamored of the idea that stock-market movements were, like many physical phenomena, random.

The two strands of statistics and pro-market ideology came together in the mid-1960s. It was the great MIT economist Paul Samuelson who made the case mathematically that a rational market would be a random one.
From browsing the Wikipedia entry on Markowitz, it sounds like his work was the first to incorporate risk (or second moments) in his estimates of the value of a portfolio. Markowitz is also responsible for the concept of the "Efficient Frontier" (the set of all investment portfolios which maximize expected return for a given level of risk) which eventually led to the efficient-market hypothesis. I would still like to know the exact mathematical details of Friedman's modelling...

Wednesday, July 8, 2009

My interest in investing

My current interest in investing started in 2007 when I read an article from San Francisco Magazine called, "The Best Investment Advice You'll Never Get". It starts with a story:
As Google’s historic August 2004 IPO approached, the company’s senior vice president, Jonathan Rosenberg, realized he was about to spawn hundreds of impetuous young multimillionaires. They would, he feared, become the prey of Wall Street brokers, financial advisers, and wealth managers, all offering their own get-even-richer investment schemes. ... [T]o protect Google’s staff, he proposed a series of in-house investment teach-ins... One by one, some of the most revered names in investment theory were brought in to school a class of brilliant engineers, programmers, and cybergeeks on the fine art of personal investing, something few of them had thought much about.
John Bogle and Burton Malkiel gave talks on the statistical superiority of indexed mutual funds and their low fees. Like income taxes, the friction provided by the transaction costs of frequent stock trades or the commission fees of actively managed mutual funds can easily reduce the total value of your investment portfolio by half. You may wind up with more money than you started out with (as investing is not a zero-sum game) but far less than you could have had with a balanced portfolio of index funds.

The simplicity and nonconformity of such thinking appeals to me.

But given that investors using such strategies lost a lot of money in 2008 (knocking out gains from the past five to ten years in some cases), is this still a valid approach? And if so, is it the best approach?

John Bogle was recently quoted as saying:
I read all the time that investors need to move beyond a buy-and-hold strategy, but this strikes me as being a dumb idea. What is the advantage of swapping stock with other people? The stock market system is based on the idea of pitting the interests of one investor against another, knowing that only one will win. People say it's a stock-picker's market but, if your stock picker is good, then mine is bad. It's all a gimmick.
There are other approaches beyond picking stocks and investing in index funds with fixed allocation percentages. At this stage, I still have more questions than answers. In this blog, I will document my attempts to understand economics and learn how to invest.