<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/investing-for-the-long-run/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://msperlin.github.io/2018-05-12-Investing-Long-Run/"> Marcelo S. Perlin</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> – </p>
<p>I often get asked about how to invest in the stock market. Not<br>
surprisingly, this has been a common topic in my classes. Brazil is<br>
experiencing a big change in its financial scenario. Historically, fixed<br>
income instruments paid a large premium over the stock market and that<br>
is no longer the case. Interest rates are low, without the pressure from<br>
inflation. This means a more sustainable scenario for low-interest rates<br>
in the future. Without the premium in the fixed income market, people<br>
turn to the stock market.</p>
<p>We can separate investors according to their horizon. Traders try to<br>
profit in the short term, usually within a day, and long-term investors<br>
buy a stock without the intent to sell it in the near future. This type<br>
of investment strategy is called BH (<em>buy and hold</em>). At the extreme,<br>
you buy a stock and hold it forever. The most famous spokesperson of BH<br>
is Warren Buffet, among many others.</p>
<p>Investing in the long run works for me because it doesn’t require much<br>
of my time. You just need to keep up with the quarterly and yearly<br>
financial reports of companies. You can easily do it as a side activity,<br>
parallel to your main job. You don’t need a lot of brain power to do it<br>
either, but it does require knowledge of accounting practices to<br>
understand all the material that is released by the company.</p>
<p>I read many books before starting to invest and one of the most<br>
interesting tables I’ve found portrays the relationship between<br>
investment horizon and profitability. The idea is that the more time you<br>
hold a stock (or index), higher the chance of a profit. The table,<br>
originally from Taleb’s <em>Fooled by Randomness</em>, is as follows.</p>
<p><img src="https://i1.wp.com/msperlin.github.io/img/investing-by-horizon.png?w=300" data-recalc-dims="1"></p>
<p>My problem with the table is that it seems pretty off. My experience<br>
tells me that a 67% chance of positive return every month seems<br>
exaggerated. If that was the case, making money in the stock market<br>
would be easy. Digging deeper, I found out that the data behind the<br>
table is simulated and, therefore, doesn’t really give good an estimate<br>
about the improvement in the probability of profits as a function of the<br>
investment horizon.</p>
<p>As you probably suspect, I decided to tackle the problem using real data<br>
and R. I wrote a simple <a rel="nofollow" href="http://msperlin.github.io/content/others/fct_invest_horizon.R" target="_blank">function</a><br>
that will grab data, simulate investments of different horizons many<br>
times and plot the results. Let’s try it for the SP500 index:</p>
<div>
<div>
<pre><code>source('fct_invest_horizon.R')

my.ticker &lt;- '^GSPC' # ticker from yahoo finance
max.horizon = 255*50 # 50 years
first.date &lt;- '1950-01-01' 
last.date &lt;- Sys.Date()
n.points &lt;- 50 # number of points in figure 
rf.year &lt;- 0 # risk free return (or inflation)

l.out &lt;- get.figs.invest.horizon(ticker.in = my.ticker, 
                                 first.date = first.date, 
                                 last.date = last.date,
                                 max.horizon = max.horizon, 
                                 n.points = n.points, 
                                 rf.year = rf.year)

## 
## Running BatchGetSymbols for:
##    tickers = ^GSPC
##    Downloading data for benchmark ticker | Found cache file
## ^GSPC | yahoo (1|1) | Found cache file - Looking good!

print(l.out$p1)
</code></pre>
</div>
</div>
<p><img alt="" src="https://i0.wp.com/msperlin.github.io/img/2018-05-12-Investing-Long-Run_files/figure-markdown_strict/unnamed-chunk-2-1.png?w=456" data-recalc-dims="1"></p>
<div>
<div>
<pre><code>print(l.out$p2)
</code></pre>
</div>
</div>
<p><img alt="" src="https://i1.wp.com/msperlin.github.io/img/2018-05-12-Investing-Long-Run_files/figure-markdown_strict/unnamed-chunk-2-2.png?w=456" data-recalc-dims="1"></p>
<p>As we can see, the data doesn’t lie. As the investment horizon<br>
increases, the chances of a positive return increases. This result<br>
suggests that, if you invest for more than 13 years, it is very unlikely<br>
that you’ll see a negative return. When looking at the distribution of<br>
total returns by the horizon, we find that it increases significantly<br>
with time. Someone that invested for 50 years is likely to receive a<br>
2500% return on the investment.</p>
<p>With input input <code>rf.year</code> we can also set a desired rate of return.<br>
Let’s try it with 5% return per year, with is pretty standard for<br>
financial markets.</p>
<div>
<div>
<pre><code>my.ticker &lt;- '^GSPC' # ticker from yahoo finance
max.horizon = 255*50 # 50 years
first.date &lt;- '1950-01-01' 
last.date &lt;- Sys.Date()
n.points &lt;- 50 # number of points in figure 
rf.year &lt;- 0.05 # risk free return (or inflation) - yearly

l.out &lt;- get.figs.invest.horizon(ticker.in = my.ticker, 
                                 first.date = first.date, 
                                 last.date = last.date,
                                 max.horizon = max.horizon, 
                                 n.points = n.points, 
                                 rf.year = rf.year)

## 
## Running BatchGetSymbols for:
##    tickers = ^GSPC
##    Downloading data for benchmark ticker | Found cache file
## ^GSPC | yahoo (1|1) | Found cache file - Got it!

print(l.out$p1)
</code></pre>
</div>
</div>
<p><img alt="" src="https://i0.wp.com/msperlin.github.io/img/2018-05-12-Investing-Long-Run_files/figure-markdown_strict/unnamed-chunk-3-1.png?w=456" data-recalc-dims="1"></p>
<p>As expected, the curve of probabilities has a lower slope, meaning that<br>
you need more time investing in the SP500 index to guarantee a return of<br>
more than 5% a year.</p>
<p>Now, let’s try the same setup for Berkshire stock (BRK-A). This is<br>
Buffet’s company and looking at its share price we can have a good<br>
understanding of how successful Buffet has been as a BH (<em>buy and hold</em>)<br>
investor.</p>
<div>
<div>
<pre><code>my.ticker &lt;- 'BRK-A' # ticker from yahoo finance
max.horizon = 255*25 # 50 years
first.date &lt;- '1980-01-01' 
last.date &lt;- Sys.Date()
n.points &lt;- 50 # number of points in figure 
rf.year &lt;- 0.05 # risk free return (or inflation) - yearly

l.out &lt;- get.figs.invest.horizon(ticker.in = my.ticker, 
                                 first.date = first.date, 
                                 last.date = last.date,
                                 max.horizon = max.horizon, 
                                 n.points = n.points, 
                                 rf.year = rf.year)

## 
## Running BatchGetSymbols for:
##    tickers = BRK-A
##    Downloading data for benchmark ticker | Found cache file
## BRK-A | yahoo (1|1) | Found cache file - OK!

print(l.out$p1)
</code></pre>
</div>
</div>
<p><img alt="" src="https://i0.wp.com/msperlin.github.io/img/2018-05-12-Investing-Long-Run_files/figure-markdown_strict/unnamed-chunk-4-1.png?w=456" data-recalc-dims="1"></p>
<div>
<div>
<pre><code>print(l.out$p2)
</code></pre>
</div>
</div>
<p><img alt="" src="https://i2.wp.com/msperlin.github.io/img/2018-05-12-Investing-Long-Run_files/figure-markdown_strict/unnamed-chunk-4-2.png?w=456" data-recalc-dims="1"></p>
<p>Well, needless to say that, historically, Buffet has done very well in<br>
his investments! If you bought the stock and kept it for more 1 year,<br>
there is a 70% chance that you got a profit on your investment.</p>
<p>I hope this post convinced you to start investing. The message from the results are straighforward: <strong>the earliest you start, the better</strong>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://msperlin.github.io/2018-05-12-Investing-Long-Run/"> Marcelo S. Perlin</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/X6kNAYd7fN0" height="1"></a></div>