Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Differences Between trading_calendars and pandas_market_calendars #152

Closed
5 of 9 tasks
gerrymanoim opened this issue Sep 4, 2020 · 8 comments
Closed
5 of 9 tasks

Comments

@gerrymanoim
Copy link
Collaborator

gerrymanoim commented Sep 4, 2020

re rsheftel/pandas_market_calendars#41

Summary status

Extras not covered by diff below:

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
@gerrymanoim
Copy link
Collaborator Author

cc @jmccorriston (FYI - @rsheftel )

@jmccorriston
Copy link
Contributor

For TSX:

I can't find any sources saying that Christmas Eve was a holiday, but I found this source suggesting that the market was open on 2010-12-24 (but closed by 2:41pm ET, suggesting it closed early): https://toronto.ctvnews.ca/modest-tsx-gain-as-trading-takes-a-christmas-break-1.589362

There's also this wiki page on the 9/11 closes around the world (includes TSX): https://en.wikipedia.org/wiki/Closings_and_cancellations_following_the_September_11_attacks

So I think the Toronto Stock exchange implementation in trading_calendars is correct.

@gerrymanoim
Copy link
Collaborator Author

FWIW https://finance.yahoo.com/quote/RY.TO/history?period1=1292112000&period2=1293753600&interval=1d&filter=history&frequency=1d shows volume on TSX on 2010-12-24.

@jmccorriston
Copy link
Contributor

jmccorriston commented Sep 9, 2020

For HKG:

It looks like Hong Kong only started observing Labour Day in 1999 (https://en.wikipedia.org/wiki/International_Workers%27_Day, "In Hong Kong, 1 May is known as Labour Day and has been considered a public holiday since 1999."). pmc is correct here, tc needs to be updated.

Establishment day started in 1997: https://www.scmp.com/news/hong-kong/education-community/article/1983718/everything-you-need-know-about-hong-kongs-return. pmc is correct here, tc needs to be updated.

National Day also first observed in 1997: http://www.cnn.com/WORLD/9710/01/china.bday/. pmc is correct, tc needs to be updated.

Buddha's birthday also only started as a public holiday in 1998: https://www.cantoneseclass101.com/blog/2020/04/24/celebrating-buddhas-birthday-in-hong-kong/, https://www.officeholidays.com/holidays/hong-kong/the-buddhas-birthday. We should trim the calendar in tc to reflect this. However, it looks like there's still a discrepancy in 1998. pmc suggests that 1998-05-04 should be a trading day while tc suggests it should be a holiday (1998-05-03 actual holiday, observed on the Monday).

There are several British holidays that were observed during British rule pre-1997 as well:

It looks like there are a lot of details in the pmc Hong Kong calendar implementation that we are missing in tc. I pinged the person who added them to pmc to see if we can get more info, but my inclination is to pull in the historical calendars that they added to pmc. From what I can tell so far, they are correct.

One exception: 2021-04-06 was a public holiday per https://www.hkex.com.hk/News/HKEX-Calendar?sc_lang=en (Ching Ming festival). This is correct in tc.

@jmccorriston
Copy link
Contributor

jmccorriston commented Sep 9, 2020

For CFE:

I can't seem to find any references for Nixon's Day of Mourning on 1994-04-27... Not sure what to do about this one.

@rsheftel
Copy link
Collaborator

Discussion of pre-1990 NYSE (XNYS) calendar here: #162

@rsheftel
Copy link
Collaborator

Discussion of LSE differences here: #163

@rsheftel
Copy link
Collaborator

rsheftel commented Sep 16, 2020

Discussion of XKTS (JPX) differences here: #164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants