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/

    Percentage Margin for Futures

    General Code/Help
    3
    6
    2234
    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.
    • P
      Praveen Baratam last edited by

      In the futures I am interested in both Margin and Commission including taxes are a percentage of the turnover than fixed.

      I am currently trying to achieve this in Backtrader as following but orders are failing with order.executed.status=7 (Margin)

      # set commission scheme
      cerebro.broker.setcommission(
      commtype=bt.CommInfoBase.COMM_PERC,
      percabs=True,
      commission=0.0001,
      automargin=0.09,
      )
      

      Please help.

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

        That's unfortunately not enough information. If you fail with Margin it's because you don't have money enough.

        1 Reply Last reply Reply Quote 0
        • P
          Praveen Baratam last edited by

          Thank you @backtrader

          I found the issue. I am trying to go all in and calculating the order size based on previous close which may be lower than todays open and the margin money will not be enough then...

          For now I am only going 95% in to avoid margin call if the price gaps up.

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

            For those absolutely non-realistic scenarios you can use cheat-on-open. See

            • Docs - Cheat On Open
            1 Reply Last reply Reply Quote 0
            • P
              Praveen Baratam last edited by

              Thank you for the Suggestion. It helped.

              By the way, how do we get the PnL of an active existing position/trade on each bar (inside next method)?

              1 Reply Last reply Reply Quote 0
              • Y
                Yelloww last edited by

                broker.get_value() gives fund value. broker.get_cash() gives currently available cash.

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