-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
stefan-jansen/pyfolio-reloaded
#20Description
I have the returns, positions, and transactions for 30 trading days. It throws an error. But when I run the same for 60 trading days, it works fine.
pyfolio.tears.create_full_tear_sheet(returns1, positions1, transactions1, round_trips=True)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/matplotlib/axis.py", line 1573, in convert_units
ret = self.converter.convert(x, self.units, self)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py", line 231, in convert
values = PeriodConverter._convert_1d(values, units, axis)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py", line 250, in _convert_1d
return [get_datevalue(x, axis.freq) for x in values]
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py", line 250, in <listcomp>
return [get_datevalue(x, axis.freq) for x in values]
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pandas/plotting/_matplotlib/converter.py", line 258, in get_datevalue
return Period(date, freq).ordinal
AttributeError: 'NaTType' object has no attribute 'ordinal'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-126-d7bb60dfd7ac>", line 1, in <module>
pyfolio.tears.create_full_tear_sheet(returns1, positions1, transactions1, round_trips=True)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pyfolio/tears.py", line 190, in create_full_tear_sheet
set_context=set_context)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pyfolio/plotting.py", line 52, in call_w_context
return func(*args, **kwargs)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pyfolio/tears.py", line 570, in create_returns_tear_sheet
returns, top=5, ax=ax_drawdown)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/pyfolio/plotting.py", line 446, in plot_drawdown_periods
color=colors[i])
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/matplotlib/__init__.py", line 1565, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 5139, in fill_between
x = ma.masked_invalid(self.convert_xunits(x))
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/matplotlib/artist.py", line 178, in convert_xunits
return ax.xaxis.convert_units(x)
File "/opt/anaconda3/envs/rlf/lib/python3.7/site-packages/matplotlib/axis.py", line 1576, in convert_units
f'units: {x!r}') from e
ConversionError: Failed to convert value(s) to axis units: (NaT, Timestamp('2021-08-03 00:00:00+0000', tz='UTC'))
When I run the same code for 60 trading days, it works fine as expected. Looking at the error, it is trying to convert NaT to datetime, but the dataframe has no NaT value.
Metadata
Metadata
Assignees
Labels
No labels