kav last edited by kav
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?
momentum last edited by
cerebro.setbroker(<instance of your broker class>)
Why don't you use what's already documented?
Example: Docs - Live Trading - Oanda v1.0
Cerebroreference says what
setbrokerdoes (can also be reached via the
brokerproperty): Docs - Cerebro
kav last edited by
Thanks, worked like a charm. As usual, thank you for the prompt answer and the references;)