For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Rerun cerebro with same data: how to refresh Broker?
-
Hello!
I need to optimize strategy parameters but for some reasons i can't use optstrategyThe problem i got is that trying to run cerebro with same data i still have position remaining open from previos run which leads to incoherency
The question is, how can i refresh all Broker attribute values back to initial before running again?
INIT_VAL = 1e06 strats = [] i = 1 l = len(combs_filtred) cerebro = bt.Cerebro(cheat_on_open = False) data = PandasData_feed(dataname = df) cerebro.adddata(data, name = 'main') cerebro.broker.setcommission(0.04/100) for f, s, llqt, lw, slqt, sw, lp, sp, tp, sl, bbp, bbm in combs_filtred: print('{}\{} '.format(i,l), end = '') cerebro.broker.setcash(INIT_VAL) strat = cerebro.addstrategy( LiqStrategy, log = False, opt_mode = True, fast=f, # period for the fast moving average slow=s, # period for the slow moving average long_lq_thresh = llqt, long_window = lw, short_lq_thresh = slqt, short_window = sw, long_period = lp, short_period = sp, tp_size = tp, sl_size = sl, bb_period = bbp, bb_mult = bbm) t = dt.datetime(2022, 1, 20, 22, 15) cerebro.run() strats.append(strat) i += 1
-
Create a new instance of cerebro ? basicaly run this line again : cerebro = bt.Cerebro(cheat_on_open = False)
-
I would suggest getting optstrategy to work, rather than re-running new instances of cerebro, try to have optstrategy run, and post your code and errors here.