Navigation

    Backtrader Community

    • Register
    • 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/

    HOW to Look for Documentation / Features?

    General Code/Help
    3
    9
    1464
    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.
    • NewestTrader
      NewestTrader last edited by

      Hi,

      while looking at the features of Backtrader, I frequently come to the point where I am little bit helpless:

      E.g.:

      I take one of the examples:

      quickstart11.py (aka: "Let’s Optimize")

      and try to extend it a little bit:

      Instead of:

                  self.order = self.buy()
      

      in

             def next(self):
      

      I write:

                  myCash = cerebro.broker.get_cash()
                  mySize = myCash/(self.dataclose[0] * 0.1)
                  self.order = self.buy(size=mySize)
      

      and nothing happens :-(

      I thought I could set the amount of stock to buy just relatively to the amount of money I have.

      My asumption was - as it seems to be possible in strategy.py:

      def buy(self, data=None,
              size=None, price=None, plimit=None,
              exectype=None, valid=None, tradeid=0, oco=None,
              trailamount=None, trailpercent=None,
              parent=None, transmit=True,
              **kwargs):
      

      that I can supply attributes like the amount of stocks (size) in this way.

      How should I look for examples, docu (or something else) to find a solution for this by myself (I realized that the online documentation is in the docu2 folder within the *.rst files, so I can look here for docu, ok - but without success in this case)? Or is there any debug/log mode available that I could activate?

      And if somebody knows a quick answer for my issue, that would be nice, too :-)

      P 2 Replies Last reply Reply Quote 0
      • A
        ab_trader last edited by

        @NewestTrader said in HOW to Look for Documentation / Features?:

        mySize = myCash/(self.dataclose[0] * 0.1)

        Maybe you wanted to make like this:

        mySize = 0.1 * myCash // self.dataclose[0]
        
        1 Reply Last reply Reply Quote 0
        • P
          Paska Houso @NewestTrader last edited by Paska Houso

          @NewestTrader said in HOW to Look for Documentation / Features?:

          How should I look for examples, docu (or something else) to find a solution for this by myself (I realized that the online documentation is in the docu2 folder within the *.rst

          Why would you look in the reSructuredText (aka .rst) files if you can read it online and directly google? (Plus the generated online documentation has a built-in search facility)

          @NewestTrader said in HOW to Look for Documentation / Features?:

          that I can supply attributes like the amount of stocks (size) in this way.

          You cannot do it in the bank/broker. When you go to the market you express yourself in $$ and that low-level operation does the same. If size had different meanings or entry points it would lead to trouble.

          In any case and even if you can do it like @ab_trader indicated you are probably looking for this:

          • https://www.backtrader.com/docu/order_target/order_target.html

          Where you can use the family of orders to specify target size, target value or target percentage.

          The other option being a Sizer which does the calculation for you

          • https://www.backtrader.com/docu/sizers/sizers.html
          1 Reply Last reply Reply Quote 1
          • A
            ab_trader last edited by

            Addition to @Paska-Houso post - target orders set percent based on portfolio value (cash + open positions). If you want to use cash only, then your code is better. The other thing that need to be corrected is

            myCash = self.broker.get_cash()
            
            1 Reply Last reply Reply Quote 2
            • P
              Paska Houso last edited by

              @ab_trader said in HOW to Look for Documentation / Features?:

              target orders set

              target_order_size works with target sizes ... or am I missing something?

              A 1 Reply Last reply Reply Quote 1
              • A
                ab_trader @Paska Houso last edited by

                @Paska-Houso in his case the target_order_value can be a better option in this case. I forgot about this type if order.

                target_order_size as I remember operates with stock quantities, not percents of cash or portfolio.

                1 Reply Last reply Reply Quote 0
                • P
                  Paska Houso @NewestTrader last edited by

                  @NewestTrader said in HOW to Look for Documentation / Features?:

                  that I can supply attributes like the amount of stocks (size) in this way.

                  The original poster said ...

                  @ab_trader said in HOW to Look for Documentation / Features?:

                  target_order_size as I remember operates with stock quantities

                  And that was my idea, that he looked into target_order_size. I believe we have probably misunderstood each other.

                  A 1 Reply Last reply Reply Quote 1
                  • A
                    ab_trader @Paska Houso last edited by

                    @Paska-Houso got your point. I was considering the 0.1 * My cash as the goal rather then setting of size. ;) Anyway target orders really convenient feature of the bt.

                    1 Reply Last reply Reply Quote 1
                    • NewestTrader
                      NewestTrader last edited by

                      Thanks for your replies guys!

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
                      $(document).ready(function () { app.coldLoad(); }); }