Skip to main content

Manages trading dates.

Project description

tradingdate

Manages trade dates.

Installation

$ pip install tradingdate

Requirements

chinesecalendar

Usage

Get a calendar

>>> import tradingdate as td
>>> cal = td.get_calendar("chinese") # by default "chinese"
>>> cal
TradingCalendar(20040102 ~ 20261231, 'chinese')
>>> list(cal)[:3]
[TradingDate(20040102), TradingDate(20040105), TradingDate(20040106)]

Get a trading date

>>> date = td.date(20250116)
>>> date
TradingDate(20250116)
>>> print(date.year, date.month, date.day)
2025 01 16

>>> date - 20
TradingDate(20241218)
>>> date + 100
TradingDate(20250617)

>>> date.week.start, date.week.end
(TradingDate(20250113), TradingDate(20250117))
>>> date.month.start, date.month.end
(TradingDate(20250102), TradingDate(20250127))
>>> date.year.start, date.year.end
(TradingDate(20250102), TradingDate(20251231))

Get iterator of trading dates

>>> list(td.daterange(20250101, 20250107))
[TradingDate(20250102), TradingDate(20250103), TradingDate(20250106)]

Make a new calendar

>>> td.make_calendar("user-defined", [20250101, 20250115, 20250201])
TradingCalendar(20250101 ~ 20250201, 'user-defined')
>>> list(td.daterange(20250101, 20250131, calendar_id="user-defined"))
[TradingDate(20250101), TradingDate(20250115)]

See Also

Github repository

PyPI project

License

This project falls under the BSD 3-Clause License.

History

v0.0.11

  • New parameter for daterange(): step and include_end.
  • Removed get_trading_dates(), use daterange(include_end=True) instead.
  • Renamed get_trading_date() to date().
  • date(missing = 'use_last') is deprecated, use date(missing = 'use_before') now.
  • make_calendar() can now receive an iterator of int, str orTradingtate objects, and the parameter date_list is renamed to dates.

v0.0.10

  • New method DateRange.apply().

v0.0.9

  • Updated support for comparison operators and 'in' operators.

v0.0.8

  • Bugfix: no longer raises an OutOfCalendarError when the end parameter for get_trading_dates() is None.
  • New method TradingDate.iterate_until().
  • daterange() returns an instance of DateRange now.

v0.0.7

  • Updated make_calendar(): raises ValueError when calender_id already exists.

v0.0.6

  • New function daterange().

v0.0.5

  • New property TradingDate.week.

v0.0.4

  • Improved effeciency when making a calendar.
  • Updated message of NotImplementedError raised by CalendarEngine.get_chinese_calendar().

v0.0.3

  • Updated make_calendar(): now accepts a date-list as the second positional argument instead of a dict.

v0.0.2

  • New function make_calendar().
  • Removed the dependency on numpy.

v0.0.1

  • New methods TradingCalendar.get_year(), YearCalendar.get_month(), MonthCalendar.get_day().
  • Bugfix: TradingDate.__sub__().

v0.0.0

  • Initial release.

Project details


Download files

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

Source Distribution

tradingdate-0.0.11.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

tradingdate-0.0.11-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file tradingdate-0.0.11.tar.gz.

File metadata

  • Download URL: tradingdate-0.0.11.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for tradingdate-0.0.11.tar.gz
Algorithm Hash digest
SHA256 7a605d118f05aed5086229dccc1b2856e5b6c2d19280bf6f58030f2f55b149dc
MD5 5f7358f8c290172dba40ac2b9ec862c5
BLAKE2b-256 c36eb337493370493e1e827828cb14c72e782866e5b28a0ff63f76ea9b30319a

See more details on using hashes here.

File details

Details for the file tradingdate-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: tradingdate-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for tradingdate-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 86cb615c9a438ffaf0154bfb6d6690d7b8e204ce84ff75a0b40ba2987e3f9fe6
MD5 963eaf3a0a0fba8fcc591aa63af524aa
BLAKE2b-256 43aa782256a034e3443caf6230457a02a4de9948451acc75d4ddea7f280dce3b

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