Skip to content

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

@Jiujiuwhoami

Description

@Jiujiuwhoami

Problem Description

Please provide a minimal, self-contained, and reproducible example:

import pandas as pd
import numpy as np
import pyfolio as pf

np.random.seed(42)
dates = pd.date_range('2022-01-01', periods=100)

returns_data = np.random.randn(100) / 100  
returns = pd.DataFrame({'returns': returns_data}, index=dates)
returns.index = pd.to_datetime(returns.index)
print(returns)
pf.plot_drawdown_periods(returns)

Please provide the full traceback:

Traceback (most recent call last):
  File "D:\quant_ai\mm\backtrader\text.py", line 14, in <module>
    pf.plot_drawdown_periods(returns)
  File "D:\python\lib\site-packages\pyfolio\plotting.py", line 432, in plot_drawdown_periods
    df_drawdowns = timeseries.gen_drawdown_table(returns, top=top)
  File "D:\python\lib\site-packages\pyfolio\timeseries.py", line 1008, 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:

Versions

  • Pyfolio version: pip install pyfolio
  • Python version: python3
  • Pandas version: yes
  • Matplotlib version: yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions