pyfolio
pyfolio copied to clipboard
'numpy.int64' object has no attribute 'to_pydatetime'
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)
~\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'
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
Same issue--would be great if this could be resolved!
With @twiecki gone, maintenance for pyfolio is going to be an issue now.
fixed this by changing line 893 in file timeseries.py
valley = underwater.index[np.argmin(underwater)] # end of the period
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
I tried reinstalling directly from git, and that fixed this issues for me
pip uninstall pyfolio
pip install git+https://github.com/quantopian/pyfolio
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 ~