Git Product home page Git Product logo

trading_calendars's Introduction

IMPORTANT NOTE

This package is currently unmaintained as the sponsor, quantopian, is going through corporate changes. As such there is a fork of this project that will receive more active maintenance, https://github.com/gerrymanoim/trading_calendars, and the actively developed and maintained alternative implimentation here: https://github.com/rsheftel/pandas_market_calendars . The process to merge these implementations will continue in those two respective repos.

trading_calendars

CI PyPI version Conda version

A Python library of exchange calendars, frequently used with Zipline.

Installation

$ pip install trading-calendars

Quick Start

import trading_calendars as tc
import pandas as pd
import pytz

Get all registered calendars with get_calendar_names:

>>> tc.get_calendar_names()[:5]
['XPHS', 'FWB', 'CFE', 'CMES', 'XSGO']

Get a calendar with get_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.day
Timestamp('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 the TradingCalendar class for more advanced usage.

Trading calendars also supports command line usage, printing a unix-cal like calendar indicating which days are trading sessions or holidays.

tcal XNYS 2020
                                        2020
        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] 30
tcal XNYS 1 2020
        January 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  31

Frequently Asked Questions

Why are open times one minute late?

Due to its historical use in the Zipline backtesting system, trading_calendars will 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 open
  • 16:00:01 is treated as closed

This may change in the future.

Calendar Support

Exchange ISO Code Country Version Added Exchange Website (English)
New York Stock Exchange XNYS USA 1.0 https://www.nyse.com/index
CBOE Futures XCBF USA 1.0 https://markets.cboe.com/us/futures/overview/
Chicago Mercantile Exchange CMES USA 1.0 https://www.cmegroup.com/
ICE US IEPA USA 1.0 https://www.theice.com/index
Toronto Stock Exchange XTSE Canada 1.0 https://www.tsx.com/
BMF Bovespa BVMF Brazil 1.0 http://www.b3.com.br/en_us/
London Stock Exchange XLON England 1.0 https://www.londonstockexchange.com/home/homepage.htm
Euronext Amsterdam XAMS Netherlands 1.2 https://www.euronext.com/en/regulation/amsterdam
Euronext Brussels XBRU Belgium 1.2 https://www.euronext.com/en/regulation/brussels
Euronext Lisbon XLIS Portugal 1.2 https://www.euronext.com/en/regulation/lisbon
Euronext Paris XPAR France 1.2 https://www.euronext.com/en/regulation/paris
Frankfurt Stock Exchange XFRA Germany 1.2 http://en.boerse-frankfurt.de/
SIX Swiss Exchange XSWX Switzerland 1.2 https://www.six-group.com/exchanges/index.html
Tokyo Stock Exchange XTKS Japan 1.2 https://www.jpx.co.jp/english/
Austrialian Securities Exchange XASX Australia 1.3 https://www.asx.com.au/
Bolsa de Madrid XMAD Spain 1.3 http://www.bolsamadrid.es/ing/aspx/Portada/Portada.aspx
Borsa Italiana XMIL Italy 1.3 https://www.borsaitaliana.it/homepage/homepage.en.htm
New Zealand Exchange XNZE New Zealand 1.3 https://www.nzx.com/
Wiener Borse XWBO Austria 1.3 https://www.wienerborse.at/en/
Hong Kong Stock Exchange XHKG Hong Kong 1.3 https://www.hkex.com.hk/?sc_lang=en
Copenhagen Stock Exchange XCSE Denmark 1.4 http://www.nasdaqomxnordic.com/
Helsinki Stock Exchange XHEL Finland 1.4 http://www.nasdaqomxnordic.com/
Stockholm Stock Exchange XSTO Sweden 1.4 http://www.nasdaqomxnordic.com/
Oslo Stock Exchange XOSL Norway 1.4 https://www.oslobors.no/ob_eng/
Irish Stock Exchange XDUB Ireland 1.4 http://www.ise.ie/
Bombay Stock Exchange XBOM India 1.5 https://www.bseindia.com
Singapore Exchange XSES Singapore 1.5 https://www.sgx.com
Shanghai Stock Exchange XSHG China 1.5 http://english.sse.com.cn
Korea Exchange XKRX South Korea 1.6 http://global.krx.co.kr
Iceland Stock Exchange XICE Iceland 1.7 http://www.nasdaqomxnordic.com/
Poland Stock Exchange XWAR Poland 1.9 http://www.gpw.pl
Santiago Stock Exchange XSGO Chile 1.9 http://inter.bolsadesantiago.com/sitios/en/Paginas/home.aspx
Colombia Securities Exchange XBOG Colombia 1.9 https://www.bvc.com.co/nueva/index_en.html
Mexican Stock Exchange XMEX Mexico 1.9 https://www.bmv.com.mx
Lima Stock Exchange XLIM Peru 1.9 https://www.bvl.com.pe
Prague Stock Exchange XPRA Czech Republic 1.9 https://www.pse.cz/en/
Budapest Stock Exchange XBUD Hungary 1.10 https://bse.hu/
Athens Stock Exchange ASEX Greece 1.10 http://www.helex.gr/
Istanbul Stock Exchange XIST Turkey 1.10 https://www.borsaistanbul.com/en/
Johannesburg Stock Exchange XJSE South Africa 1.10 https://www.jse.co.za/z
Malaysia Stock Exchange XKLS Malaysia 1.11 http://www.bursamalaysia.com/market/
Moscow Exchange XMOS Russia 1.11 https://www.moex.com/en/
Philippine Stock Exchange XPHS Philippines 1.11 https://www.pse.com.ph/stockMarket/home.html
Stock Exchange of Thailand XBKK Thailand 1.11 https://www.set.or.th/set/mainpage.do?language=en&country=US
Indonesia Stock Exchange XIDX Indonesia 1.11 https://www.idx.co.id/
Taiwan Stock Exchange Corp. XTAI Taiwan 1.11 https://www.twse.com.tw/en/
Buenos Aires Stock Exchange XBUE Argentina 1.11 https://www.bcba.sba.com.ar/
Pakistan Stock Exchange XKAR Pakistan 1.11 https://www.psx.com.pk/

Note that exchange calendars are defined by their ISO-10383 market identifier code.

trading_calendars's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trading_calendars's Issues

Exclude business day every week from the calendar

Hello, I'm trying to exclude a business day, any week, from a trading calendar.

Lets say I don't want to trade on any Friday, what I'm doing is changing the weekmask:

class CustomCalendar(IEPAExchangeCalendar):
    def __init__(self):
        super().__init__()

    @property
    def weekmask(self):
       return '111000'

custom_calendar = CustomCalendar()

but I'm getting:

ValueError: Special dates [Timestamp('1992-07-03 17:00:00+0000', tz='UTC'), ..., ...] are not trading days.

What is the best way to exclude business day every week?

Half day in Brazilian Stock Exchange

In the Brazilian calendar, Ash Wednesday is a half day, starting trading at 1pm. [1]

I noticed it's already implemented, but with it's currently commented and have a TODO tag. [2]

Judging by the same feature being implemented here, I guess the code can now be commented out, right?

Add trading_calendars to Quantopian conda channel

Hello, I am working on building a conda package for our library, and it uses trading_calendars. I'm having a hard time building my own version of the conda package for trading_calendars due to some odd dependency issues. Do you have any plans to add this project to Quantopian's conda channel? I'm hoping that you'll be able to avoid some of the issues I was running into and that I'll just be able to pull your package when it's on there.

Create a version of prevous_session_label that takes any date, not just sessions

previous_session_label requires that the date you pass actually be a session.

We should have an equivalent that takes any date and a calendar and passes back the session occurring prior to that date. Vague pseudo-code:

def last_valid_session(dt, exch='NYSE'):    
    cal = tc.get_calendar(exch)
    if cal.is_session(date):
        return cal.previous_session_label(dt)
    else:
        while not cal.is_session(dt):
            dt = dt-1
        return dt

CME calendar - products have different open/close ranges

In line with the comment in the CME calendar code, CME products sometimes have their own unique hours. Eg,

Is there a pattern for creating instrument specific calendars?

Please Fix XSHG 2020 holidays according to Chinese market calendar

According to the news, the original Spring Festival holiday is until January 30, 2020 (the sixth day), and the normal opening trading time is January 31, 2020 (the seventh day). Today, the regulatory level issued a notice that the stock and futures exchanges were closed on January 31, and the market opened as usual on February 3. The A-share market opening time is delayed by 1 day.

below codes is my Revise๏ผŒthe business logc is ok after adding a date as '2020-01-31' to XSHG array:
df = exchange_calendar_xshg.precomputed_shanghai_holidays
exchange_calendar_xshg.precomputed_shanghai_holidays = df.insert(0, pd.Timestamp(2020, 1, 31))
trading_calendar = get_calendar("XSHG")

the original code can be found from: https://github.com/quantopian/trading_calendars/blob/master/trading_calendars/exchange_calendar_xshg.py

NYSE Calendar differences prior to 1990

I see that the earliest starting date for the NYSE (XNYS) calendar is 1990-01-01 and from that date onwards the trading_calendars and pandas_market_calendars implementation are the same. But prior to that date there are many changes in the holiday calendar that pcal has that trading_calendars does not. If you are OK, I would suggest bringing over the pre-1990 holidays.

These holidays were added by @pldrouin in rsheftel/pandas_market_calendars#30. He was nice enough to upload a csv of all the holidays in the /tests/data/nyse_all_full_day_holidays_since_1928.csv and the results can be verified here: http://s3.amazonaws.com/armstrongeconomics-wp/2013/07/NYSE-Closings.pdf

Example:

trading_calendars:

from .us_holidays import (
    USNewYearsDay,
    USMartinLutherKingJrAfter1998,
    USMemorialDay,
    USIndependenceDay,
    Christmas,
    MonTuesThursBeforeIndependenceDay,
    FridayAfterIndependenceDayExcept2013and2019,
    USBlackFridayBefore1993,
    USBlackFridayInOrAfter1993,
    September11Closings,
    HurricaneSandyClosings,
    HurricaneGloriaClosing,
    NewYorkBlackout,
    PresidentialElectionDays,
    USNationalDaysofMourning,
    ChristmasEveBefore1993,
    ChristmasEveInOrAfter1993,
)

pandas_market_calendars

def regular_holidays(self):
       return AbstractHolidayCalendar(rules=[
           USNewYearsDay,
           USMartinLutherKingJrAfter1998,
           USLincolnsBirthDayBefore1954,
           USWashingtonsBirthDayBefore1964,
           USWashingtonsBirthDay1964to1970,
           USPresidentsDay,
           GoodFriday,
           USMemorialDayBefore1964,
           USMemorialDay1964to1969,
           USMemorialDay,
           USIndependenceDayBefore1954,
           USIndependenceDay,
           USLaborDay,
           USThanksgivingDayBefore1939,
           USThanksgivingDay1939to1941,
           USThanksgivingDay,
           USElectionDay1848to1967,
           USElectionDay1968to1980,
           USVeteransDay1934to1953,
           USColumbusDayBefore1954,
           ChristmasBefore1954,
           Christmas,
       ])

Is it possible to make a break in a calendar?

Hi,

Currently Im trying to make a own custom calendar, which needs to have multiple break in a single trading day.

So far as I drilled the source code, seems the current calendar implementation dont support a break during a single trading day, as each day can only have a record in the 'schedule' variable with a single 'market_open' and 'market_close'.

So may I ask if there is any idea on how to implement this? or any other approaches I can do?

"TypeError: data is already tz-aware UTC" in get_calendar()

from trading_calendars import get_calendar
get_calendar('CME')

Raises TypeError: data is already tz-aware UTC, unable to set specified tz: UTC.

This is a result of this issue in pandas where 'UTC' and pytz.UTC are not considered equal (I'm seeing this in pandas version 0.24.0).

I believe the fix would be to change the return in trading_calendars.trading_calendar.scheduled_special_times():

return pd.Series(
        index=pd.DatetimeIndex(days, tz='UTC'),
        data=days_at_time(days, time, tz=tz),
)

to:

return pd.Series(
        index=pd.DatetimeIndex(days, tz=pytz.UTC),
        data=days_at_time(days, time, tz=tz),
)

(Basically, replace 'UTC' with pytz.UTC when creating the index.)

CMES miss regular holiday Memorial Day (i.e. 2020-05-25)

https://www.cmegroup.com/tools-information/holiday-calendar.html
Memorial Day seems not in CMES regular holidays. Can we fix it?

import trading_calendars as tc

def scheduled_special_times(calendar, start, end, time, tz):
    days = calendar.holidays(start, end)
    return pd.Series(
        index=pd.DatetimeIndex(days, tz=pytz.UTC),
        data=tc.trading_calendar.days_at_time(days, time, tz=tz),
)
tc.trading_calendar.scheduled_special_times = scheduled_special_times

cal_cme = tc.get_calendar('CMES')
schedule = cal_cme.schedule```

`schedule['2019-05-20':'2019-05-30']`
	market_open	market_close
2019-05-20 00:00:00+00:00	2019-05-19 22:01:00	2019-05-20 22:00:00
2019-05-21 00:00:00+00:00	2019-05-20 22:01:00	2019-05-21 22:00:00
2019-05-22 00:00:00+00:00	2019-05-21 22:01:00	2019-05-22 22:00:00
2019-05-23 00:00:00+00:00	2019-05-22 22:01:00	2019-05-23 22:00:00
2019-05-24 00:00:00+00:00	2019-05-23 22:01:00	2019-05-24 22:00:00
**2019-05-27 00:00:00+00:00	2019-05-26 22:01:00	2019-05-27 17:00:00**
2019-05-28 00:00:00+00:00	2019-05-27 22:01:00	2019-05-28 22:00:00
2019-05-29 00:00:00+00:00	2019-05-28 22:01:00	2019-05-29 22:00:00
2019-05-30 00:00:00+00:00	2019-05-29 22:01:00	2019-05-30 22:00:00



`schedule['2020-05-20':'2020-05-30']`

market_open	market_close
2020-05-20 00:00:00+00:00	2020-05-19 22:01:00	2020-05-20 22:00:00
2020-05-21 00:00:00+00:00	2020-05-20 22:01:00	2020-05-21 22:00:00
2020-05-22 00:00:00+00:00	2020-05-21 22:01:00	2020-05-22 22:00:00
**2020-05-25 00:00:00+00:00	2020-05-24 22:01:00	2020-05-25 17:00:00**
2020-05-26 00:00:00+00:00	2020-05-25 22:01:00	2020-05-26 22:00:00
2020-05-27 00:00:00+00:00	2020-05-26 22:01:00	2020-05-27 22:00:00
2020-05-28 00:00:00+00:00	2020-05-27 22:01:00	2020-05-28 22:00:00
2020-05-29 00:00:00+00:00	2020-05-28 22:01:00	2020-05-29 22:00:00




New release?

There have been some changes to this library that is not part of a release. Do you plan to make a new release soon?

Allow users to change start_default/end_default in trading_calendars

Related to the issue: quantopian/zipline#2700

As @richafrank mentioned on the issue linked above is the module-level variable start_default in trading_calendars\trading_calendar.py being '1990-01-01'.

In my opinion '1990-01-01' seems somewhat arbitrary. As far as my understanding goes, the only reason it is '1990-01-01' and not earlier is to avoid caches to take up too much memory.

Disadvantages of this approach:

  • The open-issue linked above
  • PrecomputedTradingCalendar uses its own start/end dates and some of them start earlier than '1990-01-01'
  • The cached data frame does not take that much memory anyway? (but I might be utterly wrong here)

Possible solutions off the top of my head:

  • Change 'start_default' to something much earlier
  • Add exchange specific start_default and end_default, this is consistent with how PrecomputedTradingCalendar behaves
  • Add a way for end-user to change start_default and end_default (e.g. store start_default and end_default in a mutable container than give access to end-user).

Python 3.8 incompatible

Python 3.8 test crash:

...
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/site-packages/nose/loader.py", line 417, in loadTestsFromName
    module = self.importer.importFromPath(
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/home/agil/.pyenv/trading_calendars/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/agil/trading_calendars/tests/test_xwbo_calendar.py", line 5, in <module>
    from .test_trading_calendar import ExchangeCalendarTestBase
  File "/home/agil/trading_calendars/tests/test_trading_calendar.py", line 33, in <module>
    from trading_calendars.errors import (
  File "/home/agil/trading_calendars/trading_calendars/__init__.py", line 16, in <module>
    from .trading_calendar import TradingCalendar
  File "/home/agil/trading_calendars/trading_calendars/trading_calendar.py", line 86, in <module>
    class TradingCalendar(with_metaclass(ABCMeta)):
  File "/home/agil/trading_calendars/trading_calendars/trading_calendar.py", line 830, in TradingCalendar
    def minute_to_session_label(self, dt, direction="next"):
  File "/home/agil/trading_calendars/trading_calendars/utils/preprocess.py", line 115, in _decorator
    return _build_preprocessed_function(
  File "/home/agil/trading_calendars/trading_calendars/utils/preprocess.py", line 252, in _build_preprocessed_function
    new_func.__code__ = CodeType(*map(getitem(args), _code_argorder))
TypeError: an integer is required (got type bytes)

[error] 100.00% nose.failure.Failure.runTest: 0.0001s
----------------------------------------------------------------------
Ran 52 tests in 0.024s

FAILED (errors=52)

CodeType was updated and now require a new argument posonlyargcount:

Minor failures in all calendar tests

As the title suggests, there is always a minor failures in all calendar test tests\test_XXXX_calendar.py for all exchange code XXXX

For example, running nosetests tests\test_xnys_calendar.py yields

[success] 49.38% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minute_to_session_label: 7.4921s
[success] 12.18% tests.test_xnys_calendar.XNYSCalendarTestCase.test_open_and_close_for_session: 1.8481s
[success] 11.56% tests.test_xnys_calendar.XNYSCalendarTestCase.test_next_prev_open_close: 1.7531s
[success] 11.36% tests.test_xnys_calendar.XNYSCalendarTestCase.test_next_prev_minute: 1.7233s
[success] 3.56% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minute_index_to_session_labels_0: 0.5395s
[success] 3.05% tests.test_xnys_calendar.XNYSCalendarTestCase.test_next_prev_session: 0.4620s
[success] 2.26% tests.test_xnys_calendar.XNYSCalendarTestCase.test_sanity_check_session_lengths: 0.3434s
[success] 1.79% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minute_index_to_session_labels_2: 0.2719s
[success] 1.78% tests.test_xnys_calendar.XNYSCalendarTestCase.test_is_open_on_minute: 0.2705s
[success] 1.73% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minute_index_to_session_labels_1: 0.2623s
[success] 0.94% tests.test_xnys_calendar.XNYSCalendarTestCase.test_start_end: 0.1422s
[fail] 0.12% tests.test_xnys_calendar.XNYSCalendarTestCase.test_session_closes_in_range: 0.0187s
[success] 0.06% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minutes_for_period: 0.0096s
[fail] 0.05% tests.test_xnys_calendar.XNYSCalendarTestCase.test_session_opens_in_range: 0.0069s
[success] 0.04% tests.test_xnys_calendar.XNYSCalendarTestCase.test_minutes_in_range: 0.0054s

Ran 27 tests in 15.773s

FAILED (failures=2)

Add tests_require to setup.py

This is a follow up to #113

Setting up the required packages to run the tests for the first time was a hassle for me. It's probably a good idea to add test dependencies to setup.py to make it easier for us to contribute.

Dependencies:
nose
nose-ignore-docstring
nose-timer
nose-parameterized

Warning when creating a new calendar

When creating a new calendar, a FutureWarning is generated. pandas version used is 0.24.1.

us_calendar = get_calendar('XNYS')

gives:

/usr/lib/python3.7/site-packages/pandas/core/sorting.py:257: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
To accept the future behavior, pass 'dtype=object'.
To keep the old behavior, pass 'dtype="datetime64[ns]"'.
items = np.asanyarray(items)
/usr/lib/python3.7/site-packages/pandas/core/sorting.py:257: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
To accept the future behavior, pass 'dtype=object'.
To keep the old behavior, pass 'dtype="datetime64[ns]"'.
items = np.asanyarray(items)

Slow load time for XTKS

I noticed that the load time for most all calendars are around 1.5 seconds, except the XTKS calendar which takes 12.2 seconds to load. Is there any particular reason for that?

This is the code and results I used:

from datetime import datetime
import trading_calendars as tc

def load_times():
    for name in tc.calendar_utils._default_calendar_factories:
        print(name, end='')
        start = datetime.now()
        _ = mcal.get_calendar(name)
        end = datetime.now()
        print(f': run time is {end - start}')
ASEX: run time is 0:00:01.462395
BVMF: run time is 0:00:01.608703
CMES: run time is 0:00:01.247221
IEPA: run time is 0:00:01.221055
XAMS: run time is 0:00:01.239995
XASX: run time is 0:00:01.405535
XBKK: run time is 0:00:01.483120
XBOG: run time is 0:00:01.902455
XBOM: run time is 0:00:00.635975
XBRU: run time is 0:00:01.259231
XBUD: run time is 0:00:01.545929
XBUE: run time is 0:00:01.647241
XCBF: run time is 0:00:01.397777
XCSE: run time is 0:00:01.523843
XDUB: run time is 0:00:01.301222
XFRA: run time is 0:00:01.396143
XHEL: run time is 0:00:01.423694
XHKG: run time is 0:00:01.365153
XICE: run time is 0:00:01.561660
XIDX: run time is 0:00:01.219812
XIST: run time is 0:00:01.244760
XJSE: run time is 0:00:01.435470
XKAR: run time is 0:00:01.075075
XKLS: run time is 0:00:01.191726
XKRX: run time is 0:00:00.940299
XLIM: run time is 0:00:01.465012
XLIS: run time is 0:00:01.357335
XLON: run time is 0:00:01.407390
XMAD: run time is 0:00:01.282585
XMEX: run time is 0:00:01.377445
XMIL: run time is 0:00:01.336494
XMOS: run time is 0:00:01.307830
XNYS: run time is 0:00:01.408174
XNZE: run time is 0:00:01.423343
XOSL: run time is 0:00:01.464810
XPAR: run time is 0:00:01.283910
XPHS: run time is 0:00:01.333504
XPRA: run time is 0:00:01.456183
XSES: run time is 0:00:00.961805
XSGO: run time is 0:00:01.739328
XSHG: run time is 0:00:00.709314
XSTO: run time is 0:00:01.572027
XSWX: run time is 0:00:01.435308
XTAI: run time is 0:00:01.137340
XTKS: run time is 0:00:12.211477
XTSE: run time is 0:00:01.481504
XWAR: run time is 0:00:01.544426
XWBO: run time is 0:00:01.442748
us_futures: run time is 0:00:00.859409
24/7: run time is 0:00:01.463259
24/5: run time is 0:00:01.034509

Having Market Open or Close Time during the hour of Daylight Savings Change throws AmbiguousTimeError

At the moment, creating any custom calendar that has an open or close during the hour of Daylight Savings time changes will throw an AmbiguousTimeError:

from datetime import time
from pytz import timezone
from trading_calendars.exchange_calendar_cmes import CMESExchangeCalendar


class TestCal(CMESExchangeCalendar):
    
    name = 'TestCal'
    
    tz = timezone('America/Chicago')

    open_times = (
        (None, time(1, 1)),
    )
    
TestCal()
---------------------------------------------------------------------------
AmbiguousTimeError                        Traceback (most recent call last)
<ipython-input-7-746e7f5c6750> in <module>
     14     )
     15 
---> 16 TestCal()

~\.conda\envs\proj_ortz\lib\site-packages\trading_calendars\trading_calendar.py in __init__(self, start, end)
    109 
    110         # `DatetimeIndex`s of standard opens/closes for each day.
--> 111         self._opens = _group_times(
    112             _all_days,
    113             self.open_times,

~\.conda\envs\proj_ortz\lib\site-packages\trading_calendars\trading_calendar.py in _group_times(all_days, times, tz, offset)
     68 
     69 def _group_times(all_days, times, tz, offset):
---> 70     elements = [
     71         days_at_time(
     72             selection(all_days, start, end),

~\.conda\envs\proj_ortz\lib\site-packages\trading_calendars\trading_calendar.py in <listcomp>(.0)
     69 def _group_times(all_days, times, tz, offset):
     70     elements = [
---> 71         days_at_time(
     72             selection(all_days, start, end),
     73             time,

~\.conda\envs\proj_ortz\lib\site-packages\trading_calendars\utils\pandas_utils.py in days_at_time(days, t, tz, day_offset)
     46         seconds=t.second,
     47     )
---> 48     return (days + delta).tz_localize(tz).tz_convert(UTC)
     49 
     50 

~\.conda\envs\proj_ortz\lib\site-packages\pandas\core\accessor.py in f(self, *args, **kwargs)
     97         def _create_delegator_method(name):
     98             def f(self, *args, **kwargs):
---> 99                 return self._delegate_method(name, *args, **kwargs)
    100 
    101             f.__name__ = name

~\.conda\envs\proj_ortz\lib\site-packages\pandas\core\indexes\datetimelike.py in _delegate_method(self, name, *args, **kwargs)
    903 
    904     def _delegate_method(self, name, *args, **kwargs):
--> 905         result = operator.methodcaller(name, *args, **kwargs)(self._data)
    906         if name not in self._raw_methods:
    907             result = Index(result, name=self.name)

~\.conda\envs\proj_ortz\lib\site-packages\pandas\core\arrays\datetimes.py in tz_localize(self, tz, ambiguous, nonexistent)
    983             # Convert to UTC
    984 
--> 985             new_dates = conversion.tz_localize_to_utc(
    986                 self.asi8, tz, ambiguous=ambiguous, nonexistent=nonexistent
    987             )

pandas\_libs\tslibs\tzconversion.pyx in pandas._libs.tslibs.tzconversion.tz_localize_to_utc()

AmbiguousTimeError: Cannot infer dst time from 1990-10-28 01:01:00, try using the 'ambiguous' argument

Adding tests to setup.py

I've found a few issues/improvements to the setup.py and PyPI:

  • Libraries.io doesn't list the package's dependencies, which means that PyPI doesn't fetch or process the list of dependencies either.
  • Unit tests and test framework are not referenced in the setup.py, using test_suite. [1]
  • Possibly adding the test/resources as package_data or similar, to signal that is a data folder.

sessions_window with high negative count cycles back indices

Hi,

I've been experimenting with sessions_window and I found that when the count parameter is negative and greater than the total number of days in the trading calendar, the result cycles back and returns the dates between the end date and till the exact overflow value.

Example:

from trading_calendars import get_calendar
market_calendar = get_calendar('XNYS')
end_date = '2019-02-27'
days_rqd = -8500
dates = market_calendar.sessions_window(end_date, days_rqd)
print(dates)

>>DatetimeIndex(['2016-07-12 00:00:00+00:00', '2016-07-13 00:00:00+00:00',
               '2016-07-14 00:00:00+00:00', '2016-07-15 00:00:00+00:00',
               '2016-07-18 00:00:00+00:00', '2016-07-19 00:00:00+00:00',
               '2016-07-20 00:00:00+00:00', '2016-07-21 00:00:00+00:00',
               '2016-07-22 00:00:00+00:00', '2016-07-25 00:00:00+00:00',
               ...
               '2019-02-13 00:00:00+00:00', '2019-02-14 00:00:00+00:00',
               '2019-02-15 00:00:00+00:00', '2019-02-19 00:00:00+00:00',
               '2019-02-20 00:00:00+00:00', '2019-02-21 00:00:00+00:00',
               '2019-02-22 00:00:00+00:00', '2019-02-25 00:00:00+00:00',
               '2019-02-26 00:00:00+00:00', '2019-02-27 00:00:00+00:00'],
              dtype='datetime64[ns, UTC]', length=662, freq='C')

print(len(dates))
>> 662

Upon checking the code for this in trading_calendar.py, start_idx is 7345 for the calendar I've chosen in the above example and end_idx becomes 7345 + (-8500) = -1155 and thus the output will be all_sessions[-1155: 7345 + 1] which is not what I expected. The total length of all_sessions is 7839 - so, converting the negative indices to normal indices, we get all_sessions[7839-1155: 7345 + 1] which is all_sessions[6684: 7345 + 1] which explains why I got 662 dates.

What I expect is all_sessions[0: 7345 + 1] which can be obtained by adding end_idx = max(0, end_idx) right before the indexing on all_sessions (created a pull request for the same - #125). I'm not yet sure if this affects any other functionality, but tl;dr version is, when we query dates where the lookback/negative count is greater than the length of historical dates, it should just return all the available dates till the end date instead of looping back on the indices.

XLIS: Wrong or ambiguous early close time for XLIS.

This applies to version 2020.1 and possibly earlier versions.

The returned early close time of 14:05 for XLIS, e.g. on 2020-12-24, is incorrect or at least ambiguous. It is incorrect if the time is meant to be in the exchange's time zone -- which is WET -- since the time is correct only in CET; cf. https://www.euronext.com/en/trade/trading-hours-holidays which lists the early close time as 14:05 CET for several Euronext exchanges that are located in both CET and WET (Lisbon) time zones. It is ambiguous if the user is expected to interpret the time in CET since there's no link to that time zone from the XLIS calendar.

Syntax error on python 3.5.2 and python 2.7

Hello,
I ran python etc/lunisolar lunar-ecliptic-longitude --verbose --start '2005-01-01' with python 3.5.2 and 2.7 in virtual envs. Its throwing and syntax error. It is running fine with 3.6.6 though.

  File "etc/lunisolar", line 186
    return np.datetime64(f'{year}-{month:02d}-{day:02d}', 'D')

My default python is 3.6.6, but I had to install Python 3.5 because I could not get Zipline running on 3.6. Script etc/lunisolar and Zipline are in incompatible environments.

Thanks

Method differences between trading_calendars and pandas_market_calendars

re rsheftel/pandas_market_calendars#41

import pandas as pd
import trading_calendars as tc
import pandas_market_calendars as pmc

def method_comparison(tc_methods, pmc_methods):
  # must be an easier way to do this
  tc_col = tc_methods.copy()
  pmc_methods_set = set(pmc_methods)

  pmc_col, pmc_only = [], []

  for method in tc_col:
    if method in pmc_methods_set:
      pmc_col.append(method)
    else:
      pmc_col.append(None)
  
  pmc_only = list(pmc_methods_set - set(pmc_col))
  pmc_col.extend(pmc_only)
  tc_col.extend([None for _ in pmc_only])
  return pd.DataFrame(
    {'trading_calendars': tc_col, 'pandas_market_calendars': pmc_col}
  )

Calendar level differences

nyse_tc = tc.get_calendar("NYSE")
nyse_pmc = pmc.get_calendar("NYSE")
calendar_method_comparison = method_comparison(dir(nyse_tc), dir(nyse_pmc))
trading_calendars pandas_market_calendars
0 abstractmethods abstractmethods
1 class class
2 delattr delattr
3 dict dict
4 dir dir
5 doc doc
6 eq eq
7 format format
8 ge ge
9 getattribute getattribute
10 gt gt
11 hash hash
12 init init
13 init_subclass init_subclass
14 le le
15 lt lt
16 module module
17 ne ne
18 new new
19 reduce reduce
20 reduce_ex reduce_ex
21 repr repr
22 setattr setattr
23 sizeof sizeof
24 str str
25 subclasshook subclasshook
26 weakref weakref
27 _abc_cache _abc_cache
28 _abc_negative_cache _abc_negative_cache
29 _abc_negative_cache_version _abc_negative_cache_version
30 _abc_registry _abc_registry
31 _calculate_special_closes _calculate_special_closes
32 _calculate_special_opens _calculate_special_opens
33 _closes
34 _early_closes
35 _late_opens
36 _minute_to_session_label_cache
37 _minutes_per_session
38 _opens
39 _special_dates _special_dates
40 _trading_minutes_nanos
41 adhoc_holidays adhoc_holidays
42 all_minutes
43 all_sessions
44 close_offset close_offset
45 close_times
46 closes
47 day
48 early_closes early_closes
49 execution_minutes_for_session
50 execution_minutes_for_sessions_in_range
51 execution_time_from_close
52 execution_time_from_open
53 first_session
54 first_trading_session
55 is_open_on_minute
56 is_session
57 last_session
58 last_trading_session
59 late_opens
60 market_closes_nanos
61 market_opens_nanos
62 minute_index_to_session_labels
63 minute_to_session_label
64 minutes_count_for_sessions_in_range
65 minutes_for_session
66 minutes_for_sessions_in_range
67 minutes_in_range
68 minutes_window
69 name name
70 next_close
71 next_minute
72 next_open
73 next_session_label
74 open_and_close_for_session
75 open_offset open_offset
76 open_times
77 opens
78 previous_close
79 previous_minute
80 previous_open
81 previous_session_label
82 regular_early_close regular_early_close
83 regular_holidays regular_holidays
84 schedule schedule
85 session_close
86 session_closes_in_range
87 session_distance
88 session_open
89 session_opens_in_range
90 sessions_in_range
91 sessions_window
92 special_closes special_closes
93 special_closes_adhoc special_closes_adhoc
94 special_opens special_opens
95 special_opens_adhoc special_opens_adhoc
96 tz tz
97 weekmask weekmask
98 holidays
99 open_time
100 factory
101 calendar_names
102 break_end
103 _close_time
104 _regmeta_classes
105 aliases
106 _get_current_time
107 close_time_default
108 break_start
109 valid_days
110 is_open_now
111 open_time_default
112 _regmeta_instance_factory
113 close_time
114 open_at_time
115 _open_time
116 _holidays
117 _regmeta_class_factory
118 _regmeta_class_registry

Module level differences

def clean_methods(l):
  return [m for m in l if "exchange_" not in m]

tc_methods = clean_methods(dir(tc))
pmc_methods = clean_methods(dir(pmc))
module_method_comparison = method_comparison(tc_methods, pmc_methods)
trading_calendars pandas_market_calendars
0 TradingCalendar
1 all all
2 builtins builtins
3 cached cached
4 doc doc
5 file file
6 loader loader
7 name name
8 package package
9 path path
10 spec spec
11 version version
12 _version
13 always_open
14 calendar_helpers
15 calendar_utils calendar_utils
16 clear_calendars
17 common_holidays
18 deregister_calendar
19 errors
20 get_calendar get_calendar
21 precomputed_trading_calendar
22 register_calendar
23 register_calendar_alias
24 register_calendar_type
25 resolve_alias
26 trading_calendar
27 us_futures_calendar
28 us_holidays
29 utils
30 weekday_calendar
31 xbkk_holidays
32 xkls_holidays
33 xtks_holidays
34 calendar_registry
35 holidays_oz
36 MarketCalendar
37 holidays_us
38 holidays_uk
39 convert_freq
40 merge_schedules
41 get_calendar_names get_calendar_names
42 holidays_cn
43 date_range
44 jpx_equinox
45 market_calendar
46 class_registry
47 holidays_jp
48 pkg_resources

Data Differences Between `trading_calendars` and `pandas_market_calendars`

re rsheftel/pandas_market_calendars#41

Summary status

Extras not covered by diff below:

  • Pre 1990 NYSE holidays

Details

code generating the table below

from collections import namedtuple 

import pandas_market_calendars as pmc
import trading_calendars as tc

# todo port this back to trading calendars
def get_tc_calendar_names():
  return list(tc.calendar_utils._default_calendar_factories.keys())+list(tc.calendar_utils._default_calendar_aliases.keys())

tc.get_calendar_names = get_tc_calendar_names
# end todo

pmc_calendars = set(pmc.get_calendar_names())
tc_calendars = set(tc.get_calendar_names())
tc_to_pmc_mapping = {
    'XASX': 'ASX',
    'XHKG': 'HKEX',
    'XTKS': 'JPX',
    'XOSL': 'OSE',
    'XSWX': 'SIX',
    'XSHG': 'SSE',
}

in_both = (tc_calendars & pmc_calendars) | set(tc_to_pmc_mapping.keys())

CompareResult = namedtuple("Result", ["only_tc", "only_pmc"])

def compare_calendars(cal: str):
  tc_cal = tc.get_calendar(cal).all_sessions
  pmc_cal_name = tc_to_pmc_mapping.get(cal, cal)
  pmc_cal = pmc.get_calendar(pmc_cal_name).valid_days(min(tc_cal), max(tc_cal))
  if not (tc_cal ^ pmc_cal).empty:
    return CompareResult

out = {}
for cal in in_both:
  diff = compare_calendars(cal)
  if diff:
    out[cal] = diff

# everything below this is markdown formatting
out_str = []
for cal, result in out.items():
  out_str.append(f"## {cal} \n")
  out_str.append("Trading Days only in `trading_calendars` \n")
  out_str.extend([f"- {item} \n" for item in result.only_tc])
  out_str.append("\n")
  out_str.append("Trading Days only in `pandas_market_calendars` \n")
  out_str.extend([f"- {item} \n" for item in result.only_pmc])
  out_str.append("\n")
md = "".join(out_str); print(md)

XHKG

Trading Days only in trading_calendars

  • 1990-06-18 00:00:00+00:00
  • 1990-08-27 00:00:00+00:00
  • 1991-02-14 00:00:00+00:00
  • 1991-06-18 00:00:00+00:00
  • 1991-08-26 00:00:00+00:00
  • 1992-06-15 00:00:00+00:00
  • 1992-07-22 00:00:00+00:00
  • 1992-08-31 00:00:00+00:00
  • 1993-06-14 00:00:00+00:00
  • 1993-08-30 00:00:00+00:00
  • 1993-09-17 00:00:00+00:00
  • 1994-06-14 00:00:00+00:00
  • 1994-08-29 00:00:00+00:00
  • 1995-06-19 00:00:00+00:00
  • 1995-08-28 00:00:00+00:00
  • 1996-06-17 00:00:00+00:00
  • 1996-08-26 00:00:00+00:00
  • 1997-02-06 00:00:00+00:00
  • 1997-06-30 00:00:00+00:00
  • 1997-07-02 00:00:00+00:00
  • 1997-08-18 00:00:00+00:00
  • 1997-10-02 00:00:00+00:00
  • 1998-08-17 00:00:00+00:00
  • 1998-10-02 00:00:00+00:00
  • 1999-09-16 00:00:00+00:00
  • 1999-12-31 00:00:00+00:00
  • 2001-07-06 00:00:00+00:00
  • 2001-07-25 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 1990-05-01 00:00:00+00:00
  • 1990-05-02 00:00:00+00:00
  • 1990-07-02 00:00:00+00:00
  • 1990-10-01 00:00:00+00:00
  • 1991-05-01 00:00:00+00:00
  • 1991-05-21 00:00:00+00:00
  • 1991-07-01 00:00:00+00:00
  • 1991-10-01 00:00:00+00:00
  • 1992-05-01 00:00:00+00:00
  • 1992-05-11 00:00:00+00:00
  • 1992-07-01 00:00:00+00:00
  • 1992-10-01 00:00:00+00:00
  • 1993-05-28 00:00:00+00:00
  • 1993-07-01 00:00:00+00:00
  • 1994-05-02 00:00:00+00:00
  • 1994-05-18 00:00:00+00:00
  • 1994-07-01 00:00:00+00:00
  • 1995-05-01 00:00:00+00:00
  • 1995-05-08 00:00:00+00:00
  • 1995-10-02 00:00:00+00:00
  • 1996-05-01 00:00:00+00:00
  • 1996-05-24 00:00:00+00:00
  • 1996-07-01 00:00:00+00:00
  • 1996-10-01 00:00:00+00:00
  • 1997-05-01 00:00:00+00:00
  • 1997-05-14 00:00:00+00:00
  • 1998-05-01 00:00:00+00:00
  • 1998-05-04 00:00:00+00:00
  • 2021-04-06 00:00:00+00:00

CFE

Trading Days only in trading_calendars

Trading Days only in pandas_market_calendars

  • 1994-04-27 00:00:00+00:00
  • 2004-06-11 00:00:00+00:00
  • 2007-01-02 00:00:00+00:00
  • 2012-10-29 00:00:00+00:00
  • 2012-10-30 00:00:00+00:00
  • 2018-12-05 00:00:00+00:00

XSWX

Trading Days only in trading_calendars

  • 1994-12-30 00:00:00+00:00
  • 1995-12-29 00:00:00+00:00
  • 2000-12-29 00:00:00+00:00
  • 2005-12-30 00:00:00+00:00
  • 2006-12-29 00:00:00+00:00
  • 2011-12-30 00:00:00+00:00
  • 2016-12-30 00:00:00+00:00
  • 2017-12-29 00:00:00+00:00

Trading Days only in pandas_market_calendars

LSE

Trading Days only in trading_calendars

  • 1995-05-08 00:00:00+00:00
  • 1999-12-31 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 1995-05-01 00:00:00+00:00

XSHG

Trading Days only in trading_calendars

  • 2020-01-31 00:00:00+00:00
  • 2022-01-31 00:00:00+00:00
  • 2022-04-04 00:00:00+00:00
  • 2022-05-02 00:00:00+00:00
  • 2022-09-12 00:00:00+00:00
  • 2022-10-06 00:00:00+00:00
  • 2022-10-07 00:00:00+00:00
  • 2023-06-23 00:00:00+00:00
  • 2023-10-06 00:00:00+00:00
  • 2024-02-09 00:00:00+00:00
  • 2024-04-05 00:00:00+00:00
  • 2024-09-16 00:00:00+00:00
  • 2024-10-07 00:00:00+00:00
  • 2025-01-28 00:00:00+00:00
  • 2025-05-02 00:00:00+00:00
  • 2025-06-02 00:00:00+00:00
  • 2025-10-06 00:00:00+00:00
  • 2025-10-07 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 2020-10-08 00:00:00+00:00

XASX

Trading Days only in trading_calendars

  • 1993-01-27 00:00:00+00:00
  • 1994-01-27 00:00:00+00:00
  • 1995-01-27 00:00:00+00:00
  • 1996-01-29 00:00:00+00:00
  • 1998-01-27 00:00:00+00:00
  • 1999-01-27 00:00:00+00:00
  • 2000-01-27 00:00:00+00:00
  • 2001-01-29 00:00:00+00:00
  • 2004-01-27 00:00:00+00:00
  • 2005-01-27 00:00:00+00:00
  • 2006-01-27 00:00:00+00:00
  • 2007-01-29 00:00:00+00:00
  • 2009-01-27 00:00:00+00:00
  • 2010-01-27 00:00:00+00:00
  • 2011-01-27 00:00:00+00:00
  • 2012-01-27 00:00:00+00:00
  • 2015-01-27 00:00:00+00:00
  • 2016-01-27 00:00:00+00:00
  • 2017-01-27 00:00:00+00:00
  • 2018-01-29 00:00:00+00:00
  • 2021-01-27 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 1990-12-31 00:00:00+00:00
  • 1994-01-26 00:00:00+00:00
  • 1994-12-27 00:00:00+00:00
  • 1995-01-26 00:00:00+00:00
  • 1996-01-26 00:00:00+00:00
  • 1998-01-26 00:00:00+00:00
  • 1999-01-26 00:00:00+00:00
  • 1999-12-31 00:00:00+00:00
  • 2000-01-26 00:00:00+00:00
  • 2001-01-26 00:00:00+00:00
  • 2004-01-26 00:00:00+00:00
  • 2005-01-26 00:00:00+00:00
  • 2005-12-27 00:00:00+00:00
  • 2006-01-26 00:00:00+00:00
  • 2007-01-26 00:00:00+00:00
  • 2009-01-26 00:00:00+00:00
  • 2010-01-26 00:00:00+00:00
  • 2010-04-26 00:00:00+00:00
  • 2011-01-26 00:00:00+00:00
  • 2011-04-26 00:00:00+00:00
  • 2011-12-27 00:00:00+00:00
  • 2012-01-26 00:00:00+00:00
  • 2015-01-26 00:00:00+00:00
  • 2016-01-26 00:00:00+00:00
  • 2016-12-27 00:00:00+00:00
  • 2017-01-26 00:00:00+00:00
  • 2018-01-26 00:00:00+00:00
  • 2021-01-26 00:00:00+00:00

TSX

Trading Days only in trading_calendars

  • 1993-12-24 00:00:00+00:00
  • 1999-12-24 00:00:00+00:00
  • 2004-12-24 00:00:00+00:00
  • 2010-12-24 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 2001-09-11 00:00:00+00:00
  • 2001-09-12 00:00:00+00:00

BMF

Trading Days only in trading_calendars

  • 1997-07-09 00:00:00+00:00
  • 2020-07-09 00:00:00+00:00

Trading Days only in pandas_market_calendars

  • 1995-12-29 00:00:00+00:00
  • 2000-12-29 00:00:00+00:00
  • 2006-12-29 00:00:00+00:00
  • 2014-06-12 00:00:00+00:00
  • 2017-12-29 00:00:00+00:00

Remove footnote

In the README.md, there's a footnote:

Calendars marked with an asterisk (*) have not yet been released.

But no line was marked, probably meaning that all calendars are already released, right?

Should we add more calendars or remove the footnote?

Need help on how to use the trading calender

Hello Team,

I am new to python and wanted to know how to use the trading XBOM calendar, for example

today = datetime.date.today() i.e. 25th Dec 2019. how to check this date is in holiday list or not with condition

And also given time in market hours are not can someone help with sample code

LSE special holidays

The LSE (XLON) exchange has special holidays as described by @matthew-tomlinson in rsheftel/pandas_market_calendars#84. These are implemented in pandas_market_calendars and need to be brought to trading_calendars. In pcal they are implemented in the https://github.com/rsheftel/pandas_market_calendars/blob/master/pandas_market_calendars/holidays_uk.py module here. There are tests in the test_exchange_calendar_lse.py that can be used to confirm.

# Early May bank holiday has two exceptions based on the 50th and 75th anniversary of VE-Day
# 1995-05-01 Early May bank holiday removed for VE-day 50th anniversary
# 2020-05-04 Early May bank holiday removed for VE-day 75th anniversary

# Early May bank holiday pre-1995
MayBank_pre_1995 = Holiday(
    "Early May Bank Holiday",
    month=5,
    offset=DateOffset(weekday=MO(1)),
    day=1,
    end_date=Timestamp('1994-12-31'),
)

# Early May bank holiday post-1995 and pre-2020
MayBank_post_1995_pre_2020 = Holiday(
    "Early May Bank Holiday",
    month=5,
    offset=DateOffset(weekday=MO(1)),
    day=1,
    start_date=Timestamp('1996-01-01'),
    end_date=Timestamp('2019-12-31'),
)

# Early May bank holiday post 2020
MayBank_post_2020 = Holiday(
    "Early May Bank Holiday",
    month=5,
    offset=DateOffset(weekday=MO(1)),
    day=1,
    start_date=Timestamp('2021-01-01')
)

# Spring bank holiday has two exceptions based on the Golden & Diamond Jubilee
# 2002-05-27 Spring bank holiday removed for Golden Jubilee
# 2012-05-28 Spring bank holiday removed for Diamond Jubilee

# Spring bank holiday
SpringBank_pre_2002 = Holiday(
    "Spring Bank Holiday",
    month=5,
    day=31,
    offset=DateOffset(weekday=MO(-1)),
    end_date=Timestamp('2001-12-31'),
)

SpringBank_post_2002_pre_2012 = Holiday(
    "Spring Bank Holiday",
    month=5,
    day=31,
    offset=DateOffset(weekday=MO(-1)),
    start_date=Timestamp('2003-01-01'),
    end_date=Timestamp('2011-12-31'),
)

SpringBank_post_2012 = Holiday(
    "Spring Bank Holiday",
    month=5,
    day=31,
    offset=DateOffset(weekday=MO(-1)),
    start_date=Timestamp('2013-01-01'),
)

Need help for creating holiday calendar for India

Here's the list of holidays for NSE. Problem is, there are some holidays which follow Gregorian calendar (eg. Republic day, Independence day, Mahatama Gandhi Jayanti etc), some holidays which follow Hindu Calendars (eg. Diwali, Holi) and few holidays follow Islamic calendar (Ramzan, Eid)

How to deal with this. One option I could think is work backwards from data. Take the data of a stock which has traded longest and then figure out holidays based on it.

I am looking at hk branch but have not been able to figure out any solution yet.

Any help on this will be appreciated.

Thanks

end_default trading days limited to one year out

I didn't get a chance to dig into why this is happening, but thought I'd mention it. Hopefully this isn't predicting the end of the world! pd.date_range() responds as expected for these inputs, so I think it's a local issue not upstream, but didn't dig too far.

I have hope there is plenty of time for us to fix the future!

from trading_calendars import get_calendar

# US Stock Exchanges (includes NASDAQ)
XNYS_calendar = get_calendar('XNYS')

print("Last month is 2019-10:")
print( XNYS_calendar.sessions_in_range("2019-10", "2020") )

print("2019-11 and beyond:")
print( XNYS_calendar.sessions_in_range("2019-11", "2020") )

Results:

Last month is 2019-10:
DatetimeIndex(['2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04',
               '2019-10-07', '2019-10-08', '2019-10-09', '2019-10-10',
               '2019-10-11', '2019-10-14', '2019-10-15', '2019-10-16',
               '2019-10-17', '2019-10-18', '2019-10-21', '2019-10-22',
               '2019-10-23', '2019-10-24', '2019-10-25', '2019-10-28',
               '2019-10-29', '2019-10-30'],
              dtype='datetime64[ns, UTC]', freq='C')

2019-11 and beyond:
DatetimeIndex([], dtype='datetime64[ns, UTC]', freq='C')

Is coveralls really used?

In .travis.yml, coveralls is installed and runs in the end of the pipeline:

- python -m pip install --upgrade pip coveralls

but apparently the project is not created in the Coveralls website [1], basically discarding any report sent. Am I right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.