<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joshua Greenwald on Medium]]></title>
        <description><![CDATA[Stories by Joshua Greenwald on Medium]]></description>
        <link>https://medium.com/@josh_lxdx?source=rss-cd47ef4269e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u0Rtmwue5Kj4pVeOY6ALEg.jpeg</url>
            <title>Stories by Joshua Greenwald on Medium</title>
            <link>https://medium.com/@josh_lxdx?source=rss-cd47ef4269e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:48:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@josh_lxdx/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Trade Sizing III of IV]]></title>
            <link>https://medium.com/lxdx/trade-sizing-iii-of-iv-706e342dda43?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/706e342dda43</guid>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[market]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Fri, 21 Sep 2018 21:22:14 GMT</pubDate>
            <atom:updated>2018-09-21T21:22:14.968Z</atom:updated>
            <content:encoded><![CDATA[<h4>Edge, control of risk, and generating outsized returns</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7Xg46KkQCvRi-VFhFucjQ.jpeg" /></figure><p>We’re going to extend the <a href="https://medium.com/lxdx/trade-sizing-ii-of-iv-a9ce33de5ae4">previous discussion</a> to situations where the outcomes of each wager (trade) follow a continuous distribution akin to financial market returns.</p><p>Instead of talking in the language of trades, bets, and outcomes, we’ll move to discussing the change in value of some asset. Even though we talk in terms of assets throughout, our discussion applies identically to the discussion of trading strategies or wagers.</p><p>Typically, we talk about the <em>distribution</em> of assets. We accept that there are many possible futures and our asset of choice may take a range of values. To help us understand and summarize the distribution of outcomes, we mostly talk about the expected return of an asset or strategy, and then secondarily the variance or standard deviation. These give us a primitive but concise way of talking about the <em>average</em> outcome and how frequently we end up with an outcome near that <em>average</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mv2Hh6LZvbYjROd5anHGA.jpeg" /><figcaption>The mean return is 0.26%, which, is well, positive expected value. But observe the left tail. Not all return distributions are normal!</figcaption></figure><p>In a world where the distribution of returns (or the distribution of log returns) is Gaussian (Normal), we only need talk about the mean and variance of our outcomes. Such an assumption, while clearly not fully <em>true</em>, is powerful as our two summary statistics of choice, mean and variance, fully describe the distribution.</p><p>This is great for a few reasons:</p><ul><li>We can communicate with each other effectively. If I tell you that a distribution is Normal and give you its mean and standard deviation, you know exactly which distribution I’m describing.</li><li>It’s simple. Gaussians are mathematically nice to work with. Very often in quantitative finance, we choose simple even if naive models.</li></ul><blockquote>Finally, we make some remarks on why linear systems are so important. The answer is simple: because we can solve them! — Richard Feynman</blockquote><p>That said, while the normality assumption isn’t crazy (because of the <a href="https://en.wikipedia.org/wiki/Central_limit_theorem">CLT</a>), one should take special care especially when trading derivatives which often show amplified sensitivity to the inadequacies of characterizing outcomes with a Gaussian. Skewness and kurtosis, the third and fourth moments of a distribution, may have significant impact.</p><p>We’re going to step through the math of Kelly as it pertains to continuous distributions; while most treatments jump straight to the normally-distributed world, we’ll take a bit of care to point out how things may change in a non-normal world.</p><p>Throughout our discussion we use C³ and C⁴ to refer to skewness and kurtosis — this denotes that they are the 3rd and 4th central moment about the mean. C¹ would be the distribution’s mean, with C² being its variance.</p><p>As a refresher, the skewness of a sample is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V3lmxA9grTYn3Hv2zwZKWQ.png" /><figcaption>For skewness, we take each sample, subtract the mean, divide by the standard deviation, and cube it.</figcaption></figure><p>Similarly, kurtosis of a sample is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2DWSHvmDnAoA5KK6bcwMyw.png" /><figcaption>As n-&gt;infinity, the bottom approximation is quite good</figcaption></figure><p>The following two plots demonstrate the effect of varying skewness and kurtosis levels on outcomes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s1j-lWQh92RX82xQ48KoPA.jpeg" /><figcaption>Observe that as skewness increases, the distribution ‘leans’ left. The distribution would lean right if skewness was negative.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qg8BP8UWwcPN3Gjv51Gbg.jpeg" /><figcaption>Increased kurtosis leads to increased “peakedness”</figcaption></figure><p>When evaluating the performance of an asset, and accordingly how much one should invest, it’s often worthwhile to look at these higher moments when considering the risk-reward of the opportunity.</p><p>Readers less interested in the math can skip the derivation; it’s a bit more explicit than is typical in the literature, but well, still, <em>math</em>.</p><h3><strong>Derivation</strong></h3><p>We’ll begin with a brief notation refresher:</p><ul><li>Lowercase <em>f</em> is the fraction invested</li><li><em>p</em> and <em>q</em> represent probability of win and probability of loss, respectively</li><li>Lowercase <em>g</em> is growth rate</li></ul><p>In our first entry on the series, we determined that in an even-odds binary game, the growth rate of our capital is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMkkTbxLWtOCZiMHhWGOYg.png" /></figure><p>Extending this to where the return for winning and losing is asymmetrical</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3k5DK1IT_aDTUdaq92T7gQ.png" /></figure><p>If we relabel our variables slightly, where we’re going gets more obvious</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPRny_lVJHu5IrEvO0gCMQ.png" /></figure><p>This can be expressed as a sum that lets us extend beyond the binary-only game</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suTeGRqAUTuZZC6yVSA82w.png" /></figure><p>Expressing as an expectation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgmnJwf-70yHOksyKa5QZg.png" /></figure><p>This should be intuitive; our growth rate is a function of the expected log gains combined with our fraction invested. To extend to the continuous case, we replace the sum in (4) with an integral</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-PQz2hn3RljQ0DX1D7GGQ.png" /><figcaption>One should be a bit careful with the above notation; the growth rate is not benchmarked to any reference rate. The <em>r</em> in the above is the excess return rate of our asset or strategy (the return minus LIBOR or Treasury rates).</figcaption></figure><p>We seek to maximize growth so once again we derive and set to zero</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7Wwyh2F2l2pHhdmFrqxIg.png" /><figcaption>Note we derive w.r.t <em>f</em></figcaption></figure><p>Here, p(r) describes the return distribution of our excess return rate. This is empirical in markets; we do not know the true distribution of an asset or a strategy — we estimate it from data.</p><p>The trick to the derivation (<a href="http://www.wolframalpha.com/input/?i=1+%2F+(1%2Brf)">thanks Wolfram Alpha</a>)¹ is in the Taylor expansion of the <em>1 + fr</em> term; we can approximate <em>1 / (1+fr)</em> with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7S16w6jIkUCBKRJ0G9uow.png" /></figure><p>We can expand the right hand side of (7)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frFXN_oWzA-9v4lweAuFRg.png" /></figure><p>If we assume that the returns <em>r </em>follow a normal distribution, we can substitute in the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1hBG5FxQhcQXrBBVoxdOQ.png" /><figcaption>Where C³ and C⁴ are the 3rd and 4th moments of our returns distribution</figcaption></figure><p>Afterwards, we’re left with</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UKiACAi3vdJsWAf0cCkV-A.png" /></figure><p>If we truncate after the first two Taylor terms and solve for the optimal Kelly fraction <em>f</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itvw44ZqxKV0RR_b4hgHRA.png" /><figcaption>This is the fraction invested that maximizes long term growth if we ignore skewness and kurtosis</figcaption></figure><p>We can expand out (6) up above with a Taylor approximation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_eXoZC8aXFx-I2mO0RK0xA.png" /></figure><p>Plugging <em>f</em> back in from (11), we can solve for the growth rate at <em>f </em>(dropping again here the 3rd and 4th moments)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5FJobUuVyn3v88gEer0Bw.png" /><figcaption>This growth is ONLY true ignoring skew and kurtosis effects!</figcaption></figure><h3><strong>Summing it up</strong></h3><p>The Kelly fraction we arrived at in (11) is often truncated to the approximation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B69zY_QTlsSKnnQPZv8Ong.png" /><figcaption>This is generally reasonable because the mean is expected to be &lt;&lt; the variance</figcaption></figure><p>This approximation is quite close in the reasonable case where the expected mean profit per trade is low</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*He2WvUYJ_M1juHCromU7CQ.jpeg" /></figure><p>Armed with this knowledge, we have a primitive way of allocating to opportunities where the outcomes take a continuous distribution.</p><p>What should jump out is that the optimal Kelly fraction (14) is very similar to Sharpe Ratio</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94xUyFJEq3Um7gCEQDKgDw.png" /><figcaption>We’re dropping the riskless rate, as we’ve been defining mu as the excess return</figcaption></figure><p>Sometimes, we even express the optimal Kelly fraction directly in terms of Sharpe</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qeKw39LJr4VbahKP-lWSwA.png" /><figcaption>If a trader comes to you with an opportunity to invest in an opportunity with a Sharpe ratio of 2.0 and a volatility of 50%, the optimal Kelly is 4. (You should lever up to go after the opportunity)</figcaption></figure><p>This is quite a useful rule of thumb for allocating to a strategy with a given Sharpe and volatility. Equally useful an approximation is expressing optimal growth as a function of Sharpe ratio</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IzqSAlCELzCQszUK_ie8wg.png" /><figcaption>Investing in a strategy with a Sharpe of 2 will double your money every year. (If bet at the Kelly fraction)</figcaption></figure><p>It may be a bit shocking that this final formula is expressed only using Sharpe; we know nothing about the risk and return of the asset, but nonetheless can estimate growth of the investment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*VrTjbMOLrEcmT07UmV8vAA.jpeg" /><figcaption>Assuming cost of capital to attain leverage is cheap (it is), this is why allocations to high frequency high Sharpe strategies are so attractive</figcaption></figure><h3>Conclusion</h3><p>We’ve worked through how to arrive at the Kelly fraction and growth solutions for application to financial markets. This is the tip of the iceberg both in applying Kelly to portfolio theory and understanding the nuances that come with practical allocation.</p><p>Central to trading via Kelly is the notion of trading with leverage. Many quantitative strategies, particularly those that trade with high frequency or in young markets like crypto, have high edge and corresponding high Sharpe. Investing without leverage in such opportunities is investing significantly below the optimal growth level and leaves a lot of money on the table.</p><p>One of the great challenges in bringing institutional and quantitative trading to crypto is inefficiencies in capital availability lead to not being able to put money where the big opportunities are. Derivatives, assets with embedded leverage, margin trading, better fiat on and off ramps will massively improve the economics for both buy and sell-side players.</p><p>Nobody is staying on the sideline because they see no opportunities; they just can’t put risk to work in an effective manner. We’ve seen in this series that edge is not enough to generate outsized returns; control of risk is of great importance and much of the work we’re doing here at LXDX is to facilitate its superior deployment.</p><p><strong>Notes</strong></p><ol><li>Seriously, Wolfram Alpha is amazing for the Taylor Series feature alone. Anyone want to build a lightweight math-as-a-service api?</li></ol><p><em>The last piece in this series is going to be a bit more technical dive into some of the practical challenges of using Kelly for trade sizing. Stay tuned.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=706e342dda43" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lxdx/trade-sizing-iii-of-iv-706e342dda43">Trade Sizing III of IV</a> was originally published in <a href="https://medium.com/lxdx">LXDX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kelly Fraction — f(higher moments)]]></title>
            <link>https://medium.com/@josh_lxdx/kelly-fraction-f-higher-moments-9eedb0adb22c?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eedb0adb22c</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Sun, 16 Sep 2018 18:54:47 GMT</pubDate>
            <atom:updated>2018-09-16T18:54:47.589Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve written a series of posts on the Kelly criterion as it pertains to trade sizing over at <a href="http://www.medium.com/lxdx">our blog</a>. In pursuit of brevity, in the derivations of Kelly as it pertains to continuous distributions, I left out the higher order moments and how to solve for the Kelly fraction when skew and kurtosis are in play.</p><p>For those interested in the full equation, however</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w892pLA4PEJn5drMzD5c9Q.png" /><figcaption>Where C3 and C4 are skew and kurtosis.</figcaption></figure><p>For those looking to use it via Python</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84885976255d8c9ef125ec128860678b/href">https://medium.com/media/84885976255d8c9ef125ec128860678b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eedb0adb22c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Volume to Egress Ratio]]></title>
            <link>https://medium.com/@josh_lxdx/volume-to-egress-ratio-cbafb215f6d2?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbafb215f6d2</guid>
            <category><![CDATA[crytocurrency]]></category>
            <category><![CDATA[exchange]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 20:46:03 GMT</pubDate>
            <atom:updated>2018-09-04T21:02:05.779Z</atom:updated>
            <content:encoded><![CDATA[<p>A thought, and not necessarily a <em>good</em> one, is that we can, to some degree, compare how much “trades” in a 24 hour window on an exchange with how much the exchange distributes to users via withdrawals.</p><p>This isn’t necessarily super stable. Different platforms have different usage patterns. I’ve looked at <strong>only</strong> ETH withdrawals <strong>only</strong> from the exchange addresses of which I know. Would love some help in adding to the list of known ETH wallet addresses that platforms are using to service withdrawals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3tUjsTv1cWXRm7qVmCn3w.jpeg" /><figcaption>Most platforms are surprisingly stable at about 10k to 1.</figcaption></figure><p>I grabbed all the transactions over the past few days, and compared yesterday’s volume data (via CMC) to the median ETH sent out of the known wallets over the past 3 days.</p><p>A few outliers:</p><p><strong>Gemini</strong>: Very low. ~1000 to 1. Perhaps a function of their user base. (And their <a href="https://gemini.com/trading-fee-schedule/#trading-fee-schedule">fees</a>)</p><p><strong>OKEx, HitBTC, CoinEx</strong>: <em>58,000 : 1 ; 83,000 : 1; 167,000 : 1</em>. That’s about 5, 8, and 17 times respectively Binance’s ratio of trading to withdrawals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*USaPT_-BMkVxh68Tp7T3VQ.jpeg" /></figure><p>I’ll put together the data and code shortly for those interested.</p><p>The address set I’m working off of:</p><pre>addresses = {<br>    &#39;BINANCE&#39;: [&#39;0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be&#39;, &#39;0xd551234ae421e3bcba99a0da6d736074f22192ff&#39;,<br>                &#39;0x564286362092d8e7936f0549571a803b203aaced&#39;, &#39;0x0681d8db095565fe8a346fa0277bffde9c0edbbf&#39;,<br>                &#39;0xfe9e8709d3215310075d67e3ed32a380ccf451c8&#39;],<br>    &#39;COINEX&#39;: [&#39;0xb9ee1e551f538a464e8f8c41e9904498505b49b0&#39;],<br>    &#39;BITFINEX&#39;: [&#39;0x1151314c646ce4e0efd76d1af4760ae66a9fe30f&#39;, &#39;0x7727e5113d1d161373623e5f49fd568b4f543a9e&#39;,<br>                &#39;0x4fdd5eb2fb260149a3903859043e962ab89d8ed4&#39;, &#39;0x876eabf441b2ee5b5b0554fd502a8e0600950cfa&#39;,<br>                &#39;0x742d35cc6634c0532925a3b844bc454e4438f44e&#39;],<br>    &#39;BITTREX&#39;: [&#39;0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98&#39;, &#39;0xe94b04a0fed112f3664e45adb2b8915693dd5ff3&#39;],<br>    &#39;COBINHOOD&#39;: [&#39;0x8958618332df62af93053cb9c535e26462c959b0&#39;],<br>    &#39;CHANGELLY&#39;: [&#39;0x96fc4553a00c117c5b0bed950dd625d1c16dc894&#39;],<br>    &#39;CRYPTOPIA&#39;: [&#39;0x5baeac0a0417a05733884852aa068b706967e790&#39;],<br>    &#39;GATEIO&#39;: [&#39;0x0d0707963952f2fba59dd06f2b425ace40b492fe&#39;, &#39;0x7793cd85c11a924478d358d49b05b37e91b5810f&#39;,<br>              &#39;0x1c4b70a3968436b9a0a9cf5205c787eb81bb558c&#39;],<br>    &#39;GEMINI&#39;: [&#39;0xd24400ae8bfebb18ca49be86258a3c749cf46853&#39;, &#39;0x6fc82a5fe25a5cdb58bc74600a40a69c065263f8&#39;],<br>    &#39;HITBTC&#39;: [&#39;0x9c67e141c0472115aa1b98bd0088418be68fd249&#39;, &#39;0x59a5208b32e627891c389ebafc644145224006e8&#39;],<br>    &#39;HUOBI&#39;: [&#39;0xab5c66752a9e8167967685f1450532fb96d5d24f&#39;, &#39;0x6748f50f686bfbca6fe8ad62b22228b87f31ff2b&#39;,<br>             &#39;0xfdb16996831753d5331ff813c29a93c76834a0ad&#39;, &#39;0xeee28d484628d41a82d01e21d12e2e78d69920da&#39;,<br>             &#39;0x5c985e89dde482efe97ea9f1950ad149eb73829b&#39;, &#39;0xdc76cd25977e0a5ae17155770273ad58648900d3&#39;,<br>             &#39;0xadb2b42f6bd96f5c65920b9ac88619dce4166f94&#39;, &#39;0xa8660c8ffd6d578f657b72c0c811284aef0b735e&#39;,<br>             &#39;0x1062a747393198f70f71ec65a582423dba7e5ab3&#39;, &#39;0xe93381fb4c4f14bda253907b18fad305d799241a&#39;,<br>             &#39;0xfa4b5be3f2f84f56703c42eb22142744e95a2c58&#39;, &#39;0x46705dfff24256421a05d056c29e81bdc09723b8&#39;,<br>             &#39;0x99fe5d6383289cdd56e54fc0baf7f67c957a8888&#39;],<br>    &#39;KRAKEN&#39;: [&#39;0x2910543af39aba0cd09dbb2d50200b3e800a63d2&#39;, &#39;0x0a869d79a7052c7f1b55a8ebabbea3420f0d1e13&#39;,<br>              &#39;0xe853c56864a2ebe4576a807d26fdc4a0ada51919&#39;, &#39;0x267be1c1d684f78cb4f6a176c4911b741e4ffdc0&#39;,<br>              &#39;0xfa52274dd61e1643d2205169732f29114bc240b3&#39;],<br>    &#39;KUCOIN&#39;: [&#39;0x2b5634c42055806a59e9107ed44d43c426e58258&#39;],<br>    &#39;OKEX&#39;: [&#39;0x6cc5f688a315f3dc28a7781717a9a798a59fda7b&#39;],<br>    &#39;POLONIEX&#39;: [&#39;0x32be343b94f860124dc4fee278fdcbd38c102d88&#39;, &#39;0xab11204cfeaccffa63c2d23aef2ea9accdb0a0d5&#39;,<br>                &#39;0x209c4784ab1e8183cf58ca33cb740efbf3fc18ef&#39;, &#39;0xb794f5ea0ba39494ce839613fffba74279579268&#39;],<br>    &#39;SHAPESHIFT&#39;: [&#39;0x70faa28a6b8d6829a4b1e649d26ec9a2a39ba413&#39;],<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbafb215f6d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trade Sizing II of IV]]></title>
            <link>https://medium.com/lxdx/trade-sizing-ii-of-iv-a9ce33de5ae4?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9ce33de5ae4</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[market]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 20:27:32 GMT</pubDate>
            <atom:updated>2018-09-07T15:09:43.840Z</atom:updated>
            <content:encoded><![CDATA[<h4>Shall we play a game? M<strong>aximizing for log wealth</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9g2zNK5vtjpFrKyrIBq0g.jpeg" /></figure><blockquote>Your rich uncle has 10 times as much money as you. He proposes a game. He’ll flip a coin; if the coin comes up heads, you receive 1/3 of what was wagered. If the coin lands tails, he takes 3/10 of what was bet. He chooses your bet size per play. The coin is fair. The game ends when either player drops below a 1$. Should you play? How much do you stand to win?</blockquote><p>The game, per iteration, is clearly positive expected value. You’ve got a 50% chance to win 1/3 of a bet and a 50% chance to lose only 3/10 of that bet. The expected return of each bet is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0rUudH2HFfXhJG633fdWQ.png" /></figure><p>Each bet is for edge! The game can be expressed in the same Kelly framework from the <a href="https://medium.com/lxdx/trade-sizing-fb546bc3b1aa">first part </a>of this series. We can express the long term capital value of the game as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aU7B47y8qoq_8mPgK7J9zg.png" /><figcaption>Where p/q are odds of win/loss and w/l are payoff for win/loss. f is once again fraction invested. N is number of plays. W0 is initial wealth.</figcaption></figure><p>Our uncle, since he chooses our bet size, will opt to make sure the fraction we invest is maximally suboptimal. If we assume that our uncle will force us to bet our whole fraction each play, such that <em>f</em> = 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGPanGuvLnwboQNdXH3chQ.png" /><figcaption>Plugging in our numbers.</figcaption></figure><p>We notice that, when we simplify,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*17IvcGgayxFcSJMJAtcSwg.png" /></figure><p>Even though our game has theoretically positive expected return per play, our expected wealth decays playing it by over 3% per step!</p><p>Monte Carlo simulation of our game verifies that the game does, in fact, not go well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELugu_nKXSUgIzHFqdPrNQ.jpeg" /><figcaption>Note that the 95th percentile is <strong>well</strong> below the mean performance. We start at $1000 in these simulations.</figcaption></figure><p>In a game where our expected value is positive</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp974MKOagSgxMcYdvPNtA.png" /></figure><p>Our optimal Kelly fraction is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBvFjYkxG27whLx1TqASsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pa57jO-giA4ILuA-KNWQpw.png" /></figure><p>Plugging it all in, we arrive at a Kelly fraction of 1/6. As previously discussed, playing at any fraction above twice our Kelly fraction will drive growth negative. If our uncle was generous, and allowed us to wager at the optimal Kelly instead, observe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-VWOdu7g_ZdnlY2PlarjA.jpeg" /><figcaption>Playing instead at Kelly (1/6th) will instead generate a 4x return (on average).</figcaption></figure><p>Whereas even at <em>f</em>=1/2, the game degenerates quickly into negative long term expected value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ze7Tt5LXR4rGu-Hfo_GaKg.jpeg" /><figcaption>Mean loss ~ 50%, median loss 99.5%!</figcaption></figure><p>We must be very cautious of our intuition when it comes to the applicable statistics for these sorts of problems. While the game, at first glance, seems like a no-brainer given the positive edge, the total wealth of our portfolio follows a geometric and not an arithmetic process. That is to say, our wealth is multiplicative of its current level.</p><p>Any process that either increases by 33% per step or decreases by 30% with equal probability, given time, decays to zero. In trading, if you lose 20% on a trade, you have to make 25% to get back to your original level (high water mark effect).</p><p>A bet, trade, asset, opportunity with positive expected value, which in our simplified framework, is simply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nZ6G9UMLxo6mmS8CT8oDQ.png" /></figure><p>Any such opportunity has some fraction <em>f</em> (Kelly) that, if invested, yields positive long-term growth. Investing at larger fractions, even when the opportunity is positive edge, does <strong>not</strong> guarantee growth.</p><h3><strong>Log utility</strong></h3><p>Discussions of Kelly often, quite reasonably, ask:</p><blockquote>Is maximizing long term exponential growth rate optimal? Why? Doesn’t this imply an arbitrary fondness for log utility of wealth?</blockquote><p>While we avoided the explicit implication of taking the log of our wealth in our initial derivations, it is implicit in our assumption of maximizing growth rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zYvt2lM9FOgQOF77R-N__g.png" /></figure><p>Maximizing the log of the final wealth is implicit in maximizing growth rate. We’re still in the log-wealth world.</p><p>Direct maximization of terminal wealth is problematic reminiscent of the <a href="https://en.wikipedia.org/wiki/St._Petersburg_paradox">St Petersburg Paradox</a>. Rare outliers comprise the bulk of net expected value.</p><p>Consider the following pseudocode for a similar game but against an opponent of infinite wealth (a reasonable proxy for the market)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdf6276d689b6828fa80ded849c5f267/href">https://medium.com/media/bdf6276d689b6828fa80ded849c5f267/href</a></iframe><p>When we compare the median and mean of our terminal wealth at varying investment fractions, we see that as the fraction increases so does the spread between mean and median performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMWFlhZ_6QGMtE8KFr8DtA.jpeg" /></figure><p>When we simulate and look at the individual paths, the root cause is more clear. A few outliers drive the mean significantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zZVgZSek-9PY5ZtyKuKhA.jpeg" /><figcaption>Comparison of wealth: mean and the mean less the greatest value.</figcaption></figure><p>Unless you happen to be living in one of the luckier possible worlds, optimizing directly for wealth ends poorly.</p><p>Another common way to think about wealth maximization is minimizing the time to reach some goal (which we’ll call G). Kelly, as it maximizes growth rate, intuitively minimizes the time to reach said goal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06_IwtWG_7A0VSSX31Ii3A.jpeg" /></figure><p><strong>Benefits of maximizing for log wealth (instead of wealth):</strong></p><ol><li>As noted, maximizing for log wealth equivalently maximizes for long term growth.¹</li><li>The expected time to reach a goal G is minimized (without limit on how high G is) by maximizing for log wealth.²</li><li>The log wealth investor never faces ruin (as he only bets a fraction)</li><li>The amount wagered is monotone increasing with wealth.</li><li>The Kelly investor maximizes median wealth by maximizing log wealth.³</li></ol><h3><strong>Conclusion</strong></h3><p>Thinking about games of this nature provides valuable insight into risk management. Our intuitions are not necessarily robust and we’ve got to be very cautious describing outcomes via only their mean (“average”) result. Trade sizing is inseparable from modeling the distribution of trade outcomes. While log wealth utility is not a necessary truth, it has many nice properties for valuing possible futures.</p><p><strong>References</strong></p><ol><li>Algoet, P. H. and T. Cover (1988). Asymptotic optimality and asymptotic equipartition properties of log-optimum investment. <em>Annals of Probability</em></li><li>Breiman, L. (1961). Optimal gambling system for favorable games. <em>Proceedings of the 4th Berkeley Symposium on Mathematical Statistics and Probability 1</em>.</li><li>Ethier, S. (2004). The Kelly system maximizes median fortune. <em>Journal of Applied Probability 41</em>.</li></ol><h4>About LXDX</h4><p>LXDX is a cryptocurrency exchange platform that achieves the best prices by empowering <em>all</em> traders with the powerful technology previously accessible only by elite institutions. <a href="https://t.me/LXDXchat">Join the conversation on Telegram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9ce33de5ae4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lxdx/trade-sizing-ii-of-iv-a9ce33de5ae4">Trade Sizing II of IV</a> was originally published in <a href="https://medium.com/lxdx">LXDX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trade Sizing]]></title>
            <link>https://medium.com/lxdx/trade-sizing-fb546bc3b1aa?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb546bc3b1aa</guid>
            <category><![CDATA[market]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[finance]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 16:24:02 GMT</pubDate>
            <atom:updated>2018-09-07T15:10:17.843Z</atom:updated>
            <content:encoded><![CDATA[<h3>Trade Sizing I of IV</h3><h4>Kelly sizing and maximizing long-term capital growth</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0tHEbvEUU-M9SSko7NQEA.jpeg" /></figure><blockquote>“What would you do if you were invited to play a game where you were given $25 and allowed to place bets for 30 minutes on a coin that you were told was biased to come up heads 60% of the time?”</blockquote><h3><strong>Edge is not enough</strong></h3><p>Investing and strategic games of chance have much in common. Both require using statistics to model outcomes and act accordingly, and, both require intelligent bet sizing.</p><p>It’s not a coincidence that trading firms are full of poker players — the overlap is substantial. In gambling, because the odds are known and fixed, choosing not only when to bet, but also, how much, is critical. Trading strategies, particularly quantitative strategies, are equally sensitive to sizing decisions. Your fancy, temporal, convolutional, recursive, ninety-factor algorithm may achieve high win ratios (high accuracy), however if you ignore sizing, you may very likely still lose money.</p><p>Imagine that you have engineered a predictive model for an algorithmic trading strategy with a win rate of 60%. The strategy trades 1000 times a day. After each winning trade, you increase the bet size to 20% of your current bankroll. What are the odds of finishing the year bankrupt?</p><p>The answer, despite the high amount of edge (+10%) and reasonably small bet sizing, is that the strategy almost always goes bankrupt. Zero in ten thousand simulations end without bankruptcy.</p><p>This (and, confusingly, other similar phenomena) is <a href="https://en.wikipedia.org/wiki/Gambler%27s_ruin">Gambler’s Ruin</a>.</p><blockquote>“A gambler who raises his bet to a fixed fraction of bankroll when he wins, but does not reduce it when he loses, will eventually and inevitably go broke, even if he has a positive expected value on each bet.”</blockquote><p>Even if the odds of losing are low, eventually a string of losses will wipe you out if you don’t scale your wagers off of your bankroll (capital).</p><h3><strong>The Kelly Criterion</strong></h3><p>The discussion to follow, as it pertains to the Kelly Criterion, will use language most familiar to gambling. A decision to deploy capital follows identical logic whether we call it an investment, a bet, or a wager.</p><p>Derived over six decades ago, the Kelly Criterion solves the challenge of how a gambler with edge should act to maximize bankroll growth.</p><h4><strong>Notation</strong></h4><ul><li><em>p</em> and <em>q</em> represent probability of win and probability of loss, respectively</li><li>Lowercase <em>w</em> and <em>l</em> represent reward for winning a bet and penalty for losing a bet, respectively</li><li>Lowercase <em>b</em> is <em>net odds</em> or <em>w</em>/<em>l</em></li><li>Capital <em>W</em> is your total wealth (bankroll)</li><li>Lowercase <em>m</em> and <em>t</em> represent number of wins and total number of plays, respectively</li></ul><p>Kelly proved that the optimal wager in a repeated game</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29DBXZVRHojpOktBr5GZWg.png" /></figure><p>In literature, this often takes one of the following forms where <em>b</em> is substituted for <em>w</em>/l and/or <em>q</em> is swapped for <em>1 — p</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjbJU3OW5cBdJOLkROcTfw.png" /></figure><p>A simple numerical example where the game is a coin toss but the reward for winning is doubled</p><p><strong>0.5 - 0.5/(2/1) = 0.5 - 0.25 = 0.25</strong></p><p>Flipping a fair coin where your reward for winning is double what you lose for losing is obviously an attractive game to play; by Kelly, betting 25% of your bankroll per play will maximize the long-term expected value of said game.</p><p>Using the Kelly Criterion, we can calculate the ideal wager given any combination of net odds (win to loss ratio) and probability of winning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*GTQBwTAqDlG_u8OLzLMaXA.jpeg" /></figure><p>The Kelly ratio need not be positive. In unfavorable games, Kelly advises us to <em>pay to not play the game</em>. The negative Kelly value represents how much we should pay to avoid the wager (assuming we can’t just say no).</p><p>The Kelly Criterion provides some nice assurances. One, as we only bet a fraction of our total capital per round, we can never go bankrupt (and thus keep playing the game that is, presumably, for edge). The strategy is guaranteed to outperform any other strategy given the Kelly assumptions of known and fixed probabilities as well as infinite number of plays.</p><h4><strong>Derivation</strong></h4><p>The derivation is quite straightforward. We’ll simplify our problem to a game with binary outcomes (win or lose) with even-odds (the reward for winning is the same as the penalty for losing).</p><p>In our game, we wager fraction <em>f</em> of our wealth at each step. After <em>t</em> steps, with <em>m</em> wins, starting with initial wealth <em>W0</em> our terminal wealth <em>Wt</em> is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ut2CtRQms-FMbX235Z8Wjw.png" /></figure><p>The exponential growth rate, <em>r</em>, of asset is defined as the rate that satisfies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3W0rsfQKiUUQHv63zgxuQ.png" /></figure><p>Plugging it back into our previous equation, we can express the growth rate <em>g</em> for our binary game</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7oZWda6P72fL1wZiCQDLrA.png" /></figure><p>We can substitute <em>p</em> for <em>m</em>/<em>t</em> and <em>q</em> for (<em>t </em>— <em>m)</em>/<em>t</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*giOES8XGUCI751syLq5CEg.png" /></figure><p>To maximize the growth rate <em>g</em>, we derive and set to zero</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3Ny4LhCkFP88ZYm1mhQZQ.png" /></figure><p>Optimal growth rate is maximized by betting <em>f</em> = <em>p - q</em> (the Kelly ratio) at each step.</p><p>Assuming we play at the Kelly fraction, we can plug the Kelly Criterion back into (7) to solve for the long-term capital growth rate of a game</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*678Vkv8vik_nXzqtQuCBdw.png" /></figure><p>A similar derivation for games of uneven odds can be performed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0V-MM0R4R-969osbvMc8ag.png" /></figure><h3><strong>Betting other amounts</strong></h3><p>How suboptimal is betting other fractions of wealth? Generally, overbetting is significantly worse than underbetting the Kelly ratio. What’s perhaps most counterintuitive is that significantly overbetting the Kelly ratio will drive our growth rate negative.</p><p>Below we plot curves with varying winning probabilities and varying W/L ratios</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*PGI0cx2eQg3BuTZ6p9_TSQ.jpeg" /></figure><p>Overbetting drives our growth rate negative — <strong>even in games with positive expected value</strong>.</p><p>Generally, in games of even-odds, betting at twice the Kelly ratio drives the long-term growth negative.</p><h3><strong>The original question</strong></h3><blockquote>“What would you do if you were invited to play a game where you were given $25 and allowed to place bets for 30 minutes on a coin that you were told was biased to come up heads 60% of the time?”</blockquote><p>Armed with Kelly, we can posit a guess for the opening question. We should bet <em>p - q</em> or 20% of our bankroll per round. While this isn’t truly optimal, given that we’re violating one of the key Kelly assumptions (the game cannot be played ad infinitum), it isn’t a bad place to start.</p><p>See the code snippet at the end of this section for a simulator of the game.</p><p>The game, as discussed in “<a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2856963">Rational Decision-Making Under Uncertainty: Observed Betting Patterns on a Biased Coin</a>”, by Haghani &amp; Dewey 2016, also contains a hidden winnings cap at $250. In our analysis, our player bets nothing once he hits the cap. Generally, it’s ill-advised to bet money when you cannot win.</p><p>Playing the game using the Kelly strategy yields a ~$237 payoff. In the paper, which is a <strong>must</strong> read, the authors recruited 61 participants, 14 of which were finance professionals from leading asset management firms. The average payout of the humans: <strong>only $91</strong>. The human players, who, given their backgrounds, should be quite familiar with the Kelly Criterion, underperformed simple Kelly betting by &gt;60%.</p><p>The problem, despite being a trivial game (and thus a very simplified proxy for strategic investing), reveals how badly intuition fares when determining optimal risk allocations. Kelly is clearly suboptimal here; the paper details this underperformance extensively, and if anything, is overly generous with respect to human performance on this game. Other algorithms perform stronger, achieving scores much closer to the $250 winnings cap.</p><pre>from numba import jit</pre><pre>import numpy as np</pre><pre>@jit</pre><pre>def game(F):</pre><pre>    flips = np.random.binomial(1, .6 , 300)</pre><pre>    wealth = 25</pre><pre>    for flip in flips:</pre><pre>        bet = F * wealth if wealth &lt; 249.99 else 0</pre><pre>        wealth += bet if flip == 1 else -bet</pre><pre>        wealth = min(wealth, 250)</pre><pre>        if wealth &lt; 0.01:</pre><pre>            return wealth</pre><pre>    return wealth</pre><pre>def sim_game(F, N=1e5):</pre><pre>    return np.mean([game(F) for x in range(int(N))])</pre><pre>sim_game(.2)</pre><pre>#237.41</pre><h3>Conclusion</h3><p>Obviously, making good trades is critical. However, to maximize long-term capital growth, sizing these trades is both surprisingly important and, empirically, challenging. Kelly sizing is no panacea but does provide a reasonable framework to operate within. Armed with a solid understand of Kelly, as it pertains to simple games, the logic can be extended to markets where the outcomes are continuous distributions.</p><h4>About LXDX</h4><p>LXDX is a cryptocurrency exchange platform that achieves the best prices by empowering <em>all</em> traders with the powerful technology previously accessible only by elite institutions. <a href="https://t.me/LXDXchat">Join the conversation on Telegram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb546bc3b1aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lxdx/trade-sizing-fb546bc3b1aa">Trade Sizing</a> was originally published in <a href="https://medium.com/lxdx">LXDX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Converting Math for Medium]]></title>
            <link>https://medium.com/@josh_lxdx/converting-math-for-medium-2e04abfdd3bf?source=rss-cd47ef4269e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e04abfdd3bf</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Joshua Greenwald]]></dc:creator>
            <pubDate>Fri, 24 Aug 2018 19:41:08 GMT</pubDate>
            <atom:updated>2018-08-24T19:41:08.251Z</atom:updated>
            <content:encoded><![CDATA[<p>Medium doesn’t play nicely with LaTeX; there’s a great <a href="https://medium.com/@dtinth/typesetting-math-in-medium-e4b39755842f">post</a> by <a href="https://medium.com/u/1af7baa03775">Thai Pangsakulyanont</a> that details his work in generating PNG files that display nicely here.</p><p>As a simple Python Script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/954c84d976267304525fdc63d0f79086/href">https://medium.com/media/954c84d976267304525fdc63d0f79086/href</a></iframe><p>The expectation is that you’d run this primarily for single line expressions</p><pre>python convert_equation.py &quot;&amp;g = p \log(1+f) + q \log(1-f)&quot; kceq.png</pre><p>That said, if you’ve got a file “equations.tex”</p><pre>&amp;g = p \log(1+f) + q \log(1-f)<br>\\ &amp;g = p \log(1 + p - q) + q \log(1 - p + q)<br>\\ &amp;g = p \log (p + q + p - q) + q \log (p + q - p + q)<br>\\ &amp;g = p \log 2p + q log 2q<br>\\ &amp;g = (p \log p )(p \log 2) + (q \log q) (q \log 2)<br>\\ &amp;g = (p + q) \log 2 + p \log p  + q \log q<br>\\ &amp;g = \log 2 + p \log p  + q \log q \tag{9}</pre><p>Standard bash expansions may do the trick</p><pre>python convert_equation.py &quot;$(&lt; equations.tex)&quot; eqs.png</pre><p>This is obviously very hack-ish; improvements are appreciated and will get heavy use!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e04abfdd3bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>