Why is Quantopian's pf.create_full_tear_sheet() function giving me a DateTimeArray error?

4.6k views Asked by At

I'm trying to run Pyfolio's pf.create_full_tear_sheet(df_returns) function on my own set of returns data df_returns (pandas dataframe) which looks like this:

enter image description here

However I'm getting the error:

TypeError: Addition/subtraction of integers and integer-arrays with DatetimeArray is no longer supported.  Instead of adding/subtracting `n`, use `n * obj.freq`

I suspect the date format might be the problem, hence I checked the datatype:

In: df_returns['Date'].dtype
Out: dtype('<M8[ns]')

In: df_returns['% Returns'].dtype
Out: dtype('float64')

Could it be that I'm not specifying the benchmark data in pf.create_full_tear_sheet(df_returns) that's causing the error too?

1

There are 1 answers

6
gosuto On BEST ANSWER

I can't really reproduce your error. It might have to do with the fact that you are passing a full dataframe: according to Pyfolio's API reference the returns argument has to be passed as a pd.Series.

If I pass just the Returns % column it gives proper output. Try:

df_returns = df_returns.set_index('Date')
pf.create_full_tear_sheet(df_returns['% Returns'])

It is good to note that I found the package dependencies to be quite outdated:

  • I had to manually install zipline which degrades pandas back to 0.22.0.
  • matplotlib is throwing a lot of deprecated warnings since 3.2.x so I degraded it to 3.1.x.
  • Use of .argmin() is deprecated and throws warnings. This issue has been known since 2019-05-24.

This leads me to believe pyfolio can be very sensitive to your environment. Did you install it using the virtual environment instructions in the docs?