New Market or Exchange

See examples/usage.ipynb for demonstrations

To create a new exchange (or OTC market):

  1. Create a new class that inherits from MarketCalendar
  2. Set the class attribute aliases: […] for accessing the calendar through mcal.get_calendar
  3. Create the regular_market_times class attribute, meeting these requirements:
    1. It needs to be a dictionary
    2. Each market_time needs one entry
      1. Regular open must be “market_open”, regular close must be “market_close”.
      2. If there is a break, there must be a “break_start” and a “break_end”.
      3. only ONE break is currently supported.
    3. One list/tuple for each market_time, containing at least one list/tuple:
      1. Each nested iterable needs at least two items: (first_date_used, time[, offset]).
      2. The first iterable’s date should be None, marking the start. In every iterable thereafter this is the date when time was first used.
      3. Optionally (assumed to be zero, when not present), a positive or negative integer, representing an offset in number of days.
      4. Dates need to be in ascending order, None coming first.
  4. Define the following property methods:
    1. name
    2. tz (time zone)
  5. Now optionally define any of the following property methods:
    1. Days where the market is fully closed:
      1. regular_holidays - returns an pandas AbstractHolidayCalendar object
      2. adhoc_holidays - returns a list of pandas Timestamp of a DatetimeIndex
    2. Days where the market closes early:
      1. special_closes - returns a list of tuples. The tuple is (datetime.time of close, AbstractHolidayCalendar)
      2. special_closes_adhoc - returns a list of tuples. The tuple is (datetime.time of close, list of date strings)
    3. Days where the market opens late:
      1. special_opens - returns a list of tuples. The tuple is (datetime.time of open, AbstractHolidayCalendar)
      2. special_opens_adhoc - returns a list of tuples. The tuple is (datetime.time of open, list of date strings)
    4. Set special times for any market_time in regular_market_times, by setting a property in this format:
      1. special_{market_time}_adhoc
        same format as special_opens_adhoc, which is the same as special_market_open_adhoc
      2. special_{market_time}
        same format as special_opens, which is the same as special_market_open
  6. Import your new calendar class in
from .exchange_calendar_xxx import XXXExchangeCalendar