Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConversionError when running plot_drawdown_periods #35

Open
ktan636 opened this issue Jul 18, 2023 · 0 comments
Open

ConversionError when running plot_drawdown_periods #35

ktan636 opened this issue Jul 18, 2023 · 0 comments

Comments

@ktan636
Copy link

ktan636 commented Jul 18, 2023

Problem Description

I hit a conversion error when running pyfolio.plotting.plot_drawdown_periods().
First, I ran a backtest in Zipline-reloaded with a start date of 2022-01-02 and an end date of 2023-05-31 and the backtest completed successfully.
Then, I extracted the returns from the backtest result using pyfolio.utils.extract_rets_pos_txn_from_zipline(result).
Finally, I ran pyfolio.plotting.plot_drawdown_periods(returns) and that threw a ConversionError.

Please provide a minimal, self-contained, and reproducible example:

import pyfolio as pf
returns, positions, transactions = pf.utils.extract_rets_pos_txn_from_zipline(perf)  ## perf is output from zipline algorithm
pf.plot_drawdown_periods(returns)

Please provide the full traceback:

TypeError                                 Traceback (most recent call last)
File [c:\Users\ktan636\Anaconda3\envs\zipline310\lib\site-packages\matplotlib\axis.py:1732](file:///C:/Users/ktan636/Anaconda3/envs/zipline310/lib/site-packages/matplotlib/axis.py:1732), in Axis.convert_units(self, x)
   1731 try:
-> 1732     ret = self.converter.convert(x, self.units, self)
   1733 except Exception as e:

File [c:\Users\ktan636\Anaconda3\envs\zipline310\lib\site-packages\pandas\plotting\_matplotlib\converter.py:287](file:///C:/Users/ktan636/Anaconda3/envs/zipline310/lib/site-packages/pandas/plotting/_matplotlib/converter.py:287), in DatetimeConverter.convert(values, unit, axis)
    286 else:
--> 287     values = DatetimeConverter._convert_1d(values, unit, axis)
    288 return values

File [c:\Users\ktan636\Anaconda3\envs\zipline310\lib\site-packages\pandas\plotting\_matplotlib\converter.py:322](file:///C:/Users/ktan636/Anaconda3/envs/zipline310/lib/site-packages/pandas/plotting/_matplotlib/converter.py:322), in DatetimeConverter._convert_1d(values, unit, axis)
    320         pass
--> 322     values = dates.date2num(values)
    324 return values

File [c:\Users\ktan636\Anaconda3\envs\zipline310\lib\site-packages\matplotlib\dates.py:462](file:///C:/Users/ktan636/Anaconda3/envs/zipline310/lib/site-packages/matplotlib/dates.py:462), in date2num(d)
    461         d = np.asarray(d)
--> 462     d = d.astype('datetime64[us]')
    464 d = np.ma.masked_array(d, mask=mask) if masked else d

TypeError: 'float' object cannot be interpreted as an integer

The above exception was the direct cause of the following exception:
...
-> 1734     raise munits.ConversionError('Failed to convert value(s) to axis '
   1735                                  f'units: {x!r}') from e
   1736 return ret

ConversionError: Failed to convert value(s) to axis units: (NaT, Timestamp('2023-05-31 00:00:00+0000', tz='UTC'))

Please provide any additional information below:

returns.tail()

2023-05-24 00:00:00+00:00 -0.001341
2023-05-25 00:00:00+00:00 0.002400
2023-05-26 00:00:00+00:00 0.003129
2023-05-30 00:00:00+00:00 0.000319
2023-05-31 00:00:00+00:00 -0.001153
Name: returns, dtype: float64

Versions

  • Pyfolio version: 0.9.5
  • Python version: 3.10.11
  • Pandas version: 1.5.3
  • Matplotlib version: 3.7.1
  • Zipline version: 2.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant