quantstats
quantstats copied to clipboard
IndexError: list index out of range
Running the example code shown gives the following error:
stock = qs.utils.download_returns('FB')
qs.reports.html(stock, "SPY", output="report.html")
Traceback (most recent call last):
File "d:\Finansiering. Modern Portfolio Theory Projekt\MyOwnBacktester.py", line 106, in <module>
qs.reports.html(stock, "SPY", output="D:\\Finansiering. Modern Portfolio Theory Projekt\\Data\\Processed Data\\report.html")
File "D:\Anaconda\envs\zipline\lib\site-packages\quantstats\reports.py", line 125, in html
show=False, ylabel=False, compounded=compounded)
File "D:\Anaconda\envs\zipline\lib\site-packages\quantstats\_plotting\wrappers.py", line 381, in yearly_returns
savefig=savefig, show=show)
File "D:\Anaconda\envs\zipline\lib\site-packages\quantstats\_plotting\core.py", line 117, in plot_returns_bars
df.plot(kind='bar', ax=ax, color=colors)
File "D:\Anaconda\envs\zipline\lib\site-packages\pandas\plotting\_core.py", line 847, in __call__
return plot_backend.plot(data, kind=kind, **kwargs)
File "D:\Anaconda\envs\zipline\lib\site-packages\pandas\plotting\_matplotlib\__init__.py", line 61, in plot
plot_obj.generate()
File "D:\Anaconda\envs\zipline\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 265, in generate
self._make_legend()
File "D:\Anaconda\envs\zipline\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 572, in _make_legend
ax.legend(handles, labels, loc="best", title=title)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\axes\_axes.py", line 423, in legend
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend.py", line 556, in __init__
self._init_legend_box(handles, labels, markerfirst)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend.py", line 815, in _init_legend_box
fontsize, handlebox))
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend_handler.py", line 115, in legend_artist
fontsize, handlebox.get_transform())
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend_handler.py", line 299, in create_artists
self.update_prop(p, orig_handle, legend)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend_handler.py", line 72, in update_prop
self._update_prop(legend_handle, orig_handle)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend_handler.py", line 65, in _update_prop
self._update_prop_func(legend_handle, orig_handle)
File "D:\Anaconda\envs\zipline\lib\site-packages\matplotlib\legend_handler.py", line 38, in update_from_first_child
tgt.update_from(src.get_children()[0])
IndexError: list index out of range
same erroe = IndexError: index 0 is out of bounds for axis 0 with size 0
You need to run downgrade to 0.0.25 They borked the last release pip install quantstats==0.0.25
Have the same error as @AnasEssahal when using qs.reports.full
with both returns and a benchmark. Downgrading to 0.0.25 did not fix this error (although downgrading did allow me to run the qs.reports.html
with both returns and benchmark without error)
@AnasEssahal Thought might be useful. For my error was "IndexError: index -1 is out of bounds for axis 0 with size 0",
What I did was:
- Check that ticker name does exist (and correct name) in yahoo finance, since Quantstats retrieve their data from yahoo finance
- Set 1 yr period or lesser. example
qs.utils.download_returns('DOT1-USD', period="1y
) as some assets out there are new. this error arises especially if you deal with portfolio.qs.utils.make_index()
as some assets are newer than others, hence the data index will not match