Multicore optimization cause performance degradation.
-
I must code in some wrong way, multicore optimization cause performance degradation.
Here is my code framework:
10 strategy, 10 stock asset, 10 cpu cores
Each strategy only trade one stock asset.
preload=False, runonce=Falsecorenum = 10 stocknum = 10 class UserStockStrategy(bt.Strategy): def __init__(self): self.ind = MACD(self.datas[self.p.instance]) def next(self): if time_is_right: self.buy(self.datas[self.p.instance]) cerebro = bt.Cerebro(preload=False, runonce=False, optdatas=False, maxcpus=corenum) for i in range(corenum): params = ( ('instance', i), ) mydict = dict(params=params) MyStrategy = type( f'MyUserStockStrategy{i}', (UserStockStrategy,), mydict ) setattr(bt.metabase, f'MyUserStockStrategy{i}', MyStrategy) cerebro.optstrategy(MyStrategy) for i in range(stocknum): cerebro.adddata(pandas_data[i]) cerebro.run()
If not using multicore optimization, it need 50s to finish the task, if using muticore optimization, it need 60s.
Is there anything wrong in my code?
Thanks ind advance.
-
Any particular reason for not using
preload
andrunone
options? -
The "Reply" button works finally :)
I my previous post, I have mentioned that I want to change asset dynamically
https://community.backtrader.com/topic/3422/how-to-change-asset-dynamically?_=1614960377004So I cannot use preload=True, and Runonce=True.
Is preload=True and Runonce=True cause multicore optimization not working?
-
@yacc2000 said in Multicore optimization cause performance degradation.:
Is preload=True and Runonce=True cause multicore optimization not working?
Mistake
Is preload=False and Runonce=False cause multicore optimization not working?
-
@yacc2000 said in Multicore optimization cause performance degradation.:
Is preload=False and Runonce=False cause multicore optimization not working?
It will work, just much slower. Preloading the data is one of the technics to allow running the optimization at full speed. Technically it means that pre-loaded data's memory is shared between multiple working processes instead of being reloaded to the internal buffers for each run of the engine (for each permutation of optimized parameters).
As in my answer to your previous post - the framework wasn't designed to dynamically change the data feeds during the backtest and/or optimization. You may fight against the framework ( wish you luck), change your design ( by preloading all your data feeds once) or just try a different framework
-
@vladisld Thanks