perpetual futures equivalent on backtrader
-
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 -
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?
-
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?
-
@giebels If you figure out the answer to this could you make sure to post it back here for future readers? Thanks,
-
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.
-
@giebels It seems I already made an error: rather then using
mult
you should useleverage
which more accurately represents the circumstances of Binance futures. -
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.