Simulating the Market

I’ve had a lot of friends and family approach me, asking for investment advice. After building and approaching markets in systematic trading programs for some time, I didn’t have the type of instantaneous hot stock tips I’d feel comfortable giving to a close friend or family member; rather I had market trends, sector correlations and trading strategies. After realizing how far those are from comprehendible or actionable information to an average investor, I felt compelled to research what would happen if people simply bought and held their investments.

Most people should actively avoid “trading” in the stock market. I learned my lesson in high school when I was trading Chinese penny stocks during class on my phone that more than doubled my portfolio in a week, but also blew me up later when I had no risk management measures: which is why I now build and rely on trading systems.

Unless you are a savvy trader, stay in your lane – buy an index, check it in 5 years. Everyone in the industry knows that its a zero-sum game and the institutions have all the resources and are waiting to take the little guy’s money.

What I find interesting is the massive amounts of resources some traditional funds employ to chase down marginal bips without actual, robust risk management measures, whereas the long-term investors such as Warren, exponentially outshine their peers without worrying about the daily market moves; some even boycott the antiquated Bloomberg Terminal. Of course there are a few quant funds quietly and effectively employing strong statistical and MVA tools and whose returns are second to no other investment vehicle, that is what I’m most interested in; data-driven decision making.

“Warren [Buffet], it strikes me that if you did nothing else you never sell. That is, if you can grit your teeth through and just disregard short-term declines in the market or even long-term declines in the market, you will come out well. I mean you just stick all your money in stocks and go home and don’t look at your portfolio you’ll do far better than if you try to trade it.” – Alan Greenspan

The basis for this project is to prove or disprove the efficacy of the buy and hold strategy, more specifically:

  1. Objectively explore past returns, so that all facets of long-term investing (past and present) are explored.
  2. Show that the “Invest Early and Invest Often” adage holds weight, and by how much.
  3. Observe what happens when a “buy and hold” strategy is implemented, and how well that performs.


For comprehensive purposes, using R, I simulated the entire observable history of the stock market. The plots were generated based on past returns in the S&P500. So at Year 1, we take every point on the S&P500 curve, look at every point on the S&P500 that’s one year ahead, add in dividends and subtract inflation, and record all points as a relative gain or loss for Year 1. Then we do the same thing for Year 2. Then Year 3. And so on, ad nauseum. The program took a couple hours to finish crunching all the numbers. I was also testing different ideas so the process took a few days.

In short, for the plots here: If you invest for X years, you have a distribution of Y possible returns, based on previous history.


Since nobody is ever going to live to invest for 145 years, let’s take a look at a more realistic span of investing. Let’s say you start investing at the age of 20, and then retire and subsequently liquidate the entire or part of the account at age 70, which gives you 50 years of investing. So after a quick change subset(stocks,year<=50)


What if the market crashes right before retirement and the world ends up broke and the dollar crashes?

Real risk is not based off of possibilities, it’s based off of probability multiplied by the severity of the event.

Of course, this example only uses stocks to represent historical performance, in practice an ideal portfolio would be well diversified to offset intrinsic risk.

Sky-is-falling headlines are big money-makers for disreputable journalists, and often enough there is no disincentive for these writers to be incorrect. Best to keep the TV off or better yet, not trade based on information you receive!  Information is what drives markets and is the investor’s edge, and since you’re not spending millions of dollars on marginally faster internet speeds, chances are you are late to the party the information is already reflected in the price.


Historical averages can vary widely depending on their starting and ending points, Hence, dollar cost averaging. Some dollars invested will generate a return, and some dollars invested will incur a loss.

Here’s the list of years you can invest, and still be down. Take note that some of these years cover the same eras:

  • Down after 10 years (11.8% chance historically): 1908, 1909, 1910, 1911, 1912, 1929, 1930, 1936, 1937, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1998, 1999, 2000, 2001
  • Down after 15 years (4.73% chance historically): 1905, 1906, 1907, 1929, 1964, 1965, 1966, 1967, 1968, 1969
  • Down after 20 years (0.0664% chance historically): 1901
  • Down after 25 years (0% chance historically): none 


Additional visualisations.SP500CPI


Additional resources:  cFIREsim: open-source portfolio simulator

Data resources: Data collected and synthesized by Robert Shiller for his book, Irrational Exuberance [Princeton University Press 2000, Broadway Books 2001, 2nd ed., 2005], data posted on Shiller’s site.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s