I have created a custom broker by modifying a couple of functions from
(calling the new file
mybbroker.pyand putting it in my own code directory, -- not in the same folder as the original bbroker.py).
Now my question is: how can I call this one to be used instead?
I tried to add a line
on top of the code, and though the import happens, it's still the original broker that gets used when I do:
import backtrader import mybroker cerebro = backtrader.Cerebro(maxcpus = 1) cerebro.addobserver(backtrader.observers.Broker) cerebro.addstrategy(StrategyBaseTradingplusplus) data = PandasDataStrat1(dataname = dataframe, datetime = -1, open = -1, high = -1, low = -1, close = -1, volume = -1, openinterest = None) cerebro.adddata(data) cerebro.broker.setcash(100000.0) cerebro.broker.setcommission(commission = 0.2, margin = 1000.0, mult = 100.0) cerebro.broker.set_filler(backtrader.broker.filler.FixedBarPerc(perc = 100.0)) cerebro.run()
So my question is: How to use my custom broker?
cerebro.setbroker(<instance of your broker class>)
Thanks, worked like a charm. As usual, thank you for the prompt answer and the references;)