I added Kelly Percent to analyzers
-
Hi guys,
As title states, I've created a pull request for the Kelly formula.
This will let us know the optimal percentage of account to bet for a strategy.Although I've been coding for 20 years, I'm relatively new to Python and never used GitHub before, so any suggestions for improvements are gratefully received.
Cheers guys
RichThe formula:
K = W - [(1 - W) / R] K = Kelly optimal percent e.g. 0.156 = 15.6 percent of account was optimal bet size (based on the historical trades your system generated). W = Win rate. e.g. 0.6 (= 60%) Determined by counting profitable trades made. R = Win/Loss ratio. e.g. 1.5 = Winners were on average 1.5 x losers Determined by taking average of all winners & average of all losers. Because R and W are determined from trades the strategy generates when run, there needs to be at least 1 winner and 1 loser. Otherwise 'None' is returned. Note: A negative Kelly percent e.g. -1.16 or -0.08, means the strategy lost money. The sign is important here. The actual value does not give any useful information as far as I can see.
-
And here is what it looks like in action.. :)
-
Great! This is something I have wanted to take a look at for a while. I hope your request is accepted.
-
@ThatBlokeDave Cheers mate. I have a couple of other more useful performance measures I'd like to add after. This is my first ever time I've worked with an open source project, so just figuring out how this pull request/GitHub things works..:)
-
By issuing it, as you did. It will be of course reviewed as soon as time allows it.
-
@backtrader Ok cool thanks. I was looking at the testing code, trying to figure it out. Does a test need to be written for it?
-
Not necessarily. Not much in the internals is bound to change.
-
@backtrader Hey backtrader, I found a rare bug in Kellys (since BT standard is to class trades >=0.0 as winners, if all winners are 0.0 profit, end up with a division by zero). I'm new to Github and wasn't too sure how to modify, so I cancelled my last pull request and made another fixing it. Cheers
-
Hi guys, if anyone wants to use this Kelly performance measure, you can get it here;
https://github.com/rich-oregan/backtraderDon't mean to teach you to suck eggs but some newbies here and want to make easy for everyone :)
There are two files.
"kelly. py" [main file]
"init.py" [contains just one small bit of code at the bottom;]
from .kelly import *
I've got a much better set of performance measures I've created. I just need to write some notes/comments for.. stay tuned.