I am try to use pyfolio for bask testing but give me below error

import yfinance as yf
import pyfolio as pf
import pandas as pd

df = pd.read_csv(
    r'D:/trading_algorithms_project/strategy_analysis/stock_data/downloaded_data/nifty_bank_15minute.CSV', index_col='Date')

df = pd.DataFrame(df)
#---------------------- Stock data Returns ---------------------#
#df.index = df.index.tz_localize('utc')
df['pct'] = df['Close'].pct_change()

returns = df['pct']

pf.create_returns_tear_sheet(returns, benchmark_rets = None)

Traceback (most recent call last):

  File "d:\trading_algorithms_project\strategy_analysis\stock_strategies\Test\pyfolio_test.py", line 17, in <module>

    pf.create_returns_tear_sheet(returns, benchmark_rets = None)

  File "C:\Users\shiri\anaconda3\lib\site-packages\pyfolio\plotting.py", line 52, in call_w_context

    return func(*args, **kwargs)

  File "C:\Users\shiri\anaconda3\lib\site-packages\pyfolio\tears.py", line 496, in create_returns_tear_sheet

    plotting.show_perf_stats(returns, benchmark_rets,

  File "C:\Users\shiri\anaconda3\lib\site-packages\pyfolio\plotting.py", line 595, in show_perf_stats

    date_rows['Start date'] = returns.index[0].strftime('%Y-%m-%d')

AttributeError: 'str' object has no attribute 'strftime'

Date
2017-01-02T09:15:00+0530         NaN
2017-01-02T09:30:00+0530   -0.000130
2017-01-02T09:45:00+0530   -0.001618
2017-01-02T10:00:00+0530   -0.000166
2017-01-02T10:15:00+0530   -0.000161
                              ...   
2022-09-26T10:00:00+0530   -0.000065
2022-09-26T10:15:00+0530   -0.002258
2022-09-26T10:30:00+0530    0.001142
2022-09-26T10:45:00+0530   -0.002769
2022-09-26T11:00:00+0530   -0.000638
Name: pct, Length: 35384, dtype: float64

Hi Shirish,



This error usually occurs when the index is not in the correct format. You can refer to the following links for more information regarding the issue.



Link 1



Link 2



Hope this helps!



Thanks,

Akshay