qdpmc.dateutil.date.Calendar

class qdpmc.dateutil.date.Calendar(holiday_rule=<function _is_china_holidays>, other_holidays=None)[source]

Bases: object

Methods

__init__([holiday_rule, other_holidays])

add_holiday_rule(holiday_rule)

Add holiday rules.

add_holidays(holidays)

Add holidays to holiday rules.

is_trading(date)

Return if date trades.

num_trading_days_between(start, end[, count_end])

Return number of trading days between two dates.

offset(date, n)

Return date of trading day n days after date.

periodic(start, period, count[, if_close, force])

Generate periodical trading dates.

to_scalar(date_arr, start)

Convert dates into integers given a start date.

trading_days_between(start, end[, endpoints])

Return a list of trading days between start and end.

add_holiday_rule(holiday_rule)[source]

Add holiday rules.

Parameters

holiday_rule (callable()) – A function that converts datetime.date to bool.

add_holidays(holidays)[source]

Add holidays to holiday rules. holidays should be iterable

is_trading(date: datetime.date)[source]

Return if date trades.

Parameters

date (datetime.date) –

num_trading_days_between(start: datetime.date, end: datetime.date, count_end: bool = True) int[source]

Return number of trading days between two dates. If these dates are identical, return 0. count_end controls whether to count the end date.

offset(date: datetime.date, n: int) datetime.date[source]

Return date of trading day n days after date. n can be negative but must be an integer.

Parameters
periodic(start: datetime.date, period: str, count: int, if_close: str = 'next', force: bool = False) list[source]

Generate periodical trading dates. Duplicates will be dropped so the output list may be shorter than count. To force the length of output to count, set force to True

Examples

..ipython:: python

import datetime calendar = qm.Calendar() start_date = datetime.date(2019, 1, 31) calendar.periodic(start, ‘1m’, 13)

to_scalar(date_arr, start) list[source]

Convert dates into integers given a start date.

Parameters
Returns

list – A list of integers.

trading_days_between(start: datetime.date, end: datetime.date, endpoints: bool = True) list[source]

Return a list of trading days between start and end. Endpoints are counted only if they are trading.

Parameters
Returns

list – A list of trading dates.

Note

start and end are counted _only_ if they are trading dates.