State Space Models

All state space models are written and estimated in the R programming language. The models are available here with instructions and R procedures for manipulating the models here here.

Monday, November 25, 2013

Eugene Fama and the Random Stock Walker



The video above was posted by Index Fund Advisors (IFA) congratulating Eugene Fama on winning the 2013 Nobel Price in Economics. IFA specializes in passive index fund investing, an investment strategy developed by Eugene Fama and Dimensional Fund Advisors (Fama sits on the board of Dimensional). The passive investing strategy is based on two simple, controversial hypotheses with many subtle implications: the Random Walk Hypothesis (RWH) and the Efficient Market Hypothesis (EMH). RWH and EMH are of great interest because they describe the null hypothesis in all Random Stock Walker models. Fama's Nobel prize provides an opportunity to develop the hypotheses.

A random walk in prices is described by the following equation:


where P is the price and E is an error term. A random walk model says the tomorrow's prices are a function of today's prices plus random error. Since the value for the error term cannot be predicted, the model also means that prices following a random walk cannot be forecast. 

Under what conditions might a price follow a random walk? Consider the basic market model:


where quantity demanded and quantity supplied depend on prices. If demand is higher than prices, supply increases to meet demand. The coefficients b and d determine how responsive quantities are to prices. The coefficients a and c are the level of demand and supply, respectively, when prices are zero. If a=c and b=d (they could all be zero, also) or are effectively very close (not statistically different), then the price in this market is a random walk.

The EMH argues that in an efficient market, where information is widely and rapidly available, supply and demand should adjust very quickly, that is, the response coefficients should be very similar. The market might drift predictably over time if a > c, and here is where passive investment comes in. If you invest in an index fund that drifts over time, you might expect to make some money--how much depends on how much drift and the direction of drift. If you try to actively trade stocks in this market, you are basically gambling (allowing the error term, E, to determine your earnings).

Fama also developed another important idea for the Random Stock Walker: the so-called joint-hypothesis problem. If your models are not working, you cannot tell whether it is an imperfection in the model or an imperfection in the market. You can only try to find a better model and even the best model you can find using brute force multi-model inference will be incomplete. 

The empirical evidence for the RWH and the EMH is extensive and contradictory. For the Random Stock Walker, most stocks either show growth, decline or stagnation. Using the AIC and multi-model inference, the RW null hypothesis can almost always be rejected. On the other hand, this doesn't mean you can uses models to make money in the stock market. There are periods when the markets are not predictable and, to paraphrase John Maynard Keynes, these periods can last longer than you can stay solvent.

One of the most unusual subtle implications of accepting the RWH and the EMH is that market bubbles cannot exist, a conclusion Eugene Fama has not been shy about publicizing. After the Dot-com Bubble, Subprime Mortgage Bubble, the Japanese Asset Price Bubble, etc. it's would seem hard to accept that markets always produce rational prices. But, that is a topic for another post when the work of another 2013 Nobel Prize winner, Robert J. Shiller, is discussed.

If awards are given to people we should emulate, then Eugene Fama certainly deserves a major award and the Noble Prize in Economics certainly is one. He has had the prototypical, successful academic career. He took a collection of ideas, the RWH and the EMH, and pushed them both theoretically and empirically as hard as they could be pushed. Whether he turns out to be right, wrong or somewhere in between, he did exactly what every academic is supposed to do. Science will have to sort out the rest.

Sunday, October 20, 2013

A Random Walk Through Old Stockholm


On October 14, 2013 Eugene Fama, Lars Peter Hansen and Robert Shiller were jointly awarded the Nobel Prize in Economics. Each recipient's award was given for topics of interest to the Random Stock Walker: Fama for his work on the Efficient Market Hypothesis (EMH) which is closely related to the Random Walk Model; Hansen for his work on the Generalized Method of Moments (GMM) estimator (a semi-parametric model related to the non-parametric bootstrap); Shiller for his work on economic bubbles (his approach is closely related to Attractor Theory). The 2013 Nobel Prize in Economics is also interesting because the work of Fama and Shiller seem, on the surface, to contradict each other. In future posts, I'll discuss each researcher's work in detail (also see John Cochrane's blog, here, and the Noah Opinion blog, here, here, here, here, here and here). For right now, here is the Random Walker summary:
  • The strong-form of EMH asserts that all stock prices are a random walk because all information is immediately reflected in the stock price. The random walk is one of the models that is always tested by the Random Stock Walker, essentially as a null-model. Fama has been particularly critical of economic bubbles and Technical Analysis, arguing that in the short-run active management and fundamental analysis add nothing that isn't immediately available in the stock price.
  • The GMM estimator is semi-parametric in that normal theory is not required for every part of the model. The bootstrap is non-parametric and makes no assumptions about the mathematical form of the model error distribution.
  • Shiller used the ex-post rational price (the discounted sum of actual dividends) as the assumed attractor for a stock price. Shiller shows that the actual price varies a lot more than the ex-post rational price. This is a form of fundamental analysis which not only contradicts the EMH but also begs the question of what drives the ex-post rational price. The Random Stock Walker submits a collection of other fundamental models (business-as-usual, US economy, World System, Market Index, etc. along with the Random Walk) to multi-model inference using the Akaike Information Criteria rather than using probabilities drawn from the normal distribution.
From the Random Stock Walker perspective, this is the most interesting Nobel Prize in Economics. The implications for investing (favor low-fee index funds, invest for the long run) are important to understand but incomplete (how does the buy-and-hold strategy relate to stock market bubbles, particularly when the bubble pops just when you need retirement funds). The implications for economic theory are profound (are consumers and investors really profit maximizers or are they just trying to survive in a very uncertain world). The purpose of the Nobel Prize in Economics should be not just to reward achievement but also to draw our attention to a body of work that has important implications for the future development of economics. From the perspective of the Random Stock Walker, the 2013 Nobel Prize did all these things.

The title of this post is derived from a book by Burton Malkiel title A Random Walk Down Wall Street. The Nobel Museum is located in Old Stockholm at Stortorget 2, 103 16 in Stockholm, Sweden. Here's an appropriate if somewhat nerdy question: How long would it take you to find the Nobel Museum if you started at the Myntgatan bridge in Old Stockholm, flipped a coin and used the result to decide which way to turn at each interaction, that is, took a random walk through Old Stockholm?

Tuesday, May 14, 2013

ADR: Should Sony Be Broken Up?



In somewhat of a minor market bombshell announcement (here), Third Point Hedge Fund Investor Daniel Loeb called for the breakup of the multinational conglomerate Sony (the Sony group includes electronics, motion pictures, music and financial services). The argument, discussed in the Bloomberg video above, is that parts of Sony, particularly the US-based Sony Pictures Entertainment, doesn't really fit the rest of the company and should be spun off.

The issue that caught the attention of the Random Stock Walker was whether or not it would be best for Sony to disengage from the US economy. After WWII and until the 1980's (the beginning of Neoliberalism and Globalization), Sony was a dynamic company linked closely to the US market. They originally licensed transistor technology from Bell Laboratories and found a large US market for the Walkman. Sony acquired Columbia Pictures in 1989 and the CBS Record Group in 1989. The argument to divest the US-based business units seems to be based on culture fit. A more interesting question is whether Sony would be more successful as an electronics supplier to the World economy, allowing the company to be driven by the World economy as I have show Apple is (here).
To test the Sony break-up proposal, I ran two state space models. In the first one, the Sony stock price (ADR) was driven by the World economy and, in the second one, below, by the US economy (the testing was a little more far ranging, but these were the two best models). The attractor forecast for a world economy-driven Sony shows exponential growth for the future (the black line is the actual stock value, the dashed red line is the dynamic attractor path created from a free simulation, and the other two lines are the upper and lower 98% bootstrap prediction intervals). Although Sony stock has had some brief "bubble and trough" years around 2008, 2009 and 2001, the stock has generally followed the cyclical path of the world system.

The same can be said for the model driven by the US economy. In fact the attractor tracking seems to be somewhat better. However, the future projection does not look very good. In fact, the attractor path seems to suggest that tracking the US economy too closely is driving much of the cyclicality in Sony stock.

The obvious conclusion from these two simulations is that Sony must link its fortunes with the World economy and make sure it is insulated from cyclical forces transmitted from the US economy. Whether this means spinning off the US entertainment divisions, however, is another matter. Everything depends on how much of their revenue is driven by the world economy, and that would be require a detailed level of analysis that the Random Stock Walker does not pursue!

Monday, May 13, 2013

Are We In A Stock Market Bubble?

In a recent tweet (here), political economist Robert Reich issued a "Wall Street Bubble Alert" referencing a Business Week article (here) in which Goldman Sachs claims that "...the market is at or above where it should be trading." The CNBC technical analysts, however, don't see it that way.



In the video above, technical analyst Michael Harris claims that "..from a trend-channel perspective, this is one of the most beautiful patterns I have seen in some time."

I've duplicated the "trend channel" (sometimes called a price channel) in my forecast at the beginning of the post. The graph of ^GSPC (the S&P 500 index) shows the actual index path (black line), the dynamic attractor path (dashed red line) and the upper and lower 98% bootstrap prediction intervals (dotted green line and dot-dash blue line, respectively). The "trend channel is presented as solid heavy red lines. My attractor forecast shows that the S&P 500 index is above the 98% bootstrap prediction interval and this may be the start of a stock market bubble. Whether we are in for another massive bubble, such as the one centered on 2000, remains to be seen.

Technical analysis focused on trend channels misses all this because the time period considered is restricted to the start of the last upswing. The trend channel, to be clear, is simply constructed by connecting peaks and troughs from the start of the last upswing. That's it. There's nothing more to the trend channel than plotting lines by hand. Since this kind of analysis is quite common on Wall Street, it may actually contribute to the development of a market bubble if it is believed by enough investors. If you follow this type of technical investing model, your dilemma will be "when to get out of the market," that is, when will the bubble burst. Trend channel analysis doesn't have much to say about that issue and neither does attractor analysis, which is saying right now to start selling since the S&P 500 is above the 98% upper bootstrap prediction interval.

It will be an interesting summer in the stock market!


Wednesday, January 16, 2013

Stock Market Recap for 2012

It's time to look back at last year's Stock Market and see what, if anything, the Random Stock Walker learned. This blog is largely based on ideas from Burton Malkiel's book A Random Walk Down Wall Street. I first read Malkiel's book in 1975 and it has always been a big influence on my views of the Stock Market and of investing. However, I have also been a little uncomfortable with the lessons I took from the book and last year I set out to give some of the ideas a test.

Malkiel's basic hypothesis is that the Stock Market is a random walk, that is, today's stock price is given by yesterday's stock price plus random error P(t) = P(t-1) + E. If this is true, the implications for investing are shocking. Since you cannot predict the movement of a random walk, investing is just gambling. Your financial analyst and commentators on CNBC are basically selling snake oil. The counter argument is that stocks do seem to have trends over time and minimally might perform like a random walk with drift, P(t) = a + P(t-1) +E, where a is the drift parameter. As long as a is positive, you can expect to make a little money over time as long as your profits aren't eaten up by taxes, trading fees and investment fees (this argument is made by Andrew Lo and Archie MacKinlay in their book A Nonrandom Walk Down Wall Street, follow the link to read the free on-line pdf file).

After reading these two books and living through a few financial crises (Savings and Loan CrisisDot-com bubble, Subprime Mortgage Crisis, etc.), I have to admit that Malkiel's book is more fun to read and very appealing. However, I have always had nagging doubts. Maybe some stocks aren't random walks. If you could identify them, maybe they would be good investments. Also, being a statistician, I knew I could write a program that could test to see whether or not a stock or some market index was a random walk. The strategy would be to do this for a few years and see how the models perform. I now have a few year's worth of data.


The most important stock I had to watch last year was Apple computer (AAPL) since I owned it from 1988 to September of 2012. I sold the stock just short of the peak in September of 2012. Why?


The basic answer is the graph above taken from a February 2012 post (here) when CNBC commentators were speculating that AAPL would hit 500 within the week. My models were showing two things: AAPL was not a random walk and 500 would not be reached until half way through 2013. We are two weeks into 2013, and AAPL is 509 today, still a little over-valued given my models.

The dotted red line in the graph above is the attractor path for AAPL while the dotted green and blue lines are the upper and lower 98% prediction intervals, respectively. Anytime AAPL gets out of the upper 98% prediction interval, my models start screaming SELL and when the stock price gets below the attractor value, the models say BUY. As for AAPL, I haven't bought back in and there wouldn't be much reason to until the stock starts trending over 500. Currently, some CNBC analysts are saying that AAPL has bottomed out (here) while others are saying that the company's problems that are not going away anytime soon (here). The next few years will tell.

Unlike individual stocks, Malkiel argues that index funds provide great investment opportunities because of low fees and consistent performance, that is, they are not random walks, supposedly because the index usually consist of the best stocks on a particular exchange. In October of 2012, I took a look at the Dow Jones Industrial Average (DJI) in terms of the 1987 Flash Crash (here). The DJI was of interest because flash crashes appear to be a new feature of investing driven by program trading. Can we be sure the DJI is not a random walk?

My models suggest that the DJI is not a random walk but rather that it's attractor path is being driven by the US economy. Unfortunately, for long periods during the late 1980's, the DJI was well below its attractor path. If you had your savings in a DJI index fund, had retired during this period and needed the money, you might be taking some losses. Investing in index funds are, evidently, no guarantee of good performance at any given point in time.

In summary, the Random Stock Walker investigations for 2012 are inconclusive. Some stocks are not random walks and some index funds are not random walks. This doesn't mean that you can simply identify a stock that is being driven by the world economy (as is AAPL) or an index who's attractor is being driven by the US economy (as is the DJI), and do some log-term buy-and-hold investing. If a stock gets too far above its attractor, it would be smarter to sell. The bubble may not last forever and who knows what might happen in the future. Index funds can also also be subject to bubbles (as was true of the DJI during 1987) and the return to the attractor (the bubble-popping "Flash Crash") can be rapid. What's worse, the index can under-perform for years afterward.

If I look back a littler further, into 2011, the are some other lessons about identifying stocks that I will cover in a future post.