<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/"></div></div><div><a data-url="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/" data-counturl="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/" data-count="horizontal" data-text="A Return.Portfolio Wrapper to Automate Harry Long Seeking Alpha Backtests" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://quantstrattrader.wordpress.com/2016/06/17/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/"> R – QuantStrat TradeR</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This post will cover a function to simplify creating Harry Long type rebalancing strategies from SeekingAlpha for interested readers. As Harry Long has stated, most, if not all of his strategies are more for demonstrative purposes rather than actual recommended investments.</p>
<p>So, since Harry Long has been posting some more articles on Seeknig Alpha, I’ve had a reader or two ask me to analyze his strategies (again). Instead of doing that, however, I’ll simply put this tool here, which is a wrapper that automates the acquisition of data and simulates portfolio rebalancing with one line of code.</p>
<p>Here’s the tool.</p>
<pre>
require(quantmod)
require(PerformanceAnalytics)
require(downloader)

LongSeeker &lt;- function(symbols, weights, rebalance_on = &quot;years&quot;, 
                       displayStats = TRUE, outputReturns = FALSE) {
  getSymbols(symbols, src='yahoo', from = '1990-01-01')
  prices &lt;- list()
  for(i in 1:length(symbols)) {
    if(symbols[i] == &quot;ZIV&quot;) {
      download(&quot;https://www.dropbox.com/s/jk3ortdyru4sg4n/ZIVlong.TXT&quot;, destfile=&quot;ziv.txt&quot;)
      ziv &lt;- xts(read.zoo(&quot;ziv.txt&quot;, header=TRUE, sep=&quot;,&quot;, format=&quot;%Y-%m-%d&quot;))
      prices[[i]] &lt;- Cl(ziv)
    } else if (symbols[i] == &quot;VXX&quot;) {
      download(&quot;https://dl.dropboxusercontent.com/s/950x55x7jtm9x2q/VXXlong.TXT&quot;, 
               destfile=&quot;vxx.txt&quot;)
      vxx &lt;- xts(read.zoo(&quot;vxx.txt&quot;, header=TRUE, sep=&quot;,&quot;, format=&quot;%Y-%m-%d&quot;))
      prices[[i]] &lt;- Cl(vxx)
    }
    else {
      prices[[i]] &lt;- Ad(get(symbols[i]))
    }
  }
  prices &lt;- do.call(cbind, prices)
  prices &lt;- na.locf(prices)
  returns &lt;- na.omit(Return.calculate(prices))
  
  returns$zeroes &lt;- 0
  weights &lt;- c(weights, 1-sum(weights))
  stratReturns &lt;- Return.portfolio(R = returns, weights = weights, rebalance_on = rebalance_on)
  
  if(displayStats) {
    stats &lt;- rbind(table.AnnualizedReturns(stratReturns), maxDrawdown(stratReturns), CalmarRatio(stratReturns))
    rownames(stats)[4] &lt;- &quot;Max Drawdown&quot;
    print(stats)
    charts.PerformanceSummary(stratReturns)
  }
  
  if(outputReturns) {
    return(stratReturns)
  }
} 
</pre>
<p>It fetches the data for you (usually from Yahoo, but a big thank you to Mr. Helumth Vollmeier in the case of ZIV and VXX), and has the option of either simply displaying an equity curve and some statistics (CAGR, annualized standard dev, Sharpe, max Drawdown, Calmar), or giving you the return stream as an output if you wish to do more analysis in R.</p>
<p>Here’s an example of simply getting the statistics, with an 80% XLP/SPLV (they’re more or less interchangeable) and 20% TMF (aka 60% TLT, so an 80/60 portfolio), <a target="_blank" href="http://seekingalpha.com/article/3981831-strategy-hitting-sharpe-3-ytd">from one of Harry Long’s articles</a>.</p>
<pre>
LongSeeker(c(&quot;XLP&quot;, &quot;TLT&quot;), c(.8, .6))
</pre>
<p>Statistics:</p>
<pre>

                          portfolio.returns
Annualized Return                 0.1321000
Annualized Std Dev                0.1122000
Annualized Sharpe (Rf=0%)         1.1782000
Max Drawdown                      0.2330366
Calmar Ratio                      0.5670285
</pre>
<p>Equity curve:</p>
<p><img src="https://i1.wp.com/imgur.com/dXVmzvK.png"></p>
<p>Nothing out of the ordinary of what we might expect from a balanced equity/bonds portfolio. Generally does well, has its largest drawdown in the financial crisis, and some other bumps in the road, but overall, I’d think a fairly vanilla “set it and forget it” sort of thing.</p>
<p>And here would be the way to get the stream of individual daily returns, assuming you wanted to rebalance these two instruments weekly, instead of yearly (as is the default).</p>
<pre>
tmp &lt;- LongSeeker(c(&quot;XLP&quot;, &quot;TLT&quot;), c(.8, .6), rebalance_on=&quot;weeks&quot;,
                    displayStats = FALSE, outputReturns = TRUE)
</pre>
<p>And now let’s get some statistics.</p>
<pre>
table.AnnualizedReturns(tmp)
maxDrawdown(tmp)
CalmarRatio(tmp)
</pre>
<p>Which give:</p>
<pre>
> table.AnnualizedReturns(tmp)
                          portfolio.returns
Annualized Return                    0.1328
Annualized Std Dev                   0.1137
Annualized Sharpe (Rf=0%)            1.1681
> maxDrawdown(tmp)
[1] 0.2216417
> CalmarRatio(tmp)
             portfolio.returns
Calmar Ratio         0.5990087
</pre>
<p>Turns out, moving the rebalancing from annually to weekly didn’t have much of an effect here (besides give a bunch of money to your broker, if you factored in transaction costs, which this doesn’t).</p>
<p>So, that’s how this tool works. The results, of course, begin from the latest instrument’s inception. The trick, in my opinion, is to try and find proxy substitutes with longer histories for newer ETFs that are simply leveraged ETFs, such as using a 60% weight in TLT with an 80% weight in XLP instead of a 20% weight in TMF with 80% allocation in SPLV.</p>
<p>For instance, here are some proxies:</p>
<p>SPXL = XLP<br>
SPXL/UPRO = SPY * 3<br>
TMF = TLT * 3</p>
<p>That said, I’ve worked with Harry Long before, and he develops more sophisticated strategies behind the scenes, so I’d recommend that SeekingAlpha readers take his publicly released strategies as concept demonstrations, as opposed to fully-fledged investment ideas, and contact Mr. Long himself about more customized, private solutions for investment institutions if you are so interested.</p>
<p>Thanks for reading.</p>
<p>NOTE: I am currently in the northeast. While I am currently contracting, I am interested in networking with individuals or firms with regards to potential collaboration opportunities.</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quantstrattrader.wordpress.com/473/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/quantstrattrader.wordpress.com/473/" border="0"></a> <img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=quantstrattrader.wordpress.com&blog=66155974&%23038;post=473&%23038;subd=quantstrattrader&%23038;ref=&%23038;feed=1" border="0"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/"></div></div><div><a data-url="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/" data-counturl="http://www.r-bloggers.com/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/" data-count="vertical" data-text="A Return.Portfolio Wrapper to Automate Harry Long Seeking Alpha Backtests" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://quantstrattrader.wordpress.com/2016/06/17/a-return-portfolio-wrapper-to-automate-harry-long-seeking-alpha-backtests/"> R – QuantStrat TradeR</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/7JNTb6aoIBc"></a></div>