Skip to content

AttributeError: 'Index' object has no attribute 'tz' on Hourly data #26

Description

@thomasf1

When testing with hourly data instead of the daily on the example app (ms/ml) and calling the summary, I get the following error:

Traceback (most recent call last):
  File "pyback1.py", line 75, in <module>
    print(bt.summary())
  File "/usr/local/lib/python3.7/site-packages/pybacktest/backtest.py", line 174, in summary
    print((yaml.dump(self.report, allow_unicode=True, default_flow_style=False)))
  File "/usr/local/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.7/site-packages/pybacktest/backtest.py", line 164, in report
    return pybacktest.performance.performance_summary(self.equity)
  File "/usr/local/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.7/site-packages/pybacktest/backtest.py", line 152, in equity
    return pybacktest.parts.trades_to_equity(self.trades)
  File "/usr/local/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.7/site-packages/pybacktest/backtest.py", line 142, in trades
    assert p.index.tz == tp.index.tz, "Cant operate on singals and prices " \
AttributeError: 'Index' object has no attribute 'tz'

The data looks similar, with the date format being more detailed.

I was using pd.to_datetime on a csv (without a timezone information). If there is no TimeZone information it would be nice to have a better error message.

Solution: Add a Timezone, pd.to_datetime(x, utc=True) in my case

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions