<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/the-kelly-criterion-does-it-work/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://quantstrattrader.wordpress.com/2017/09/29/the-kelly-criterion-does-it-work/"> 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 be about implementing and investigating the running Kelly Criterion — that is, a constantly adjusted Kelly Criterion that changes as a strategy realizes returns.</p>
<p>For those not familiar with the Kelly Criterion, it’s the idea of adjusting a bet size to maximize a strategy’s long term growth rate. Both <a rel="nofollow" href="https://en.wikipedia.org/wiki/Kelly_criterion" target="_blank">https://en.wikipedia.org/wiki/Kelly_criterion</a><a rel="nofollow" href="https://en.wikipedia.org/wiki/Kelly_criterion" target="_blank">Wikipedia</a> and <a rel="nofollow" href="http://www.investopedia.com/articles/trading/04/091504.asp" target="_blank">Investopedia</a> have entries on the Kelly Criterion. Essentially, it’s about maximizing your long-run expectation of a betting system, by sizing bets higher when the edge is higher, and vice versa.</p>
<p>There are two formulations for the Kelly criterion: the Wikipedia result presents it as mean over sigma squared. The Investopedia definition is P-[(1-P)/winLossRatio], where P is the probability of a winning bet, and the winLossRatio is the average win over the average loss.</p>
<p>In any case, here are the two implementations.</p>
<pre>
investoPediaKelly &lt;- function(R, kellyFraction = 1, n = 63) {
  signs &lt;- sign(R)
  posSigns &lt;- signs; posSigns[posSigns &lt; 0] &lt;- 0
  negSigns &lt;- signs; negSigns[negSigns > 0] &lt;- 0; negSigns &lt;- negSigns * -1
  probs &lt;- runSum(posSigns, n = n)/(runSum(posSigns, n = n) + runSum(negSigns, n = n))
  posVals &lt;- R; posVals[posVals &lt; 0] &lt;- 0
  negVals &lt;- R; negVals[negVals > 0] &lt;- 0; 
  wlRatio &lt;- (runSum(posVals, n = n)/runSum(posSigns, n = n))/(runSum(negVals, n = n)/runSum(negSigns, n = n))
  kellyRatio &lt;- probs - ((1-probs)/wlRatio)
  out &lt;- kellyRatio * kellyFraction
  return(out)
}

wikiKelly &lt;- function(R, kellyFraction = 1, n = 63) {
  return(runMean(R, n = n)/runVar(R, n = n)*kellyFraction)
}
</pre>
<p>Let’s try this with some data. At this point in time, I’m going to show a non-replicable volatility strategy that I currently trade.</p>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/volsince2011.png?w=456" data-orig-size="803,522" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/volsince2011.png?w=456?w=300" data-attachment-id="1307" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/volsince2011.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/29/the-kelly-criterion-does-it-work/volsince2011/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/volsince2011.png?w=456?w=640" alt="volSince2011" data-image-title="volSince2011" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1307" data-recalc-dims="1"></p>
<p>For the record, here are its statistics:</p>
<pre>
                              Close
Annualized Return         0.8021000
Annualized Std Dev        0.3553000
Annualized Sharpe (Rf=0%) 2.2574000
Worst Drawdown            0.2480087
Calmar Ratio              3.2341613
</pre>
<p>Now, let’s see what the Wikipedia version does:</p>
<pre>
badKelly &lt;- out * lag(wikiKelly(out), 2)
charts.PerformanceSummary(badKelly)
</pre>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/badkelly.png?w=456" data-orig-size="808,517" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/badkelly.png?w=456?w=300" data-attachment-id="1312" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/badkelly.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/29/the-kelly-criterion-does-it-work/badkelly/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/badkelly.png?w=456?w=640" alt="badKelly" data-image-title="badKelly" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1312" data-recalc-dims="1"></p>
<p>The results are simply ridiculous. And here would be why: say you have a mean return of .0005 per day (5 bps/day), and a standard deviation equal to that (that is, a Sharpe ratio of 1). You would have 1/.0005 = 2000. In other words, a leverage of 2000 times. This clearly makes no sense.</p>
<p>The other variant is the more particular Investopedia definition.</p>
<pre>
invKelly &lt;- out * lag(investKelly(out), 2)
charts.PerformanceSummary(invKelly)
</pre>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/invkelly.png?w=456" data-orig-size="805,528" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/invkelly.png?w=456?w=300" data-attachment-id="1330" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/invkelly.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/29/the-kelly-criterion-does-it-work/invkelly/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/invkelly.png?w=456?w=640" alt="invKelly" data-image-title="invKelly" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1330" data-recalc-dims="1"></p>
<p>Looks a bit more reasonable. However, how does it stack up against not using it at all?</p>
<pre>
compare &lt;- na.omit(cbind(out, invKelly))
charts.PerformanceSummary(compare)
</pre>
<p><img data-orig-file="https://quantstrattrader.files.wordpress.com/2017/09/kellycompare.png?w=456" data-orig-size="813,534" data-medium-file="https://quantstrattrader.files.wordpress.com/2017/09/kellycompare.png?w=456?w=300" data-attachment-id="1334" data-image-meta="{" data-image-description="" src="https://quantstrattrader.files.wordpress.com/2017/09/kellycompare.png?w=456" data-permalink="https://quantstrattrader.wordpress.com/2017/09/29/the-kelly-criterion-does-it-work/kellycompare/#main" data-large-file="https://quantstrattrader.files.wordpress.com/2017/09/kellycompare.png?w=456?w=640" alt="kellyCompare" data-image-title="kellyCompare" sizes="(max-width: 640px) 100vw, 640px" data-comments-opened="1" class="wp-image-1334" data-recalc-dims="1"></p>
<p>Turns out, the fabled Kelly Criterion doesn’t really change things all that much.</p>
<p>For the record, here are the statistical comparisons:</p>
<pre>
                               Base     Kelly
Annualized Return         0.8021000 0.7859000
Annualized Std Dev        0.3553000 0.3588000
Annualized Sharpe (Rf=0%) 2.2574000 2.1903000
Worst Drawdown            0.2480087 0.2579846
Calmar Ratio              3.2341613 3.0463063
</pre>
<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/1283/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/quantstrattrader.wordpress.com/1283/"></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/29/the-kelly-criterion-does-it-work/"> 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/6WEOqbQIdB0" height="1"></a></div>