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

'DatetimeIndex' object has no attribute 'to_datetime' #22

Open
plankconst opened this issue Feb 10, 2019 · 0 comments
Open

'DatetimeIndex' object has no attribute 'to_datetime' #22

plankconst opened this issue Feb 10, 2019 · 0 comments

Comments

@plankconst
Copy link

plankconst commented Feb 10, 2019

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'

ematvey added a commit that referenced this issue Aug 19, 2019
fixes datetime converstion issue ( issue #22)
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