quantopian / pyfolio

Portfolio and risk analytics in Python

Home Page:https://quantopian.github.io/pyfolio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'datetime.date' object has no attribute 'to_pydatetime'

shirishaardak opened this issue · comments

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: