trading_calendars icon indicating copy to clipboard operation
trading_calendars copied to clipboard

HistoryWindowStartsBeforeData

Open noobmaster29 opened this issue 4 years ago • 2 comments

Im currently using trading_calendars with zipline.

When I run my backtest, I'm currently getting a HistoryWindowStartsBeforeData error.

I'm starting the backtesting on January 02, 1968. However, it returns:

HistoryWindowStartsBeforeData: History window extends before 1975-01-02. To use this history window, start the backtest on or after 1975-12-31. (I am loading in 1 year worth of data for averages)

From my understanding, the issue is that trading calendar for the NYSE begins on 1975-01-02. This can be seen by running the following code: from trading_calendars import get_calendar

us_calendar = get_calendar('XNYS')

for x in us_calendar.schedule.index: print(x, 0.0)

The first date would be Jan. 2nd 1975.

How can we modify trading calendars to move this date further back so we can backtest beyond 1975.

Thanks in advance.

noobmaster29 avatar Nov 20 '20 03:11 noobmaster29

There was some discussion of this in https://github.com/quantopian/trading_calendars/issues/147. The current best option to get a calendar at a particular start date is to create the calendar manually instead of using the get_calendar helper:

from trading_calendars.exchange_calendar_xnys import XNYSExchangeCalendar
start = pd.Timestamp(from_date, tz=pytz.UTC)
cal = XNYSExchangeCalendar(start=start)

@richafrank and I started working on getting get_calendar to accept kwargs in https://github.com/quantopian/trading_calendars/pull/176, but had some unresolved questions about the interface.

gerrymanoim avatar Nov 20 '20 21:11 gerrymanoim

Thank you very much for the quick response.

My current fix was to manually edit the start date in trading_calendar.py. Zipline works fine after this adjustment.

start_default = pd.Timestamp('1990-01-01', tz=UTC) #edit this date to desired start end_base = pd.Timestamp('today', tz=UTC)

noobmaster29 avatar Nov 20 '20 22:11 noobmaster29