I try to using quantstats but when i load intraday data then give me below

I try to using quantstats but when i  load intraday data then give me below error  please check and let me know 

import yfinance as yf
import quantstats as qs



start = "2021-01-01"
end = '2022-1-01'
df = yf.download(tickers='VALE3.SA', period='5d', interval='60m')


#---------------------- Stock data Returns ---------------------#
df['pct'] = df['Close'].pct_change()


qs.reports.full(df['pct'])

Traceback (most recent call last):
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\arrays\datetimelike.py", line 1008, in _cmp_method
    other = self._validate_comparison_value(other)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\arrays\datetimelike.py", line 539, in _validate_comparison_value
    raise InvalidComparison(other) from err
pandas.core.arrays.datetimelike.InvalidComparison: 2022-08-01 00:00:00

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Algorithmic Trading Proejct\Project\stock_strategies\Test\pyfolio_test.py", line 20, in <module>
    qs.reports.full(df['pct'])
  File "C:\Users\shiri\anaconda3\lib\site-packages\quantstats\reports.py", line 302, in full
    metrics(returns=returns, benchmark=benchmark,
  File "C:\Users\shiri\anaconda3\lib\site-packages\quantstats\reports.py", line 518, in metrics
    metrics['MTD %'] = comp_func(df[df.index >= _dt(today.year, today.month, 1)]) * pct
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\ops\common.py", line 70, in new_method
    return method(self, other)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\arraylike.py", line 60, in __ge__
    return self._cmp_method(other, operator.ge)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 6685, in _cmp_method
    result = op(self._values, other)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\ops\common.py", line 70, in new_method
    return method(self, other)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\arraylike.py", line 60, in __ge__
    return self._cmp_method(other, operator.ge)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\arrays\datetimelike.py", line 1010, in _cmp_method
    return invalid_comparison(self, other, op)
  File "C:\Users\shiri\anaconda3\lib\site-packages\pandas\core\ops\invalid.py", line 34, in invalid_comparison
    raise TypeError(f"Invalid comparison between dtype={left.dtype} and {typ}")
TypeError: Invalid comparison between dtype=datetime64[ns, America/Sao_Paulo] and datetime

I attached data file



data

import pandas as pd
import numpy as np
import quantstats as qs
import pyfolio as pf
import yfinance as yf
import quantstats as qs

df = pd.read_csv(r'D:/Algorithmic Trading Proejct/Project/stock_data/downloaded_data/nifty_bank_10minute.CSV', index_col='Date')
df = pd.DataFrame(df)

df['Date'] = pd.to_datetime(df.index)
df['Differe_close'] = df['Close'] - df['Close'].shift(5)

df['long_positions'] = np.where(df['Differe_close'] > 0, 1, 0)

df['short_positions'] = np.where(df['Differe_close'] < 0, -1, 0)

df['positions'] = df['long_positions'] + df['short_positions']

# Calculate daily returns
df['returns'] = df['Close'].pct_change()

# Calculate strategy returns
df['strategy_returns'] = df['returns'] * df['positions'].shift(1)

qs.reports.full(df['strategy_returns'])

 

Hi Shirish, 



You need to remove the timezone information from the index of the dataframe df and convert it to UTC before using quantstats (especially for intraday data)



so, add the following line after downloading the data from yfinance.

df.index = df.index.tz_convert(None)

You will be able to generate the full report without any issues. 



Hope this helps!