Package: exchange-calendars
exchange_calendarsA Python library for defining and querying calendars for security exchanges.Calendars for more than50 exchangesavailable out-the-box! If you still can't find the calendar you're looking for,create a new one!Installation$pipinstallexchange_calendarsQuick Startimportexchange_calendarsasxcalsGet a list of available calendars:>>>xcals.get_calendar_names(include_aliases=False)[5:10]['CMES','IEPA','XAMS','XASX','XBKK']Get a calendar:>>>xnys=xcals.get_calendar("XNYS")# New York Stock Exchange>>>xhkg=xcals.get_calendar("XHKG")# Hong Kong Stock ExchangeQuery the schedule:>>>xhkg.schedule.loc["2021-12-29":"2022-01-04"]openbreak_startbreak_endclose2021-12-292021-12-29 01:30:00+00:002021-12-29 04:00:00+00:002021-12-29 05:00:00+00:002021-12-29 08:00:00+00:002021-12-302021-12-30 01:30:00+00:002021-12-30 04:00:00+00:002021-12-30 05:00:00+00:002021-12-30 08:00:00+00:002021-12-312021-12-31 01:30:00+00:00NaTNaT2021-12-31 04:00:00+00:002022-01-032022-01-03 01:30:00+00:002022-01-03 04:00:00+00:002022-01-03 05:00:00+00:002022-01-03 08:00:00+00:002022-01-042022-01-04 01:30:00+00:002022-01-04 04:00:00+00:002022-01-04 05:00:00+00:002022-01-04 08:00:00+00:00Working withsessions>>>xnys.is_session("2022-01-01")False>>>xnys.sessions_in_range("2022-01-01","2022-01-11")DatetimeIndex(['2022-01-03','2022-01-04','2022-01-05','2022-01-06','2022-01-07','2022-01-10','2022-01-11'],dtype='datetime64[ns]',freq='C')>>>xnys.sessions_window("2022-01-03",7)DatetimeIndex(['2022-01-03','2022-01-04','2022-01-05','2022-01-06','2022-01-07','2022-01-10','2022-01-11'],dtype='datetime64[ns]',freq='C')>>>xnys.date_to_session("2022-01-01",direction="next")Timestamp('2022-01-03 00:00:00',freq='C')>>>xnys.previous_session("2022-01-11")Timestamp('2022-01-10 00:00:00',freq='C')>>>xhkg.trading_index(..."2021-12-30","2021-12-31",period="90min",force=True...)IntervalIndex([[2021-12-3001:30:00,2021-12-3003:00:00),[2021-12-3003:00:00,2021-12-3004:00:00),[2021-12-3005:00:00,2021-12-3006:30:00),[2021-12-3006:30:00,2021-12-3008:00:00),[2021-12-3101:30:00,2021-12-3103:00:00),[2021-12-3103:00:00,2021-12-3104:00:00)],dtype='interval[datetime64[ns, UTC], left]')See thesessions tutorialfor a deeper dive into sessions.Working withminutes>>>xhkg.session_minutes("2022-01-03")DatetimeIndex(['2022-01-03 01:30:00+00:00','2022-01-03 01:31:00+00:00','2022-01-03 01:32:00+00:00','2022-01-03 01:33:00+00:00','2022-01-03 01:34:00+00:00','2022-01-03 01:35:00+00:00','2022-01-03 01:36:00+00:00','2022-01-03 01:37:00+00:00','2022-01-03 01:38:00+00:00','2022-01-03 01:39:00+00:00',...'2022-01-03 07:50:00+00:00','2022-01-03 07:51:00+00:00','2022-01-03 07:52:00+00:00','2022-01-03 07:53:00+00:00','2022-01-03 07:54:00+00:00','2022-01-03 07:55:00+00:00','2022-01-03 07:56:00+00:00','2022-01-03 07:57:00+00:00','2022-01-03 07:58:00+00:00','2022-01-03 07:59:00+00:00'],dtype='datetime64[ns, UTC]',length=330,freq=None)>>>mins=["2022-01-03 "+tmfortmin["01:29","01:30","04:20","07:59","08:00"]]>>>[xhkg.is_trading_minute(minute)forminuteinmins][False,True,False,True,False]# by default minutes are closed on the left side>>>xhkg.is_break_minute("2022-01-03 04:20")True>>>xhkg.previous_close("2022-01-03 08:10")Timestamp('2022-01-03 08:00:00+0000',tz='UTC')>>>xhkg.previous_minute("2022-01-03 08:10")Timestamp('2022-01-03 07:59:00+0000',tz='UTC')Check out theminutes tutorialfor a deeper dive that includes an explanation of the concept of 'minutes' and how the "side" option determines which minutes are treated as trading minutes.Tutorialssessions.ipynb- all thingssessions.minutes.ipynb- all thingsminutes. Don't miss this one!calendar_properties.ipynb- calendar constrution and a walk through the schedule and all other calendar properties.calendar_methods.ipynb- a walk through all the methods available to interrogate a calendar.trading_index.ipynb- a method that warrants a tutorial all of its own.Hopefully you'll find thatexchange_calendarshas the method you need to get the information you want. If it doesn't, eitherPRit orraise an issueand let us know!Command Line UsagePrint a unix-cal like calendar straight from the command line (holidays are indicated by brackets)...ecalXNYS20202020
        January                        February                        March
Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa
            [ 1]  2   3 [ 4]                           [ 1]
[ 5]  6   7   8   9  10 [11]   [ 2]  3   4   5   6   7 [ 8]   [ 1]  2   3   4   5   6 [ 7]
[12] 13  14  15  16  17 [18]   [ 9] 10  11  12  13  14 [15]   [ 8]  9  10  11  12  13 [14]
[19][20] 21  22  23  24 [25]   [16][17] 18  19  20  21 [22]   [15] 16  17  18  19  20 [21]
[26] 27  28  29  30  31        [23] 24  25  26  27  28 [29]   [22] 23  24  25  26  27 [28]
                                                              [29] 30  31

        April                           May                            June
Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa
              1   2   3 [ 4]                         1 [ 2]         1   2   3   4   5 [ 6]
[ 5]  6   7   8   9 [10][11]   [ 3]  4   5   6   7   8 [ 9]   [ 7]  8   9  10  11  12 [13]
[12] 13  14  15  16  17 [18]   [10] 11  12  13  14  15 [16]   [14] 15  16  17  18  19 [20]
[19] 20  21  22  23  24 [25]   [17] 18  19  20  21  22 [23]   [21] 22  23  24  25  26 [27]
[26] 27  28  29  30            [24][25] 26  27  28  29 [30]   [28] 29  30
                               [31]

            July                          August                       September
Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa
              1   2 [ 3][ 4]                           [ 1]             1   2   3   4 [ 5]
[ 5]  6   7   8   9  10 [11]   [ 2]  3   4   5   6   7 [ 8]   [ 6][ 7]  8   9  10  11 [12]
[12] 13  14  15  16  17 [18]   [ 9] 10  11  12  13  14 [15]   [13] 14  15  16  17  18 [19]
[19] 20  21  22  23  24 [25]   [16] 17  18  19  20  21 [22]   [20] 21  22  23  24  25 [26]
[26] 27  28  29  30  31        [23] 24  25  26  27  28 [29]   [27] 28  29  30
                               [30] 31

        October                        November                       December
Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa     Su  Mo  Tu  We  Th  Fr  Sa
                  1   2 [ 3]                                            1   2   3   4 [ 5]
[ 4]  5   6   7   8   9 [10]   [ 1]  2   3   4   5   6 [ 7]   [ 6]  7   8   9  10  11 [12]
[11] 12  13  14  15  16 [17]   [ 8]  9  10  11  12  13 [14]   [13] 14  15  16  17  18 [19]
[18] 19  20  21  22  23 [24]   [15] 16  17  18  19  20 [21]   [20] 21  22  23  24 [25][26]
[25] 26  27  28  29  30 [31]   [22] 23  24  25 [26] 27 [28]   [27] 28  29  30  31
                               [29] 30ecalXNYS12020January 2020
Su  Mo  Tu  We  Th  Fr  Sa
            [ 1]  2   3 [ 4]
[ 5]  6   7   8   9  10 [11]
[12] 13  14  15  16  17 [18]
[19][20] 21  22  23  24 [25]
[26] 27  28  29  30  31Frequently Asked QuestionsHow can I create a new calendar?First off, make sure the calendar you're after hasn't already been defined; exchange calendars comes with over50 pre-defined calendars, including major security exchanges.If you can't find what you're after, a custom calendar can be created as a subclass ofExchangeCalendar.This workflowdescribes the process to add a new calendar toexchange_calendars. Just follow the relevant parts.To access the new calendar viaget_calendarcall eitherxcals.register_calendarorxcals.register_calendar_typeto register, respectively, a specific calendar instance or a calendar factory (i.e. the subclass).Can I contribute a new calendar to exchange calendars?Yes please! The workflow can be foundhere.<calendar>is missing a holiday, has a wrong time, should have a break etc...Allof the exchange calendars are maintained by user contributions. If a calendar you care about needs revising, please open aPR- that's how this thing works! (Never contributed to a project before and it all seems a bit daunting? Checkthis outand don't look back!)You'll find the workflow to modify an existing calendarhere.What times are considered open and closed?exchange_calendarsattempts to be broadly useful by considering an exchange to be open only during periods of regular trading. During any pre-trading, post-trading or auction period the exchange is treated as closed. An exchange is also treated as closed during any observed lunch break.See theminutes tutorialfor a detailed explanation of which minutes an exchange is considered open over. If you previously usedtrading_calendars, orexchange_calendarsprior to release 3.4, then this is the place to look for answers to questions of how the definition of trading minutes has changed over time (and is now stable and flexible!).CalendarsExchangeISO CodeCountryVersion AddedExchange Website (English)New York Stock ExchangeXNYSUSA1.0https://www.nyse.com/indexCBOE FuturesXCBFUSA1.0https://markets.cboe.com/us/futures/overview/Chicago Mercantile ExchangeCMESUSA1.0https://www.cmegroup.com/ICE USIEPAUSA1.0https://www.theice.com/indexToronto Stock ExchangeXTSECanada1.0https://www.tsx.com/BMF BovespaBVMFBrazil1.0http://www.b3.com.br/en_us/London Stock ExchangeXLONEngland1.0https://www.londonstockexchange.com/Euronext AmsterdamXAMSNetherlands1.2https://www.euronext.com/en/regulation/amsterdamEuronext BrusselsXBRUBelgium1.2https://www.euronext.com/en/regulation/brusselsEuronext LisbonXLISPortugal1.2https://www.euronext.com/en/regulation/lisbonEuronext ParisXPARFrance1.2https://www.euronext.com/en/regulation/parisFrankfurt Stock ExchangeXFRAGermany1.2http://en.boerse-frankfurt.de/SIX Swiss ExchangeXSWXSwitzerland1.2https://www.six-group.com/en/home.htmlTokyo Stock ExchangeXTKSJapan1.2https://www.jpx.co.jp/english/Australian Securities ExchangeXASXAustralia1.3https://www.asx.com.au/Bolsa de MadridXMADSpain1.3https://www.bolsamadrid.esBorsa ItalianaXMILItaly1.3https://www.borsaitaliana.itNew Zealand ExchangeXNZENew Zealand1.3https://www.nzx.com/Wiener BorseXWBOAustria1.3https://www.wienerborse.at/en/Hong Kong Stock ExchangeXHKGHong Kong1.3https://www.hkex.com.hk/?sc_lang=enCopenhagen Stock ExchangeXCSEDenmark1.4http://www.nasdaqomxnordic.com/Helsinki Stock ExchangeXHELFinland1.4http://www.nasdaqomxnordic.com/Stockholm Stock ExchangeXSTOSweden1.4http://www.nasdaqomxnordic.com/Oslo Stock ExchangeXOSLNorway1.4https://www.oslobors.no/ob_eng/Irish Stock ExchangeXDUBIreland1.4http://www.ise.ie/Bombay Stock ExchangeXBOMIndia1.5https://www.bseindia.comSingapore ExchangeXSESSingapore1.5https://www.sgx.comShanghai Stock ExchangeXSHGChina1.5http://english.sse.com.cnKorea ExchangeXKRXSouth Korea1.6http://global.krx.co.krIceland Stock ExchangeXICEIceland1.7http://www.nasdaqomxnordic.com/Poland Stock ExchangeXWARPoland1.9http://www.gpw.plSantiago Stock ExchangeXSGOChile1.9https://www.bolsadesantiago.com/Colombia Securities ExchangeXBOGColombia1.9https://www.bvc.com.co/nueva/https://www.bvc.com.co/nueva/Mexican Stock ExchangeXMEXMexico1.9https://www.bmv.com.mxLima Stock ExchangeXLIMPeru1.9https://www.bvl.com.pePrague Stock ExchangeXPRACzech Republic1.9https://www.pse.cz/en/Budapest Stock ExchangeXBUDHungary1.10https://bse.hu/Athens Stock ExchangeASEXGreece1.10http://www.helex.gr/Istanbul Stock ExchangeXISTTurkey1.10https://www.borsaistanbul.com/en/Johannesburg Stock ExchangeXJSESouth Africa1.10https://www.jse.co.za/zMalaysia Stock ExchangeXKLSMalaysia1.11http://www.bursamalaysia.com/market/Moscow ExchangeXMOSRussia1.11https://www.moex.com/en/Philippine Stock ExchangeXPHSPhilippines1.11https://www.pse.com.ph/Stock Exchange of ThailandXBKKThailand1.11https://www.set.or.th/set/mainpage.do?language=en&country=USIndonesia Stock ExchangeXIDXIndonesia1.11https://www.idx.co.id/Taiwan Stock Exchange Corp.XTAITaiwan1.11https://www.twse.com.tw/en/Buenos Aires Stock ExchangeXBUEArgentina1.11https://www.bcba.sba.com.ar/Pakistan Stock ExchangeXKARPakistan1.11https://www.psx.com.pk/XetraXETRGermany2.1https://www.xetra.com/Tel Aviv Stock ExchangeXTAEIsrael2.1https://www.tase.co.il/Astana International ExchangeAIXKKazakhstan3.2https://www.aix.kz/Bucharest Stock ExchangeXBSERomania3.2https://www.bvb.ro/Saudi Stock ExchangeXSAUSaudi Arabia4.2https://www.saudiexchange.sa/Note that exchange calendars are defined by theirISO-10383market identifier code.market-pricesMuch of the post v3 development ofexchange_calendarshas been driven by themarket_priceslibrary. Check it out if you like the idea of usingexchange_calendarsto create meaningful OHLCV datasets. It works out-the-box with freely available data!Deprecations and RenamingMethods renamed in version 4.0.3 and removed in 4.3Previous nameNew namebound_startbound_minbound_endbound_maxMethods deprecated in 4.0 and removed in 4.3Deprecated methodReasonsessions_closesuse.closes[start:end]sessions_opensuse.opens[start:end]Methods with a parameter renamed in 4.0Methodis_sessionis_open_on_minuteminutes_in_rangeminutes_windownext_closenext_minutenext_openprevious_closeprevious_minuteprevious_opensession_break_endsession_break_startsession_closesession_opensessions_in_rangesessions_windowMethods renamed in version 3.4 and removed in 4.0Previous nameNew nameall_minutesminutesall_minutes_nanosminutes_nanosall_sessionssessionsbreak_start_and_end_for_sessionsession_break_start_enddate_to_session_labeldate_to_sessionfirst_trading_minutefirst_minutefirst_trading_sessionfirst_sessionhas_breakssessions_has_breaklast_trading_minutelast_minutelast_trading_sessionlast_sessionnext_session_labelnext_sessionopen_and_close_for_sessionsession_open_closeprevious_session_labelprevious_sessionmarket_break_ends_nanosbreak_ends_nanosmarket_break_starts_nanosbreak_starts_nanosmarket_closes_nanoscloses_nanosmarket_opens_nanosopens_nanosminute_index_to_session_labelsminutes_to_sessionsminute_to_session_labelminute_to_sessionminutes_count_for_sessions_in_rangesessions_minutes_countminutes_for_sessionsession_minutesminutes_for_sessions_in_rangesessions_minutessession_closes_in_rangesessions_closessession_distancesessions_distancesession_opens_in_rangesessions_opensOther methods deprecated in 3.4 and removed in 4.0Removed Methodexecution_minute_for_sessionexecution_minute_for_sessions_in_rangeexecution_time_from_closeexecution_time_from_open