Upgrading from 1.9.27.105 -> 1.9.43.116 breaks things
-
Hello,
I'm trying to upgrade from backtrader 1.9.27.105 to a more recent release, and things break for me.
First of all, I operate mostly on minute data and previously all of my charts would work on minute bars.
Now, the data appears to be loading in a daily timeframe, even though it is clearly minute data.... How do I fix this?
Then when I try to plot things, I get the following traceback:
cerebro.plot() File "/home/xnox/ig/backtrader/backtrader/cerebro.py", line 739, in plot start=start, end=end) File "/home/xnox/ig/backtrader/backtrader/plot/plot.py", line 218, in plot self.plotdata(data, self.dplotsover[data]) File "/home/xnox/ig/backtrader/backtrader/plot/plot.py", line 656, in plotdata color=color, label=datalabel) File "/home/xnox/ig/backtrader/backtrader/plot/finance.py", line 594, in plot_lineonclose **kwargs) File "/home/xnox/ig/backtrader/backtrader/plot/finance.py", line 534, in __init__ ax.add_line(self.loc) File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 1708, in add_line self._update_line_limits(line) File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 1730, in _update_line_limits path = line.get_path() File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 925, in get_path self.recache() File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 632, in recache raise RuntimeError('xdata and ydata must be the same length') RuntimeError: xdata and ydata must be the same length
Any idea how to work out which line / what is bombing out here?
-
Looking through latest threads on multi-frame data - it seems that you need
compression
param to be used for both.adddata
and.resampledata
. -
Hm,
TypeError: adddata() got an unexpected keyword argument 'compression'
Adding compression to the
BacktraderCSVData
object, andresampledata
call, still results in the inability to plot. -
@xnox said in Upgrading from 1.9.27.105 -> 1.9.43.116 breaks things:
TypeError: adddata() got an unexpected keyword argument 'compression'
@ab_trader meant to add
timeframe
andcompressoin
to data feed creation and not toadddata
(a small typo)Releases have been tightening that, using those parameters more and more (and more with the addition of trading calendars).
sessionend
will now be needed more and more. In the code in your github report you can add:timeframe=bt.TimeFrame.Minutes, compression=5, sessionend=datetime.time(17, 30),
And things will plot. But they may easily break.
The problem here being how the axes in
matplotlib
align if they have different lengths and things break easily. -
There was a pull request some time ago which added a calculation for aligning unequal (lengthwise) streams when plotting with multiple figures. The calculation was not 100% accurate, but it should be now with this commit.
https://github.com/mementum/backtrader/commit/f0dbadef2bc61ba1046e7f07b6a944aae864b96f