3

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?

spidermarn
  • 959
  • 1
  • 10
  • 18

1 Answers1

2

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?

gosuto
  • 5,422
  • 6
  • 36
  • 57
  • Hi jorijnsmit.. with your suggestion i managed to get the Annual Return to Dail value risk stats. but it stops there and doesn't produce any charts. I get this error ````'numpy.int64' object has no attribute 'to_pydatetime'```` Similar to the final post in this thread: https://www.quantopian.com/posts/trouble-with-basic-pyfolio-tearsheet – spidermarn Apr 08 '20 at 17:11
  • create_full_tear_sheet() requires a full pandas dataframe format to be passed in.. – spidermarn Apr 08 '20 at 17:18
  • Then only set a proper index and pass the whole `df_returns`. – gosuto Apr 08 '20 at 17:26
  • ````ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().```` – spidermarn Apr 08 '20 at 17:33
  • Expanded my answer. Here's a working example: https://colab.research.google.com/drive/1Umi9fC5srxxssrGbFJoNjFsxqBO-s_eO – gosuto Apr 09 '20 at 10:30
  • i realized it was my local zipline library giving me the issues...using colab as u indirectly suggested worked! – spidermarn Apr 10 '20 at 16:07