Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supersedes #89.
Adds
ExchangeCalendar.trading_index
to create a trading index over a given range of sessions at a given period. Similar topandas_market_calendars.date_range
with additional functionality:pd.DatetimeIndex
of indices orpd.IntervalIndex
of intervals.force_close
andforce_break_close
options.exchange_calendars
use of nanos for faster execution (evaluates trading index for XHKG (a calendar with breaks) over a year at 30 minute periods in <2ms).Credit to @Stryder-Git at
pandas_market_calendars
for showing the way with a vectorised implementation.Given the extent of the implementation, I've placed the guts of it as a class (
_TradingIndex
) oncalendar_helpers.py
. This also fits neatly with the substantial test class being placed ontest_calendar_helpers.py
rather than overwhelmingExchangeCalendarTestBase
.I'll add/update tutorials on the readme branch to include example usage.
Tests
The functionality provides for a high degree of customisation, with the
intervals
,closed
,force_close
,force_break_close
andcurtail_overlaps
options all providing for different behaviour. Such variablilty precludes comprehensively testing against concrete cases. Thehypothesis
library (new dev. dependency) is instead employed to define fuzz tests.Testing is split between:
ExchangeCalendarTestBase.test_trading_index
. Tests, for all calendars, a multitude of concrete cases covering the product of various periods and all answers session blocks. Options assume default values.test_calendar_helpers.TestTradingIndex
. Class subjects select calendars (each of a unique behaviour) to: