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/

    perpetual futures equivalent on backtrader

    General Code/Help
    futures leverage commission binance
    4
    7
    733
    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.
    • S
      stonks last edited by

      Hello everyone,

      First of all, thanks for this awesome platform and this community forum. I have been a silent reader up until now but could need some help with the issue below to continue my algo trading journey:

      What I want to do:
      Test various trading strategies on perpetual future contracts as offered on Binance.

      What I can do:
      I understand the basic platform concepts (as far as i know, please correct me on this one if I'm mistaken) and can code up strategies for stock like assets, code up indicators, load data etc.

      What doesn't work / what I'm unsure about:
      I would like to configure the platform in a way that most accurately replicates cryptocurrency future trading on Binance. The discussion given in https://community.backtrader.com/topic/2132/unable-to-figure-out-leverage didn't help me to figure out what exactly i need in my case.

      From my understanding I need the following settings:

      1

      cerebro.broker.set_shortcash(False)
      

      (we don't actually receive cash when we buy perpetual short contracts on Binance)

      2

      cerebro.broker.setcommission(commission=0.0015, margin = None, mult = 2)
      

      (indicates the commission for futures trades and the "leverage" on binance which is actually a multiplier if I get that right.)

      Has anyone configured the platform for this case before? I'm running into trouble with rejected orders especially when trading several assets. On Binance, if I have 100$ and set the leverage to 2X that means that I can buy future contracts with a value of 110$ without any risk of rejection. It seems like this doesn't work on backtrader (using target_order_value or target_order_percent) with my current settings. If required, I will provide a code example but I presume this is a fairly general problem that is better described without example.

      Thanks for your help,
      stonks

      1 Reply Last reply Reply Quote 0
      • G
        Giebels last edited by

        Hi,

        I'm actually struggling with the same problem. Have you found your solution yet? Or do you know whether the assumptions you made are indeed correct?

        1 Reply Last reply Reply Quote 0
        • G
          Giebels last edited by

          Hi,

          I'm actually struggling with the same problem. Have you found your solution yet? Or do you know whether the assumptions you made are indeed correct?

          run-out 1 Reply Last reply Reply Quote 0
          • run-out
            run-out @Giebels last edited by

            @giebels If you figure out the answer to this could you make sure to post it back here for future readers? Thanks,

            RunBacktest.com

            1 Reply Last reply Reply Quote 0
            • G
              Giebels last edited by

              I have been reading up on how backtrader and binance work and I came to the conclusion that these assumptions are right. You can find up to date commission fees for binance on the binance website.

              However I'm not an expert at this stuff so I might be wrong in my conclusion.

              G 1 Reply Last reply Reply Quote 1
              • G
                Giebels @Giebels last edited by

                @giebels It seems I already made an error: rather then using mult you should use leverage which more accurately represents the circumstances of Binance futures.

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

                  I know this is over a year old, but I’m currently working on this problem and will try to make a post on how to backtest futures once I’m done figuring it out.

                  As for the comment about orders getting rejected, this is usually caused by a price difference when the order is submitted and when the order actually tries to execute, like this:

                  Buy Submitted on 2022-07-27 - Price $55.50, Value $1,000.00, Size 18.02
                  Buy Completed on 2022-07-27 - Price $55.43, Value $998.74, Size 18.02
                  

                  You can see there if the price is higher when it’s executed you won’t have enough cash available so the order will be rejected. As far as I know, the easiest way to fix this is to change the order target percentage from 1.0 to something like 0.99 so that there will be enough cash available for any slight price changes.

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