{"id":656,"date":"2009-02-23T23:27:35","date_gmt":"2009-02-24T03:27:35","guid":{"rendered":"\/blog\/?p=656"},"modified":"2009-12-17T00:47:23","modified_gmt":"2009-12-17T05:47:23","slug":"log-transform","status":"publish","type":"post","link":"https:\/\/www.holypotato.net\/?p=656","title":{"rendered":"Log Transform"},"content":{"rendered":"<p>I was playing around with some data analysis here at work, and decided that I&#8217;d try to do a little log transform on some stock market data. Generally, you expect the market to increase exponentially over the long term. This leads to some pretty big numbers after some time, so a chart looks something* like this:<\/p>\n<p><img src='\/wp-content\/djia001.gif' alt='DJIA over 100 years' title='DJIA over 100 years'\/><\/p>\n<p>It&#8217;s an impressive chart, however the thing about exponential growth is that after a century we&#8217;re dealing with some very large numbers. In fact, the last few decades seem to dominate the chart: the recent market crash and the tech issues in the 2000&#8217;s appear, on that chart, to be way worse than the great depression, which looks like a small blip in the 30&#8217;s down in the bottom of the range. We could of course zoom in on that region:<\/p>\n<p><img src='\/wp-content\/djia_30s.gif' alt='DJIA focus on 1925-1934' title='DJIA focus on 1925-1934' \/><\/p>\n<p>Showing that there was a big nasty swing in there. <\/p>\n<p>So one way to better look at data over the real long term like this is to do a log transform (in this case, I chose base 10). That takes an exponential growth curve and makes it linear. Now instead of being dollar value up the y-axis, we now have powers of 10.<\/p>\n<p><img src='\/wp-content\/djia_log_002.gif' alt='Log (base 10) transformation of DJIA, 100 years' title='Log (base 10) transformation of DJIA, 100 years' \/><\/p>\n<p>This is a different way to view the data. To my eye, the long-term trends seem to stick out more, and the current crisis can be put into perspective with past issues. The stock market crash of the 30&#8217;s, from about 380 to 41 was a fall of almost 90%, or about a drop of one power of ten, which would be 1 unit on the logarithmic scale. Right now we&#8217;re down about 50%, or 0.3 on the log scale.<\/p>\n<p>I like looking at the log plot, because it shows that over the span of multiple decades that there is some consistency to the stock market going up, and that while this recent disappointment is crushing (down another 3+% today!) it&#8217;s not totally unprecedented. It also helps restore my sanity after reading some extreme bears who point to that 100-year chart and say that the world went crazy in 1985 and everything that happened after that was crazy and volatile and that if we fit a line to the rest we&#8217;d be back down to 2000-4000 and that&#8217;s where the Dow is heading! Of course that&#8217;s really just an artifact of the magnification of exponential growth &#8212; you can&#8217;t fit a linear trend to an exponential curve (ok, for small values you can, which is exactly the error they&#8217;re making!). If you want to draw a straight line, then you should work from the log plot. While I don&#8217;t put too much faith in chart divination, I think I might have this one printed off:<\/p>\n<p><img src='\/wp-content\/djia_log_trendline.gif' alt='DJIA 1940-present with trendline' title='DJIA 1940-present with trendline' \/><\/p>\n<p>The market can underperform for a long time (the market can stay irrational longer than you can stay solvent, as the saying goes), but with a timespan of 20-30 years (when I&#8217;ll be 50-60) it should come back to that long-term trend. It doesn&#8217;t help me figure out when we&#8217;ll bottom, or when we&#8217;ll get back up, or even for sure if that&#8217;s an accurate projection of what will happen in the future, but it will help me sleep better knowing that essentially all of my net worth is subject to the whims of the market. For the curious, here&#8217;s what that same trendline looks like on the untransformed data:<\/p>\n<p><img src='\/wp-content\/djia_exponential_trend.gif' alt='DJIA with exponential trendline' \/><\/p>\n<p>Exponential growth is everywhere in nature, but I bet at least half of you are shaking your heads at that 25,000 by 2020 extrapolation! It&#8217;s just so hard to wrap your head around numbers that large, though that would only be a ~6% return per year from the peak (about 11% per year from where we are now).<\/p>\n<p>* &#8211; Note, I was getting some Y2K errors with the data I have (starting from 1900 &#8212; I just did a Google search for DJIA historical data and took the first one), I think I fixed it up, but might have made some mistakes. <a href=\/wp-content\/djia100nographs.txt title='DJIA 100 year data tab delimited; date YYMMDD, DJIA $, DJIA Log_10'>Feel free to fix if you like<\/a>. To improve on this analysis you can include dividends, inflation, and compare multiple countries (I doubt things would look as good in Japan, for example) or run a monte carlo with sample portfolios to get some confidence intervals. These are left as exercises for the reader.<\/p>\n<p>Also, for those on the RSS feed, the images may not come through. Try viewing in your <a href=\"http:\/\/www.holypotato.com\/?p=656\">web browser<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was playing around with some data analysis here at work, and decided that I&#8217;d try to do a little log transform on some stock market data. Generally, you expect the market to increase exponentially over the long term. This leads to some pretty big numbers after some time, so a chart looks something* like [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/www.holypotato.net\/index.php?rest_route=\/wp\/v2\/posts\/656"}],"collection":[{"href":"https:\/\/www.holypotato.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.holypotato.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.holypotato.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.holypotato.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=656"}],"version-history":[{"count":0,"href":"https:\/\/www.holypotato.net\/index.php?rest_route=\/wp\/v2\/posts\/656\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.holypotato.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.holypotato.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.holypotato.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}