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

Breaks, interruptions, special market times, and min python version #198

Closed
Stryder-Git opened this issue May 25, 2022 · 6 comments · Fixed by #210
Closed

Breaks, interruptions, special market times, and min python version #198

Stryder-Git opened this issue May 25, 2022 · 6 comments · Fixed by #210

Comments

@Stryder-Git
Copy link
Collaborator

Stryder-Git commented May 25, 2022

@rsheftel, @glossner

This is my proposal for handling the interruptions marked as "NOT IMPLEMENTED" in NYSEExchangeCalendar.

Considering that these kind of "breaks" don't neatly fit into regular_market_times and/or the schedule, and that not everyone will care about them. I thought this would be a good way of optionally allowing access to the interruptions data.

The code for the 'MyCalendar' class is in this gist. There you will see the way such a property would be defined.

Demo:

cal = MyCalendar()
print(cal.interruptions_df.to_string())
                interruption_start_1        interruption_end_1      interruption_start_2        interruption_end_2
0                                                                                                                 
2011-01-10 2011-01-10 11:00:00-05:00 2011-01-10 11:01:00-05:00                       NaT                       NaT
2010-01-11 2010-01-11 11:00:00-05:00 2010-01-11 11:01:00-05:00                       NaT                       NaT
2003-09-11 2003-09-11 09:59:00-04:00 2003-09-11 10:00:00-04:00 2003-09-11 10:29:00-04:00 2003-09-11 10:30:00-04:00
2002-02-03 2002-02-03 11:00:00-05:00 2002-02-03 11:02:00-05:00                       NaT                       NaT

sched = cal.schedule("2003-09-07", "2003-09-14", interruptions= True)
print(sched.to_string())

                         market_open              market_close      interruption_start_1        interruption_end_1      interruption_start_2        interruption_end_2
2003-09-08 2003-09-08 13:30:00+00:00 2003-09-08 20:00:00+00:00                       NaT                       NaT                       NaT                       NaT
2003-09-09 2003-09-09 13:30:00+00:00 2003-09-09 20:00:00+00:00                       NaT                       NaT                       NaT                       NaT
2003-09-10 2003-09-10 13:30:00+00:00 2003-09-10 20:00:00+00:00                       NaT                       NaT                       NaT                       NaT
2003-09-11 2003-09-11 13:30:00+00:00 2003-09-11 20:00:00+00:00 2003-09-11 13:59:00+00:00 2003-09-11 14:00:00+00:00 2003-09-11 14:29:00+00:00 2003-09-11 14:30:00+00:00
2003-09-12 2003-09-12 13:30:00+00:00 2003-09-12 20:00:00+00:00                       NaT                       NaT                       NaT                       NaT

I would integrate this into the MarketCalendar base class. The .schedule method would provide an interruptions kwarg that would allow these interruptions to be added to the schedule. Then the default (not adding it) would still return the same output as the current version.

Also, it is already possible to add multiple breaks to regular_market_times and to set special times for any of those market_times. When implementing this update, I can clarify and demonstrate this further in the examples notebook.

Other changes I would like to include in this update:

  • Adjust .open_at_time to work with multiple breaks and/or interruptions in a day.
  • Allow offsets to be set in the special_ properties, which wasn't possible thus far.

Let me know what you think.

Additional note (mostly as a reminder to myself), offsets should also be allowed in the interruptions property.

(edit) Addtional reminder: #207

@glossner
Copy link
Collaborator

@Stryder-Git Looks good. Thanks!

If you enhance open_at_time(), shouldn't we enable interruptions as the default case?

@rsheftel
Copy link
Owner

Seems like a very smart solution

@Stryder-Git
Copy link
Collaborator Author

@glossner, I was planning on leaving the default as is, so that backwards compatibility is not a problem. Also, adding the interruptions will cause a lot of NaN values, that I don't think most people would want.

If there are no additional requests/issues pointed out I will get started on this in the next week or two and keep you posted.

Thanks.

@glossner
Copy link
Collaborator

glossner commented Jun 8, 2022

@Stryder-Git the point about NaNs makes sense. Thanks.

@Stryder-Git Stryder-Git changed the title Breaks, interruptions and special market times Breaks, interruptions, special market times, and min python version Jun 8, 2022
@Stryder-Git
Copy link
Collaborator Author

@rsheftel, For the past weeks to months, travis kept failing with the python 3.7 build. Python 3.7 is getting relatively old and exchange_calendars is advancing its minimum python version from 3.7 to 3.8 in version 4.0. So we will have to drop 3.7 anyway and then we should also add python 3.10 to the the travis build configuration.

Unless you disagree or would like to do it yourself, should I open a PR for this before starting on the other suggestions in this issue?

Thanks.

@Stryder-Git Stryder-Git linked a pull request Aug 2, 2022 that will close this issue
@rsheftel
Copy link
Owner

This is released in v4.0 PR #210

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

Successfully merging a pull request may close this issue.

3 participants