amor71 / LiuAlgoTrader

Framework for algorithmic trading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backtesting on a market closed day

aivisol opened this issue · comments

Describe the bug
Running backtesting on day when markets are closed, throws following error:

[backtest()][49032]2023-10-08 13:18:41.303132:backtest() - exception of type IndexError with args ('list index out of range',)
 ...
  File "/opt/homebrew/lib/python3.11/site-packages/liualgotrader/trading/alpaca.py", line 58, in __init__
    calendar = self.alpaca_rest_client.get_calendar(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

Most likely caused by this:

calendar = self.alpaca_rest_client.get_calendar(

Suggesting to change it to:

        try:
            calendar = self.alpaca_rest_client.get_calendar(
                start=now.strftime("%Y-%m-%d"), end=now.strftime("%Y-%m-%d")
            )[0]
        except IndexError:
            self.market_open = self.market_close = None
            super().__init__(qm)
            return

Let me know if this makes sense, I can send a PR.

thanks.

Thank you for joining LiuAlgoTrader community and submitting your first issue. Feel free to check out Liu community: https://gitter.im/LiuAlgoTrader/community

Stale issue message