Package: trading-calendars
trading_calendarsA Python library of exchange calendars, frequently used withZipline.Installation$pipinstalltrading-calendarsQuick Startimporttrading_calendarsastcimportpandasaspdimportpytzGet all registered calendars withget_calendar_names:>>>tc.get_calendar_names()[:5]['XPHS','FWB','CFE','CMES','XSGO']Get a calendar withget_calendar:>>>xnys=tc.get_calendar("XNYS")Working with sessions:>>>xnys.is_session(pd.Timestamp("2020-01-01"))False>>>xnys.next_open(pd.Timestamp("2020-01-01"))Timestamp('2020-01-02 14:31:00+0000',tz='UTC')>>>pd.Timestamp("2020-01-01",tz=pytz.UTC)+xnys.dayTimestamp('2020-01-02 00:00:00+0000',tz='UTC')>>>xnys.previous_close(pd.Timestamp("2020-01-01"))Timestamp('2019-12-31 21:00:00+0000',tz='UTC')>>>xnys.sessions_in_range(>>>pd.Timestamp("2020-01-01",tz=pytz.UTC),>>>pd.Timestamp("2020-01-10",tz=pytz.UTC)>>>)DatetimeIndex(['2020-01-02 00:00:00+00:00','2020-01-03 00:00:00+00:00','2020-01-06 00:00:00+00:00','2020-01-07 00:00:00+00:00','2020-01-08 00:00:00+00:00','2020-01-09 00:00:00+00:00','2020-01-10 00:00:00+00:00'],dtype='datetime64[ns, UTC]',freq='C')>>>xnys.sessions_window(>>>pd.Timestamp("2020-01-02",tz=pytz.UTC),>>>7>>>)DatetimeIndex(['2020-01-02 00:00:00+00:00','2020-01-03 00:00:00+00:00','2020-01-06 00:00:00+00:00','2020-01-07 00:00:00+00:00','2020-01-08 00:00:00+00:00','2020-01-09 00:00:00+00:00','2020-01-10 00:00:00+00:00','2020-01-13 00:00:00+00:00'],dtype='datetime64[ns, UTC]',freq='C')NOTE: see theTradingCalendar classfor more advanced usage.Trading calendars also supports command line usage, printing a unix-cal like calendar indicating which days are trading sessions or holidays.tcalXNYS20202020
        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] 30tcalXNYS12020January 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 QuestionsWhy are open times one minute late?Due to its historical use in theZiplinebacktesting system,trading_calendarswill only indicate a market is open upon the completion of the first minute bar in a day. Zipline uses minute bars labeled with the end of the bar, e.g. 9:31AM for 9:30-9:31AM. As an example, on a regular trading day for NYSE:9:30:00 is treated as closed.9:30:01 is treated as closed.9:31:00 is the first time treated as open.16:00:00 is treated as open16:00:01 is treated as closedThis may change in the future.Calendar SupportExchangeISO 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/home/homepage.htmEuronext 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/exchanges/index.htmlTokyo Stock ExchangeXTKSJapan1.2https://www.jpx.co.jp/english/Austrialian Securities ExchangeXASXAustralia1.3https://www.asx.com.au/Bolsa de MadridXMADSpain1.3http://www.bolsamadrid.es/ing/aspx/Portada/Portada.aspxBorsa ItalianaXMILItaly1.3https://www.borsaitaliana.it/homepage/homepage.en.htmNew 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.9http://inter.bolsadesantiago.com/sitios/en/Paginas/home.aspxColombia Securities ExchangeXBOGColombia1.9https://www.bvc.com.co/nueva/index_en.htmlMexican 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/stockMarket/home.htmlStock 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/Note that exchange calendars are defined by theirISO-10383market identifier code.