alpacahq/alpaca-backtrader-api

clean install fails - trading_calendars is broken and unmaintained

Tantalon opened this issue · 5 comments

A clean install of alpaca_backtrader_api fails on import:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/regg002/.local/share/virtualenvs/Repo-7RUXb6y2/lib/python3.9/site-packages/alpaca_backtrader_api/__init__.py", line 1, in <module>
    from .alpacastore import AlpacaStore
  File "/Users/regg002/.local/share/virtualenvs/Repo-7RUXb6y2/lib/python3.9/site-packages/alpaca_backtrader_api/alpacastore.py", line 12, in <module>
    import trading_calendars
  File "/Users/regg002/.local/share/virtualenvs/Repo-7RUXb6y2/lib/python3.9/site-packages/trading_calendars/__init__.py", line 16, in <module>
    from .trading_calendar import TradingCalendar
  File "/Users/regg002/.local/share/virtualenvs/Repo-7RUXb6y2/lib/python3.9/site-packages/trading_calendars/trading_calendar.py", line 33, in <module>
    from .calendar_helpers import (
  File "/Users/regg002/.local/share/virtualenvs/Repo-7RUXb6y2/lib/python3.9/site-packages/trading_calendars/calendar_helpers.py", line 6, in <module>
    NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

This is due to quantopian/trading_calendars#224: "[trading_calendars] isn't being maintained (see the README) although a fork exchange_calendars is being maintained and this issue was resolved in the latest release (3.2)." [ref]

vi /Users/claytongraham/.pyenv/versions/trading-bot/lib/python3.8/site-packages/trading_calendars/calendar_helpers.py

change:

#NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
NP_NAT = pd.NaT.value

vi /Users/claytongraham/.pyenv/versions/trading-bot/lib/python3.8/site-packages/trading_calendars/calendar_helpers.py

change:

#NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
NP_NAT = pd.NaT.value

useful for pd.version = 1.3.3 Many thanks!

I tried the above workaround (changing value of NP_NAT) which gets me further... but then throws this error:

Starting Portfolio Value: 10000.00
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/kian/.local/lib/python3.8/site-packages/alpaca_backtrader_api/alpacastore.py", line 415, in _t_candles
    cdl = cdl.loc[
  File "/home/kian/.local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)
  File "/home/kian/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 5948, in dropna
    raise KeyError(list(np.compress(check, subset)))
KeyError: ['high']

@kianjones9 #172 references this error, specifically this comment