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: 'datetime.date' object has no attribute 'to_pydatetime' #677

Open
shirishaardak opened this issue Jul 22, 2021 · 0 comments

Comments

@shirishaardak
Copy link

Problem Description

AttributeError: 'datetime.date' object has no attribute 'to_pydatetime'
Please provide a minimal, self-contained, and reproducible example:

import pandas as pd
import numpy as np
import pyfolio as pf
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')




#Read CSV file with Pandas
stock_price = pd.read_csv('./data/NIFTY_15minute.csv')

stock_price.columns = ['Date', 'Open', 'High', 'Low', 'Close', 'volume', 'oi']

stock_price['Date'] = pd.to_datetime(stock_price['Date']).dt.date

stock_price.set_index('Date', inplace=True)

stock_price['ret'] = (stock_price['Close'] - stock_price['Open'])/stock_price['Open']

stock_price = stock_price[stock_price['ret']!=0]

returns  = stock_price['ret']

print(returns)
pf.create_returns_tear_sheet(returns,
                            positions=None,
                            transactions=None,
                            cone_std=(1.0,1.5,2.0),
                            benchmark_rets=None,
                            bootstrap=False,
                            header_rows=None,
                            return_fig=False)

Please provide the full traceback:

Date
2021-01-01    0.000353
2021-01-01    0.000524
2021-01-01   -0.000517
2021-01-01    0.000642
2021-01-01   -0.000317
                ...
2021-07-19   -0.001171
2021-07-19   -0.001592
2021-07-19    0.002279
2021-07-19    0.000270
2021-07-19    0.000432
Name: ret, Length: 3353, dtype: float64
<IPython.core.display.HTML object>
Traceback (most recent call last):
  File "d:/Algorithmic Trading Proejct/algorithmic-trading-strategies/strategies/test.py", line 27, in <module>
    pf.create_returns_tear_sheet(returns,
  File "C:\Users\91989\anaconda3\lib\site-packages\pyfolio\plotting.py", line 52, in call_w_context
    return func(*args, **kwargs)
  File "C:\Users\91989\anaconda3\lib\site-packages\pyfolio\tears.py", line 504, in create_returns_tear_sheet
    plotting.show_worst_drawdown_periods(returns)
  File "C:\Users\91989\anaconda3\lib\site-packages\pyfolio\plotting.py", line 1664, in show_worst_drawdown_periods
    drawdown_df = timeseries.gen_drawdown_table(returns, top=top)
  File "C:\Users\91989\anaconda3\lib\site-packages\pyfolio\timeseries.py", line 1006, in gen_drawdown_table
    df_drawdowns.loc[i, 'Peak date'] = (peak.to_pydatetime()
AttributeError: 'datetime.date' object has no attribute 'to_pydatetime'

Please provide any additional information below:

Versions

  • Pyfolio version:
  • Python version:
  • Pandas version:
  • Matplotlib version:
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

1 participant