Replies: 3 comments
-
It's common internally to get the index of a session or slice of a range of sessions. Using session nanos would allow for the following performance improvements on such calls: With... import exchange_calendars as xcals
cal = xcals.get_calendar("XHKG")
all_sessions_nanos = cal.all_sessions.values.astype('int64')
session = cal.all_sessions[-333]
start = cal.all_sessions[-1000]
end = cal.all_sessions[-300] then... all_sessions_nanos.searchsorted(session.value) is >10x quicker than... cal.all_sessions.get_loc(session) and... slice_start = all_sessions_nanos.searchsorted(start.value, side="left")
slice_end = all_sessions_nanos.searchsorted(end.value, side="right")
slice(slice_start, slice_end) is also >10x quicker than... cal.all_sessions.slice_indexer(start, end) Seems like a no-brainer to employ session nanos internally...? |
Beta Was this translation helpful? Give feedback.
-
I'm going to implement this on a method-by-method basis... I looked into changing the parsing methods so that they return an interger (nano) rather than a pd.Timestamp. On balance, I've decided against it - some methods are no worse off or better off using a Timestamp than an integer. Also, it's cleaner for tests (which for speed want to be able to skip parsing) to pass through Timestamps than having to first convert everything to values. A session or minute argument is always going to be represented as a timestamp at some point before it gets to a method's guts (either during parsing or, for tests, in Answers), there's no point further parsing them to nanos. Better that a method receives parsed input as a Timestamp and is then responsible for converting to a nano if that's what's most efficient for the method's purpose. |
Beta Was this translation helpful? Give feedback.
-
Implemented in #104. |
Beta Was this translation helpful? Give feedback.
-
In the same way that methods interrogating mintues were sped up by the use of nano arrays, couldn't methods looking up a session or sessions benefit from an
all_sessions_nanos
property and being able to do this...all_sessions_nanos.searchsorted(session(s).value)
?I suspect at least some such methods could see worthwhile speed increases.
Example:
...is about 6x quicker than the current...
Beta Was this translation helpful? Give feedback.
All reactions