pybacktest icon indicating copy to clipboard operation
pybacktest copied to clipboard

'DatetimeIndex' object has no attribute 'to_datetime'

Open plankconst opened this issue 6 years ago • 0 comments

I am using Python 3.7 and Pandas 0.24

I get this error from holding_periods function.

def holding_periods(eqd):
    # rather crude, but will do
    return pd.Series(eqd.index.to_datetime(), index=eqd.index, dtype=object).diff().dropna()

Should it be?

def holding_periods(eqd):
    # rather crude, but will do
    return pd.Series(pd.to_datetime (eqd.index), index=eqd.index, dtype=object).diff().dropna()

Or it might be deprecated in latest versions of Pandas:

https://pandas.pydata.org/pandas-docs/version/0.21/generated/pandas.Timestamp.to_datetime.html

Timestamp.to_datetime() DEPRECATED: use to_pydatetime() instead.

Convert a Timestamp object to a native Python datetime object.


AttributeError Traceback (most recent call last) in ----> 1 bt.summary()

C:\ProgramData\Anaconda3\lib\site-packages\pybacktest\backtest.py in summary(self) 172 print(s) 173 print(('-' * len(s) + '\n')) --> 174 print((yaml.dump(self.report, allow_unicode=True, default_flow_style=False))) 175 print(('-' * len(s))) 176

C:\ProgramData\Anaconda3\lib\site-packages\cached_property.py in get(self, obj, cls) 33 return self._wrap_in_coroutine(obj) 34 ---> 35 value = obj.dict[self.func.name] = self.func(obj) 36 return value 37

C:\ProgramData\Anaconda3\lib\site-packages\pybacktest\backtest.py in report(self) 162 @cached_property 163 def report(self): --> 164 return pybacktest.performance.performance_summary(self.equity) 165 166 def summary(self):

C:\ProgramData\Anaconda3\lib\site-packages\pybacktest\performance.py in performance_summary(equity_diffs, quantile, precision) 89 if len(eqd) == 0: 90 return {} ---> 91 hold = holding_periods(equity_diffs) 92 93 return _format_out({

C:\ProgramData\Anaconda3\lib\site-packages\pybacktest\performance.py in holding_periods(eqd) 68 def holding_periods(eqd): 69 # rather crude, but will do ---> 70 return pd.Series(eqd.index.to_datetime(), index=eqd.index, dtype=object).diff().dropna() 71 72

AttributeError: 'DatetimeIndex' object has no attribute 'to_datetime'

plankconst avatar Feb 10 '19 02:02 plankconst