pyfolio icon indicating copy to clipboard operation
pyfolio copied to clipboard

'numpy.int64' object has no attribute 'to_pydatetime'

Open euribate opened this issue 4 years ago • 7 comments

Problem Description

I got the following errorn when I run create_full_tear_sheet from pyfolio. can anybody help as I cannot use Pyfolio.

The following are the packages version I have installed: python 3.6 pandas 1.0.5 numpy 1.18.5 pyfolio 0.9.2 empyrical 0.5.3

the following is the full error I got AttributeError Traceback (most recent call last) in ----> 1 pf.create_returns_tear_sheet(Globale)

~\Miniconda3\envs\lavoro\lib\site-packages\pyfolio\plotting.py in call_w_context(*args, **kwargs) 50 if set_context: 51 with plotting_context(), axes_style(): ---> 52 return func(*args, **kwargs) 53 else: 54 return func(*args, **kwargs)

~\Miniconda3\envs\lavoro\lib\site-packages\pyfolio\tears.py in create_returns_tear_sheet(returns, positions, transactions, live_start_date, cone_std, benchmark_rets, bootstrap, turnover_denom, header_rows, return_fig) 502 header_rows=header_rows) 503 --> 504 plotting.show_worst_drawdown_periods(returns) 505 506 vertical_sections = 11

~\Miniconda3\envs\lavoro\lib\site-packages\pyfolio\plotting.py in show_worst_drawdown_periods(returns, top) 1662 """ 1663 -> 1664 drawdown_df = timeseries.gen_drawdown_table(returns, top=top) 1665 utils.print_table( 1666 drawdown_df.sort_values('Net drawdown in %', ascending=False),

~\Miniconda3\envs\lavoro\lib\site-packages\pyfolio\timeseries.py in gen_drawdown_table(returns, top) 1006 df_drawdowns.loc[i, 'Peak date'] = (peak.to_pydatetime() 1007 .strftime('%Y-%m-%d')) -> 1008 df_drawdowns.loc[i, 'Valley date'] = (valley.to_pydatetime() 1009 .strftime('%Y-%m-%d')) 1010 if isinstance(recovery, float):

AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'

euribate avatar Jul 31 '20 09:07 euribate

Been having the same error for quite a while

Python 3.8.2 numpy 1.19.1 pyfolio 0.9.2 empyrical 0.5.3 pandas 1.0.5

akalingking avatar Jul 31 '20 09:07 akalingking

Same issue--would be great if this could be resolved!

arnavprasad avatar Sep 02 '20 03:09 arnavprasad

With @twiecki gone, maintenance for pyfolio is going to be an issue now.

mrconway avatar Sep 05 '20 22:09 mrconway

fixed this by changing line 893 in file timeseries.py valley = underwater.index[np.argmin(underwater)] # end of the period

ghost avatar Oct 17 '20 17:10 ghost

In function: def get_max_drawdown_underwater(underwater): this line return array index(as int), but not array value:

valley = np.argmin(underwater)

so we need to change return type:

return peak, valley, recovery

to

return peak, underwater[valley:].index[0], recovery

hejun-lyne avatar Mar 04 '21 03:03 hejun-lyne

I tried reinstalling directly from git, and that fixed this issues for me

pip uninstall pyfolio

pip install git+https://github.com/quantopian/pyfolio

changjulian17 avatar Dec 02 '21 05:12 changjulian17

I tried reinstalling directly from git, and that fixed this issues for me

pip uninstall pyfolio

pip install git+https://github.com/quantopian/pyfolio

It works, thanks ~

ngloom avatar Feb 15 '22 09:02 ngloom