Extending Commissions
-
Use the link below to go the original post
Click here to see the full blog post
-
How can I use it to trade a portfolio of futures? Every contract has a different multiplier and different margin. So multiplier and margin should be linked to data rather than broker. Or is there another way to do it?
-
Commissions can be added to
bt
with relation to data feed names:for index, contract in FUT_SPECS.iterrows(): data = <add data feed with the name=contract['name']> cerebro.adddata(data) cerebro.broker.setcommission(commission=float(contract['comm']), margin=float(contract['margin']), mult=float(contract['mult']), name=contract['name'])
FUT_SPECS pandas data frame has
comm
,margin
,mult
andname
columns. -
As indicated by @ab_trader in his/her snippet, the key is the
name
that you assign to the data feed and which helps you link a given set of details for a commission scheme to that data feed.In the snippet, the commission scheme is added directly with
setcommission
, but you can also create your own instances ofCommissionInfo
and useaddcommissioninfo
. See: Docs - Broker -
That's very helpful. Thank you @ab_trader and @backtrader