Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    I added Kelly Percent to analyzers

    Indicators/Strategies/Analyzers
    3
    9
    3350
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Richard O'Regan
      Richard O'Regan last edited by

      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
      Rich

      The 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.
      

      You can take the man out of the army, but you can't take the army out of the man.

      1 Reply Last reply Reply Quote 2
      • Richard O'Regan
        Richard O'Regan last edited by

        And here is what it looks like in action.. :)

        0_1505412222718_Untitled.png

        You can take the man out of the army, but you can't take the army out of the man.

        1 Reply Last reply Reply Quote 1
        • T
          ThatBlokeDave last edited by

          Great! This is something I have wanted to take a look at for a while. I hope your request is accepted.

          Richard O'Regan 1 Reply Last reply Reply Quote 0
          • Richard O'Regan
            Richard O'Regan @ThatBlokeDave last edited by Richard O'Regan

            @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..:)

            You can take the man out of the army, but you can't take the army out of the man.

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              By issuing it, as you did. It will be of course reviewed as soon as time allows it.

              Richard O'Regan 1 Reply Last reply Reply Quote 0
              • Richard O'Regan
                Richard O'Regan @backtrader last edited by

                @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?

                You can take the man out of the army, but you can't take the army out of the man.

                1 Reply Last reply Reply Quote 0
                • B
                  backtrader administrators last edited by

                  Not necessarily. Not much in the internals is bound to change.

                  Richard O'Regan 1 Reply Last reply Reply Quote 0
                  • Richard O'Regan
                    Richard O'Regan @backtrader last edited by

                    @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

                    You can take the man out of the army, but you can't take the army out of the man.

                    1 Reply Last reply Reply Quote 0
                    • Richard O'Regan
                      Richard O'Regan last edited by Richard O'Regan

                      Hi guys, if anyone wants to use this Kelly performance measure, you can get it here;
                      https://github.com/rich-oregan/backtrader

                      Don'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 *

                      0_1508369029498_Untitled.png

                      I've got a much better set of performance measures I've created. I just need to write some notes/comments for.. stay tuned.

                      You can take the man out of the army, but you can't take the army out of the man.

                      1 Reply Last reply Reply Quote 3
                      • 1 / 1
                      • First post
                        Last post
                      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors