@MuSaCN said in How does the backtrader get the cash or value of each step?:
After this code, what can I do to get it?
one of the ways is using debugging tools get into results variable and check what data it contains.
It seems Backtrader is not compatible with Dask.
Dask version not working:
with ProgressBar(): # Backtrader is not compatible with Dask
stats = db.from_sequence(params_list).map(run_strategy).compute()
Plain multiprocessing version works:
with multiprocessing.Pool(os.cpu_count()) as p:
stats = p.map(run_strategy, params_list)
Thanks for this solution @backtrader it works like a charm !
I was wondering how you can pass an argument to the new_load function in order to deal with a variable minute (for dealing with multiple timeframes in a strategy).
I looked on stack overflow and I tried this (but got this error AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute '_old_load'):
def _new_load(self, minutes):
ret = self._old_load()
datetime = self.datetime.datetime(0)
self.datetime = bt.date2num(datetime - timedelta(minutes=minutes - 1))
minutes = 240
rd = cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=minutes)
ad, rd._load = rd._load, _new_load.__get__(rd, rd.__class__)(minutes)
@vladisld @run-out Thanks for your clarification !
Now I'm sure that Backtrader is a pure event-driven framework.
vectorized means it must take advantage of SMID operations like numpy and Pandas(Pandas actually uses numpy under the hood).
@ab_trader that seems like a simple and elegant solution.
Another solution is proposed here. It is more complex and error-prone. I built a custom class (called DataSynchronizer) that handles data feeds on the same principle (feel free to fork).