Skip to main content

Exchange Calendars: issession, trade_date_range

Project description

Holidays in China

Background

We classify calendar days into:

  • regular workdays: working days not on weekends
  • regular weekends: weekends (Saturday and Sunday) not working
  • festivals: true or legal holidays. e.g. 2026-01-01 (Thursday) is New Year holiday; 2023-01-02 (Monday), which is shifted from 2023-01-01 (Sunday), is also a legal holiday
  • quasi-holidays: extra holidays swapped with weekend workdays
  • weekend workdays:workdays in weekends for swapped extra holidays

For example, 2025-12-31 (Wednesday) is a regular workday.

2025-01-01 (Thursday) is a festival holiday (New Year)

2025-01-02 (Friday) is a quasi-holiday, though we need not to work on this day, but we need to work on 2026-01-04 (Sunday) to swap with this extra holiday.

2025-01-03 (Saturday) is a regular weekend.

2025-01-04 (Sunday) is a weekend workday. Though it a weekend, but we to work on this day to swap with extra extra holiday on 2025-01-02.

On weekend workdays, exchanges in China mainland are closed, although they are workdays.

In November each year, the state council of China announces the holiday arrangement for next year. Please update the holiday data accordingly.

cnexchcal Package

This package provides a class to handle holidays and trading days in China mainland since year 2004. We does not touch holidays before 2004.

Installation

pip install cnexchcal

Usage

Instantiation:

from cnexchcal import ExchCal
cal = ExchCal()

To return holiday names in Chinese or English

cal.holiday_cnnames
cal.holiday_ennames

To determine if a given date is a holiday or workday, uese:

cal.isholiday('2026-01-04')   # False
cal.isworkday('2026-01-04')   # True

To determine if a given date is a trading day:

cal.issession('2026-01-04')   # False

To get the previous trading day, use:

cal.previoussession('2026-01-04')   # 2025-12-31

To get the next trading day, use:

cal.nextsession('2026-01-01')   # 2026-01-05

To get the n-th trading day after a given date, use:

cal.next_nth_tradingday('2026-01-01', 3)   # 2026-01-07

To get the n-th trading day before a given date, use:

cal.previous_nth_tradingday('2026-01-01', 3)   # 2025-12-29

To get all trading dates between two given dates, use:

cal.trade_date_range('2025-12-20', '2026-02-28')

To get the number of trading days in a given year, use:

cal.ntradedays(2025)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cnexchcal-0.2.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file cnexchcal-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: cnexchcal-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for cnexchcal-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d3ab92648e529260331219c48a829305ae0e86529e9482b24b1f9c780029c15
MD5 e37046880f6b16541ec6baa759472700
BLAKE2b-256 9d046c47f6931a3d2622aa92e587da3d667fdd51db09a7d978825d476e93c130

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page