<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/leverage-up-when-youre-down/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://quantstrattrader.wordpress.com/2017/09/05/leverage-up-when-youre-down/"> R – QuantStrat TradeR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This post will investigate the idea of reducing leverage when drawdowns are small, and increasing leverage as losses accumulate. It’s based on the idea that whatever goes up must come down, and whatever comes down generally goes back up.</p>
<p>I originally came across this idea from this <a rel="nofollow" href="http://www.vixstrategies.com/simple-way-outperform-xiv/" target="_blank">blog post.<br>
</a></p>
<p>So, first off, let’s write an easy function that allows replication of this idea. Essentially, we have several arguments: </p>
<p>One: the default leverage (that is, when your drawdown is zero, what’s your exposure)? For reference, in the original post, it’s 10%. </p>
<p>Next: the various leverage levels. In the original post, the leverage levels are 25%, 50%, and 100%. </p>
<p>And lastly, we need the corresponding thresholds at which to apply those leverage levels. In the original post, those levels are 20%, 40%, and 55%.</p>
<p>So, now we can create a function to implement that in R. The idea being that we have R compute the drawdowns, and then use that information to determine leverage levels as precisely and frequently as possible.</p>
<p>Here’s a quick piece of code to do so:</p>
<pre>
require(xts)
require(PerformanceAnalytics)

drawdownLev &lt;- function(rets, defaultLev = .1, levs = c(.25, .5, 1), ddthresh = c(-.2, -.4, -.55)) {
  # compute drawdowns
  dds &lt;- PerformanceAnalytics:::Drawdowns(rets)
  
  # initialize leverage to the default level
  dds$lev &lt;- defaultLev
  
  # change the leverage for every threshold
  for(i in 1:length(ddthresh)) {
    
    # as drawdowns go through thresholds, adjust leverage
    dds$lev[dds$Close &lt; ddthresh[i]] &lt;- levs[i]
  }
  
  # compute the new strategy returns -- apply leverage at tomorrow's close
  out &lt;- rets * lag(dds$lev, 2)
  
  # return the leverage and the new returns
  leverage &lt;- dds$lev
  colnames(leverage) &lt;- c(&quot;DDLev_leverage&quot;)
  return(list(leverage, out))
}
</pre>
<p>So, let’s replicate some results.</p>
<pre>
require(downloader)
require(xts)
require(PerformanceAnalytics)


download(&quot;https://dl.dropboxusercontent.com/s/jk6der1s5lxtcfy/XIVlong.TXT&quot;,
         destfile=&quot;longXIV.txt&quot;)


xiv &lt;- xts(read.zoo(&quot;longXIV.txt&quot;, format=&quot;%Y-%m-%d&quot;, sep=&quot;,&quot;, header=TRUE))
xivRets &lt;- Return.calculate(Cl(xiv))

xivDDlev &lt;- drawdownLev(xivRets, defaultLev = .1, levs = c(.25, .5, 1), ddthresh = c(-.2, -.4, -.55))
compare &lt;- na.omit(cbind(xivDDlev[[2]], xivRets))
colnames(compare) &lt;- c(&quot;XIV_DD_leverage&quot;, &quot;XIV&quot;)

charts.PerformanceSummary(compare['2011::2016'])
</pre>
<p>And our results look something like this:</p>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev.png?w=456" data-orig-size="818,521" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev.png?w=456?w=300" data-attachment-id="1250" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/05/leverage-up-when-youre-down/xivddlev/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev.png?w=456?w=640" alt="xivddlev" data-image-title="xivddlev" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1250" data-recalc-dims="1"></p>
<pre>
                          XIV_DD_leverage       XIV
Annualized Return               0.2828000 0.2556000
Annualized Std Dev              0.3191000 0.6498000
Annualized Sharpe (Rf=0%)       0.8862000 0.3934000
Worst Drawdown                  0.4870604 0.7438706
Calmar Ratio                    0.5805443 0.3436668
</pre>
<p>That said, what would happen if one were to extend the data for all available XIV data?</p>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev2.png?w=456" data-orig-size="808,505" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev2.png?w=456?w=300" data-attachment-id="1255" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev2.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/05/leverage-up-when-youre-down/xivddlev2/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/xivddlev2.png?w=456?w=640" alt="xivddlev2" data-image-title="xivddlev2" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1255" data-recalc-dims="1"></p>
<pre>
> rbind(table.AnnualizedReturns(compare), maxDrawdown(compare), CalmarRatio(compare))
                          XIV_DD_leverage       XIV
Annualized Return               0.1615000 0.3319000
Annualized Std Dev              0.3691000 0.5796000
Annualized Sharpe (Rf=0%)       0.4375000 0.5727000
Worst Drawdown                  0.8293650 0.9215784
Calmar Ratio                    0.1947428 0.3601385
</pre>
<p>A different story.</p>
<p>In this case, I think the takeaway is that such a mechanism does well when the drawdowns for the benchmark in question occur sharply, so that the lower exposure protects from those sharp drawdowns, and then the benchmark spends much of the time in a recovery mode, so that the increased exposure has time to earn outsized returns, and then draws down again. When the benchmark continues to see drawdowns after maximum leverage is reached, or continues to perform well when not in drawdown, such a mechanism falls behind quickly.</p>
<p>As always, there is no free lunch when it comes to drawdowns, as trying to lower exposure in preparation for a correction will necessarily mean forfeiting a painful amount of upside in the good times, at least as presented in the original post.</p>
<p>Thanks for reading.</p>
<p>NOTE: I am currently looking for my next full-time opportunity, preferably in New York City or Philadelphia relating to the skills I have demonstrated on this blog. My LinkedIn profile can be found <a rel="nofollow" href="https://www.linkedin.com/in/ilyakipnis/" target="_blank">here.</a> If you know of such opportunities, do not hesitate to reach out to me.</p>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/quantstrattrader.wordpress.com/1218/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/quantstrattrader.wordpress.com/1218/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></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="https://quantstrattrader.wordpress.com/2017/09/05/leverage-up-when-youre-down/"> R – QuantStrat TradeR</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 alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/DleHecEJgSM" height="1"></a></div>