Back to Community
Kelly Criterion Sizing

Has anyone successfully implemented the kelly criterion? I've been stuck on trying to implement this as a function that returns the risk/kelly% but I haven't had any luck. I've seen a few posts on this and the only functional example was one that takes in a universe and sorts them by the kelly %. I haven't seen a function call for one strategy and/or weigh it against your portfolio. Please help.

8 responses

Last time I looked into this (over 18 months ago), it looked pretty tedious to calculate since, at the time, one had to keep track of all the per-trade statistics oneself. That might have changed, perhaps Quantopian exposes more information about your strategy performance back into the algo? Max Dama's PDF had some excellent code (probably in Python even?) for calculating the "kelly criterion" using the empirical returns distribution of the strategy, rather than assuming normality. It's on here somewhere.

That's what I was afraid of and it also is where I was running into issues. Do you know of other types of dynamic sizing strategies that could be easily implemented on this platform?

I am not sure, sorry. In theory one should be able to write a module that did everything correctly. Perhaps one could appeal to the zipline contributors?

Bryant, have you seen David's algorithm of the Kelly formula here? https://www.quantopian.com/posts/dynamic-portfolio-selection-with-the-kelly-formula

Is that something along the lines of what you're looking for?

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Alisa, what I believe he is looking for is being able to size the next trade based on the kelly criterion of the strategy itself over the last N trades. This requires keeping track of running statistics of the outcomes of previous trades of the strategy itself, and having access to those statistics from within the algorithm. From memory, one would need to know the % winning trades (of the last N), and the average win size, average loss size, and/or average trade profit/capital or some combination like that.

Alisa, I tried implementing this but Simon is right, since I couldn't count the last N trades I wasn't able to get the formula to work correctly. I couldn't find another example of this implemented anywhere. I'd like to implement Kelly sizing but if that isn't possible for what I'm doing is there other examples of dynamic sizing strategies? I've looked and haven't come up with many code examples on quantopian.

This is a tougher one, but it is doable. It's gonna require a method of tracking returns per strategy. The easiest way might be to use track the returns on each position and associate those returns with a particular strategy.

This is a simplistic attempt at tracking per position returns, it just uses the log return from open to close each day. It's a start, next you would have to aggregate the position returns into strategy buckets, and calculate the Kelly score of each bucket.

Clone Algorithm
61
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 54614528d9305a34ca14fbcb
There was a runtime error.

Any update on this?