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

AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime' due to incorrect valley val type #682

Open
gcorre02 opened this issue Sep 25, 2021 · 1 comment

Comments

@gcorre02
Copy link

gcorre02 commented Sep 25, 2021

Problem Description

valley is not being set to a timestamp in line 884 of timeseries.py

Please provide a minimal, self-contained, and reproducible example:
too complex to add code here, will try later and add as a follow up comment

Please provide the full traceback:

Traceback (most recent call last):
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-535ebec2a3b4>", line 1, in <module>
    runfile('/opt/fin_gpu/GPU_Podracer/test.py', wdir='/opt/fin_gpu/GPU_Podracer')
  File "/opt/pycharm-2021.2.2/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/opt/pycharm-2021.2.2/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/opt/fin_gpu/GPU_Podracer/test.py", line 23, in <module>
    args.env.backtest_plot(prediction, baseline_ticker = '^DJI', baseline_start = '2019-01-01', baseline_end = '2021-01-01')
  File "/opt/fin_gpu/GPU_Podracer/elegant_finrl/env.py", line 291, in backtest_plot
    pyfolio.create_full_tear_sheet(returns=test_returns, benchmark_rets=baseline_returns, set_context=False)
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/pyfolio/tears.py", line 173, in create_full_tear_sheet
    create_returns_tear_sheet(
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/pyfolio/plotting.py", line 54, in call_w_context
    return func(*args, **kwargs)
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/pyfolio/tears.py", line 457, in create_returns_tear_sheet
    plotting.show_worst_drawdown_periods(returns)
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/pyfolio/plotting.py", line 1688, in show_worst_drawdown_periods
    drawdown_df = timeseries.gen_drawdown_table(returns, top=top)
  File "/home/guilherme/anaconda3/envs/GPU_Podracer/lib/python3.9/site-packages/pyfolio/timeseries.py", line 999, in gen_drawdown_table
    df_drawdowns.loc[i, 'Valley date'] = (valley.to_pydatetime()
AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'

Please provide any additional information below:

Fixed the issue by replacing line 884 of timeseries.py with:

valley = underwater.index[np.argmin(underwater)] # end of the period

Versions

  • Pyfolio version: 0.8.0
  • Python version: 3.9
  • Pandas version: 1.3.3
  • Matplotlib version: 3.4.3
@gcorre02 gcorre02 changed the title AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime' due to incorrect valley val format AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime' due to incorrect valley val type Sep 25, 2021
@gerileka
Copy link

gerileka commented Apr 5, 2022

This resolved my issue, thank you

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

2 participants