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 avoid overbuying/overselling

    General Code/Help
    3
    6
    145
    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.
    • F
      ForexBeginner last edited by

      Hello everyone,

      I am a beginner to backtrader. It seems that when I use self.buy or self.sell, I expect the trader to not use more cash than initially set with broker.setcash(x). However, this does not seem to happen. How can I make sure that no more than the set cash is used?

      1 Reply Last reply Reply Quote 1
      • A
        ab_trader last edited by

        By default bt doesn't allow you to buy more than cash available. Short positions by default adds cash, but this can be turned off using shortcash parameter, check out Docs - Broker.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 1
        • F
          ForexBeginner last edited by

          Thank you for the quick reply!

          I am quite new to trading, does this mean that the broker.getvalue() value might overestimate the real value of the portfolio, because loaned money is added to the total value?

          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            No, this is what docs say -

            shortcash (default: True)

            If True then cash will be increased when a stocklike asset is shorted and the calculated value for the asset will be negative.

            If False then the cash will be deducted as operation cost and the calculated value will be positive to end up with the same amount

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 0
            • B
              blake last edited by

              @ab_trader just out of curiosity, why would anyone want shortcash=True? I can't seem to make sense of it.

              B 1 Reply Last reply Reply Quote 0
              • B
                blake @blake last edited by

                @blake nvm, i figured it out

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