Tag Archives: Quantitative back testing

[Solved] Backtrader_plotting Error: RuntimeError: Unexpected data type

During installation and use of backtrader_plotting, an error was reported.
Traceback (most recent call last):
File “main.py”, line 86, in
cerebro.plot(b)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py”, line 991, in plot
start=start, end=end, use=use)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\bokeh.py”,
line 516, in plot
self._blueprint_strategy(obj, start, end, tradingdomain, **kwargs)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\bokeh.py”,
line 228, in _blueprint_strategy
figureenv.plot(master)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\figure.py”, line 180, in plot
self.plot_data(obj)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\figure.py”, line 253, in plot_data
title = sanitize_source_name(labelizer.label(data))
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\labelizer.py”, line 84, in label
primary = _label_datafeed(obj)
File “C:\ProgramData\Anaconda3\lib\site-packages\backtrader_plotting-2.0.0-py3.7.egg\backtrader_plotting\bokeh\labelizer.py”, line 52, in _label_datafeed
raise RuntimeError(f’Unexpected data type: {data.__class__}’)
RuntimeError: Unexpected data type:

Check that it is the getattr(data, n, “”) statement that cannot get the name of the data, so it needs to be actively assigned, modifying the main code.
# Load data
cerebro.adddata(data)
for
# Load data
codename=’510300′
cerebro.adddata(data,name=codename)
Problem solved.