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

HistoryWindowStartsBeforeData #194

Open
noobmaster29 opened this issue Nov 20, 2020 · 2 comments
Open

HistoryWindowStartsBeforeData #194

noobmaster29 opened this issue Nov 20, 2020 · 2 comments

Comments

@noobmaster29
Copy link

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.

@gerrymanoim
Copy link
Collaborator

There was some discussion of this in #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 #176, but had some unresolved questions about the interface.

@noobmaster29
Copy link
Author

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)

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

2 participants