Skip to content

Commit

Permalink
- Changed name of folder from "exchange_calendars" to "calendars" to …
Browse files Browse the repository at this point in the history
…avoid conflict with exchange_calendars package

- Merged in PR #282
  • Loading branch information
rsheftel committed Sep 5, 2023
2 parents 7011fc9 + 6cdf57e commit 69fec3c
Show file tree
Hide file tree
Showing 70 changed files with 633 additions and 175 deletions.
9 changes: 5 additions & 4 deletions docs/calendars.rst
Expand Up @@ -26,13 +26,14 @@ Exchange BSE BSEExchangeCalendar rakesh1988

Futures Calendars
#################
========== ================ =================================== ============ ============
========== ================= =================================== ============ ============
Exchange Name Class Unit Tests Creator
========== ================ =================================== ============ ============
========== ================= =================================== ============ ============
CME CME_Equity CMEEquityExchangeCalendar Yes rsheftel
CME CME_Bond CMEBondExchangeCalendar Yes rsheftel
CME CME_Agricultural CMEAgriculturalExchangeCalendar Yes lionelyoung
========== ================ =================================== ============ ============
CME CME_Agricultural CMEAgriculturalExchangeCalendar Yes lionelyoung
CME CME Globex Crypto CMEGlobexCryptoExchangeCalendar Yes Coinbase Asset Management
========== ================= =================================== ============ ============

Bond Market Calendars
#####################
Expand Down
2 changes: 1 addition & 1 deletion examples/usage.ipynb
Expand Up @@ -1427,7 +1427,7 @@
"# If you want to use the equity options exchange (8:30 - 15:00), including the order acceptance time at 7:30, and\n",
"# some special cases when the order acceptance time was different, do this:\n",
"\n",
"from pandas_market_calendars.exchange_calendar_cboe import CFEExchangeCalendar \n",
"from pandas_market_calendars.exchange_calendar.cboe import CFEExchangeCalendar \n",
"\n",
"class DemoOptionsCalendar(CFEExchangeCalendar): # Inherit what doesn't need to change\n",
" name = \"Demo_Options\"\n",
Expand Down
51 changes: 26 additions & 25 deletions pandas_market_calendars/calendar_registry.py
@@ -1,31 +1,32 @@
from .market_calendar import MarketCalendar
from .exchange_calendar_asx import ASXExchangeCalendar
from .exchange_calendar_bmf import BMFExchangeCalendar
from .exchange_calendar_cboe import CFEExchangeCalendar
from .exchange_calendar_cme import \
from .calendars.asx import ASXExchangeCalendar
from .calendars.bmf import BMFExchangeCalendar
from .calendars.bse import BSEExchangeCalendar
from .calendars.cboe import CFEExchangeCalendar
from .calendars.cme import \
CMEEquityExchangeCalendar, \
CMEBondExchangeCalendar
from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
from .exchange_calendar_cme_globex_agriculture import CMEGlobexAgricultureExchangeCalendar
from .exchange_calendar_cme_globex_fx import CMEGlobexFXExchangeCalendar
from .exchange_calendar_cme_globex_energy_and_metals import CMEGlobexEnergyAndMetalsExchangeCalendar
from .exchange_calendar_cme_globex_equities import CMEGlobexEquitiesExchangeCalendar
from .exchange_calendar_cme_globex_fixed_income import CMEGlobexFixedIncomeCalendar
from .exchange_calendar_eurex import EUREXExchangeCalendar
from .exchange_calendar_hkex import HKEXExchangeCalendar
from .exchange_calendar_ice import ICEExchangeCalendar
from .exchange_calendar_iex import IEXExchangeCalendar
from .exchange_calendar_jpx import JPXExchangeCalendar
from .exchange_calendar_lse import LSEExchangeCalendar
from .exchange_calendar_nyse import NYSEExchangeCalendar
from .exchange_calendar_ose import OSEExchangeCalendar
from .exchange_calendar_sifma import SIFMAUSExchangeCalendar, SIFMAUKExchangeCalendar, SIFMAJPExchangeCalendar
from .exchange_calendar_six import SIXExchangeCalendar
from .exchange_calendar_sse import SSEExchangeCalendar
from .exchange_calendar_tsx import TSXExchangeCalendar
from .exchange_calendar_bse import BSEExchangeCalendar
from .exchange_calendar_tase import TASEExchangeCalendar
from .exchange_calendars_mirror import *
from .calendars.cme_globex_base import CMEGlobexBaseExchangeCalendar
from .calendars.cme_globex_agriculture import CMEGlobexAgricultureExchangeCalendar
from .calendars.cme_globex_crypto import CMEGlobexCryptoExchangeCalendar
from .calendars.cme_globex_energy_and_metals import CMEGlobexEnergyAndMetalsExchangeCalendar
from .calendars.cme_globex_equities import CMEGlobexEquitiesExchangeCalendar
from .calendars.cme_globex_fx import CMEGlobexFXExchangeCalendar
from .calendars.cme_globex_fixed_income import CMEGlobexFixedIncomeCalendar
from .calendars.eurex import EUREXExchangeCalendar
from .calendars.hkex import HKEXExchangeCalendar
from .calendars.ice import ICEExchangeCalendar
from .calendars.iex import IEXExchangeCalendar
from .calendars.jpx import JPXExchangeCalendar
from .calendars.lse import LSEExchangeCalendar
from .calendars.nyse import NYSEExchangeCalendar
from .calendars.ose import OSEExchangeCalendar
from .calendars.sifma import SIFMAUSExchangeCalendar, SIFMAUKExchangeCalendar, SIFMAJPExchangeCalendar
from .calendars.six import SIXExchangeCalendar
from .calendars.sse import SSEExchangeCalendar
from .calendars.tase import TASEExchangeCalendar
from .calendars.tsx import TSXExchangeCalendar
from .calendars.mirror import *


def get_calendar(name, open_time=None, close_time=None) -> MarketCalendar:
Expand Down
2 changes: 1 addition & 1 deletion pandas_market_calendars/calendar_utils.py
Expand Up @@ -14,7 +14,7 @@ def merge_schedules(schedules, how='outer'):
CAVEATS:
* This does not work for schedules with breaks, the break information will be lost.
* Onlu "market_open" and "market_close" are considered, other market times are not yet supported.
* Only "market_open" and "market_close" are considered, other market times are not yet supported.
:param schedules: list of schedules
:param how: outer or inner
Expand Down
Empty file.
Expand Up @@ -3,8 +3,8 @@
from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, EasterMonday
from pytz import timezone

from .holidays_oz import *
from .market_calendar import MarketCalendar
from pandas_market_calendars.holidays.oz import *
from pandas_market_calendars.market_calendar import MarketCalendar

AbstractHolidayCalendar.start_date = '2011-01-01'

Expand Down
Expand Up @@ -19,7 +19,7 @@
from pandas.tseries.holiday import AbstractHolidayCalendar, Day, Easter, GoodFriday, Holiday
from pytz import timezone

from .market_calendar import (FRIDAY, MarketCalendar)
from pandas_market_calendars.market_calendar import (FRIDAY, MarketCalendar)

# Universal Confraternization (new years day)
ConfUniversal = Holiday(
Expand Down
Expand Up @@ -5,7 +5,7 @@
from pandas import Timestamp
from pytz import timezone
from datetime import time
from .market_calendar import MarketCalendar
from pandas_market_calendars.market_calendar import MarketCalendar


BSEClosedDay = [
Expand Down
File renamed without changes.
Expand Up @@ -20,10 +20,10 @@
from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
from pytz import timezone

from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USNationalDaysofMourning,
USNewYearsDay)
from .market_calendar import MarketCalendar
from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USNationalDaysofMourning,
USNewYearsDay)
from pandas_market_calendars.market_calendar import MarketCalendar


# Useful resources for making changes to this file: http://www.cmegroup.com/tools-information/holiday-calendar.html
Expand Down
Expand Up @@ -13,22 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
from abc import abstractmethod
from .cme_globex_base import CMEGlobexBaseExchangeCalendar

from datetime import time
from itertools import chain

from pandas import Timestamp
from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
from pytz import timezone

from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
USNationalDaysofMourning, USNewYearsDay)
from .market_calendar import MarketCalendar


from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay,
USNewYearsDay)


class CMEGlobexAgricultureExchangeCalendar(CMEGlobexBaseExchangeCalendar):
Expand Down
Expand Up @@ -15,17 +15,13 @@

from abc import ABC, abstractmethod

from datetime import time
from itertools import chain

from pandas import Timestamp
from pandas.tseries.holiday import AbstractHolidayCalendar, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
from pytz import timezone

from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
USNationalDaysofMourning, USNewYearsDay)
from .market_calendar import MarketCalendar
from pandas_market_calendars.holidays.us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
USNewYearsDay)
from pandas_market_calendars.market_calendar import MarketCalendar


class CMEGlobexBaseExchangeCalendar(MarketCalendar, ABC):
Expand All @@ -34,6 +30,7 @@ class CMEGlobexBaseExchangeCalendar(MarketCalendar, ABC):
CME Markets: https://www.cmegroup.com/markets/agriculture.html#overview
- Agriculture
- Crypto
- Energy
- Equity Index
- FX
Expand Down
147 changes: 147 additions & 0 deletions pandas_market_calendars/calendars/cme_globex_crypto.py
@@ -0,0 +1,147 @@
import datetime as dt

from pandas.tseries.holiday import AbstractHolidayCalendar
import pytz

from .cme_globex_base import CMEGlobexBaseExchangeCalendar
from pandas_market_calendars.holidays.cme import (
GoodFriday2021,
GoodFridayAfter2021,
GoodFridayBefore2021,
USIndependenceDayBefore2022PreviousDay,
)
from pandas_market_calendars.holidays.cme_globex import (
ChristmasCME,
USMartinLutherKingJrFrom2022,
USMartinLutherKingJrPre2022,
USPresidentsDayFrom2022,
USPresidentsDayPre2022,
USMemorialDayFrom2022,
USMemorialDayPre2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022,
USIndependenceDayPre2022,
USLaborDayFrom2022,
USLaborDayPre2022,
USThanksgivingDayFrom2022,
USThanksgivingDayPre2022,
USThanksgivingFridayFrom2021,
USThanksgivingFridayPre2021,
)
from pandas_market_calendars.holidays.us import (
ChristmasEveInOrAfter1993,
USNewYearsDay,
)


# https://github.com/rsheftel/pandas_market_calendars/blob/master/docs/new_market.rst
class CMEGlobexCryptoExchangeCalendar(CMEGlobexBaseExchangeCalendar):
# The label you fetch the exchange with in mcal.get_calendar('CME Globex ...')
aliases = ["CME Globex Cryptocurrencies", "CME Globex Crypto"]

# https://www.cmegroup.com/markets/cryptocurrencies/bitcoin/bitcoin.contractSpecs.html
regular_market_times = {
# Tuple[Tuple[first date used, time, offset], ...]
# -1 offset indicates that the open is on the previous day
# None for first date used marks the start, subsequent market times must have an actual timestamp
"market_open": (
(None, dt.time(17, tzinfo=pytz.timezone("America/Chicago")), -1),
),
"market_close": (
(
None,
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
),
),
"break_start": (
(
None,
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
),
),
"break_end": (
(
None,
dt.time(17, tzinfo=pytz.timezone("America/Chicago")),
),
),
}

@property
def tz(self):
# Central Time
return pytz.timezone("America/Chicago")

@property
def name(self):
return "CME Globex Crypto"

# Check the .zip files at the bottom of this page
# https://www.cmegroup.com/tools-information/holiday-calendar.html?redirect=/tools-information/holiday-calendar/#cmeGlobex
# Note: many of the holiday objects (ie. GoodFridayBefore2021) were originally made for equities and other markets
# and hence have a start_date starting before crypto is actually available

@property
def regular_holidays(self):
# Days where the market is fully closed
return AbstractHolidayCalendar(
rules=[
GoodFridayBefore2021,
GoodFridayAfter2021,
ChristmasCME,
USNewYearsDay,
]
)

@property
def special_closes(self):
# Days where the market closes early
# list[Tuple[time, AbstractHolidayCalendar]]
return [
(
dt.time(8, 15, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(rules=[GoodFriday2021]),
),
(
dt.time(12, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
USMartinLutherKingJrPre2022,
USPresidentsDayPre2022,
USMemorialDayPre2022,
USIndependenceDayPre2022,
USLaborDayPre2022,
USThanksgivingDayPre2022,
]
),
),
(
dt.time(12, 15, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
ChristmasEveInOrAfter1993,
USIndependenceDayBefore2022PreviousDay,
USThanksgivingFridayPre2021,
]
),
),
(
dt.time(12, 45, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(rules=[USThanksgivingFridayFrom2021]),
),
# TODO: this market already closes at 1600 normally, do we need these holidays?
(
dt.time(16, tzinfo=pytz.timezone("America/Chicago")),
AbstractHolidayCalendar(
rules=[
USMartinLutherKingJrFrom2022,
USPresidentsDayFrom2022,
USMemorialDayFrom2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022,
USLaborDayFrom2022,
USThanksgivingDayFrom2022,
]
),
),
]
Expand Up @@ -13,34 +13,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from .exchange_calendar_cme_globex_base import CMEGlobexBaseExchangeCalendar
from .cme_globex_base import CMEGlobexBaseExchangeCalendar

from datetime import time
from itertools import chain

import pandas as pd
from pandas import Timestamp
from pandas.tseries.holiday import AbstractHolidayCalendar #, GoodFriday, USLaborDay, USPresidentsDay, USThanksgivingDay
from pytz import timezone

#from .holidays_us import (Christmas, ChristmasEveBefore1993, ChristmasEveInOrAfter1993, USBlackFridayInOrAfter1993,
# USIndependenceDay, USMartinLutherKingJrAfter1998, USMemorialDay, USJuneteenthAfter2022,
# USNationalDaysofMourning, USNewYearsDay)

from .holidays_cme_globex import ( USNewYearsDay,
USMartinLutherKingJrFrom2022, USMartinLutherKingJrPre2022, USNewYearsDay,
USPresidentsDayFrom2022, USPresidentsDayPre2022,
GoodFriday,
USMemorialDayFrom2022, USMemorialDayPre2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022, USIndependenceDayPre2022,
USLaborDay,
USThanksgivingDayFrom2022, USThanksgivingDayPre2022, FridayAfterThanksgiving,
ChristmasCME)
from .market_calendar import MarketCalendar


from pandas_market_calendars.holidays.cme_globex import (USMartinLutherKingJrFrom2022, USMartinLutherKingJrPre2022, USNewYearsDay,
USPresidentsDayFrom2022, USPresidentsDayPre2022,
GoodFriday,
USMemorialDayFrom2022, USMemorialDayPre2022,
USJuneteenthFrom2022,
USIndependenceDayFrom2022, USIndependenceDayPre2022,
USLaborDay,
USThanksgivingDayFrom2022, USThanksgivingDayPre2022, FridayAfterThanksgiving,
ChristmasCME)


class CMEGlobexEnergyAndMetalsExchangeCalendar(CMEGlobexBaseExchangeCalendar):
Expand Down

0 comments on commit 69fec3c

Please sign in to comment.