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/

    Margin account simulation

    General Discussion
    margin account leverage
    3
    7
    4520
    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.
    • A
      ab_trader last edited by ab_trader

      Hi! At this point I wasn't able to open position larger then amount of cash on the account. Usually broker allow to open at least 2x cash. I was trying to use cerebro.broker.set_checksubmit(False), but unsuccessful.

      Is there any way to simulate broker margin account i.e. ability to loan some money from 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 0
      • B
        backtrader administrators last edited by

        Margin (aka leverage) is not supported. This is a conscious design decision.

        There are ways to emulate it. For example:

        • A custom commission scheme which reduces the cost of asset acquisition

        Which means that more things can be bought with the same cash. See:

        • https://www.backtrader.com/docu/user-defined-commissions/commission-schemes-subclassing.html
        • https://www.backtrader.com/docu/extending-commissions/commission-schemes-extended.html
        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          Thank you! It is pity. I'll try to play with commissions.

          • 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
          • A
            ab_trader last edited by

            For the trading with the real broker (say IB), backtrader will not use leverage too? Or it is a limitation of the backtester only?

            • 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
              backtrader administrators last edited by

              The configuration (Margin or not) of the account used with Interactive Brokers is not controlled by backtrader.

              The backtester doesn't have a limitation. See what for example Interactive Broker offers you with the leverage with some assets:

              • Futures: no leverage - either you have the money in the account for the guarantee or you can't operate
              • Stocks: leverage - but market dependent
              • Forex: greatet leverate as with stocks

              From that simple view with just 3 different assets it should be clear that it is not the account what has the leverage but the assets (obviously there are accounts which doesn't offer leverage for any asset)

              And that's the reason for the design of the internal broker. Blindly offering leverage for any asset type would simply mean that someone would be testing for example futures with the illusion that leverage is available, or forex with the limitations of the leverage applied to stocks.

              As such, the proper way to do it is to make sure each asset gets the associated cash deduction level from the commission scheme applied to it.

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

                The latest release of backtrader, 1.9.20.105, has added leverage.

                Rather than having people subclassing CommissionInfo, it is fully integrated into that hierarchy and with the broker. See the latest BTFD blog post for a sample.

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

                  Deleted by author.

                  • 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
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors