Calendar utilities#
Weekday enumeration. |
-
sigtech.framework.infra.calendar.dates.DATE_MONTH = 'MONTH'
Increment type: month.
-
sigtech.framework.infra.calendar.dates.DATE_QUARTER = 'QUARTER'
Increment type: quarter.
-
sigtech.framework.infra.calendar.dates.DATE_WEEK = 'WEEK'
Increment type: week.
-
sigtech.framework.infra.calendar.dates.DATE_YEAR = 'YEAR'
Increment type: year.
-
sigtech.framework.infra.calendar.dates.adjust(calendar: str, ref_date: date, mode: str) date
Adjust the reference date according to supplied business day conventions.
- Parameters:
calendar – String calendar identifier.
ref_date – Input reference date.
mode – Business day convention, e.g.
'FOLLOWING'
,'MOD_FOL'
,'PRECEDE'
,'MOD_PRE'
,'NONE_RULE'
.
- Returns:
date.
-
sigtech.framework.infra.calendar.dates.build_calendar(names: Union[str, list[str], FrameworkObjectCalendarType], use_business_calendar=True, quant_library=None, env: Optional[ConfiguredEnvironment] = None) Union[CustomCalendar, Calendar]
Create a calendar library object from persistent calendar objects.
- Parameters:
names – Calendar string identifier.
use_business_calendar – Use Python business calendar package if True (default), otherwise use quant library calendar.
quant_library – Only used if
use_business_calendar
is set to False.env – Configured environment to use (optional).
- Returns:
Calendar object.
-
sigtech.framework.infra.calendar.dates.business_days(calendar: Union[str, list[str], FrameworkObjectCalendarType], start_date: date, end_date: date) list[datetime.date]
Return the list of calendar business dates in
[start_date, end_date]
inclusive.- Parameters:
calendar – Calendar string identifier or calendar instance.
start_date – Start date of the range.
end_date – End date of the range.
- Returns:
List of dates.
-
sigtech.framework.infra.calendar.dates.business_days_ts(calendar: Union[str, list[str], FrameworkObjectCalendarType], start_date: date, end_date: date) DatetimeIndex
Return the list of calendar business dates in
[start_date, end_date]
inclusive.- Parameters:
calendar – Calendar string identifier or calendar instance.
start_date – Start date of the range.
end_date – End date of the range.
- Returns:
List of dates.
-
sigtech.framework.infra.calendar.dates.calendar_ttm(start: Union[date, list[datetime.date]], end: Union[date, list[datetime.date]], calendar)
Evaluate the day fraction between two dates in terms of actual, weekends and holidays.
- Parameters:
start – Start date.
end – End date.
calendar – String calendar identifier.
- Returns:
Tuple of days, weekends, holidays fractions.
-
sigtech.framework.infra.calendar.dates.closest_weekday(base_date: date, weekday: str) date
Return the closest weekday as date for given base date.
- Parameters:
base_date – Input reference date.
weekday – String identifier for day of the week, i.e.
'Monday'
,'Tuesday'
, …'Sunday'
.
- Returns:
date.
-
sigtech.framework.infra.calendar.dates.combined_holidays(*args: str) str
Combine a list of holidays into a string stub.
- Parameters:
args – List of holiday string identifiers.
- Returns:
str.
-
sigtech.framework.infra.calendar.dates.count_business_days(calendar: Union[str, list[str], FrameworkObjectCalendarType], start_date: date, end_date: date) int
Return the number of calendar business dates in
[start_date, end_date]
inclusive.- Parameters:
calendar – Calendar string identifier or calendar instance.
start_date – Start date of the range.
end_date – End date of the range.
- Returns:
int.
-
sigtech.framework.infra.calendar.dates.current_next_business_day(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[date, ndarray]
Return
day
if it is a business day, else the next business day.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
Date or array of dates.
-
sigtech.framework.infra.calendar.dates.current_previous_business_day(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[date, ndarray]
Return
day
if it is a business day, else the previous business day.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
Date or array of dates.
-
sigtech.framework.infra.calendar.dates.date_dcf(style, start, end, bus_calendar=None)
Calculate the day count fraction using the following supported day count methods:
'ACT_360'
'ACT_365F'
'ACT_ACT'
'BUS_252'
- Parameters:
style – Day count method.
start – Start date.
end – End date.
bus_calendar – Calendar for business day counting (if required by
style
).
- Returns:
Day count fraction.
-
sigtech.framework.infra.calendar.dates.date_dcf_series(style: str, series: Series)
Faster method to get multiple day-count fractions at once, when the input is pandas series. Index is start-dates, data is end-dates. Only
DAYCOUNT_ACTUAL_360
andDAYCOUNT_ACTUAL_365_FIXED
have a speed up.- Parameters:
style – Day count method.
series – Input day-count fraction series.
- Returns:
pandas Series.
-
sigtech.framework.infra.calendar.dates.date_increment(d: Union[date, DatetimeIndex, ndarray], increment: str, calendar: Union[str, list[str], FrameworkObjectCalendarType], backward: bool = False, bdc: str = 'FOLLOWING', eom: bool = False) Union[date, DatetimeIndex, ndarray]
Increment the input date.
- Parameters:
d – Input date.
increment – Increment string stub, e.g.
'1d'
,'1bd'
,'1b'
,'1cd'
,'1w'
,'1m'
, …calendar – Calendar string identifier or calendar instance.
backward – Adjust backward if set True, otherwise adjust forward (default).
bdc – Business day convention, e.g.
'FOLLOWING'
,'MOD_FOL'
,'PRECEDE'
,'MOD_PRE'
,'NONE_RULE'
(default is'BDC_FOLLOWING'
).eom – Apply the EOM rule if set to True (default is False).
- Returns:
Date or array of dates.
-
sigtech.framework.infra.calendar.dates.dependencies(names: Union[str, list[str], FrameworkObjectCalendarType]) list[sigtech.framework.internal.infra.mu.graph.registry.factory.Dependency]
Dependencies
-
sigtech.framework.infra.calendar.dates.end_of_month(d: Union[date, ndarray]) Union[date, ndarray]
Return the end of month date for the given date.
- Parameters:
d – Python date.
- Returns:
End of month date.
-
sigtech.framework.infra.calendar.dates.get_month_end_dates(start: date, end: date, calendar_names: str) list[pandas.core.indexes.datetimes.DatetimeIndex]
Provide the month end dates for dates in the range
[start, end]
using the provider calendars.- Parameters:
start – Start date.
end – End date.
calendar_names – String stub for calendar names.
- Returns:
List of month end dates.
-
sigtech.framework.infra.calendar.dates.imm_code(imm_date: date, one_year_digit: bool) str
Return the IMM stub, e.g. to be used in interest rate swap generation.
Example:
- ::
from sigtech.framework.infra.calendar.dates import imm_code
imm_code(dtm.date(2020, 3, 20), False) # Return ‘H20’
imm_code(dtm.date(2020, 3, 20), True) # Return ‘H0’
- Parameters:
imm_date – Input IMM date.
one_year_digit – Flag to check if the year is represented with one digit.
- Returns:
str.
-
sigtech.framework.infra.calendar.dates.imm_date(ref_date: date, currency: str, apply_switch: Optional[bool] = False) date
Return the next IMM date for a given reference date and currency.
- Parameters:
ref_date – Input reference date.
currency – Currency string.
apply_switch – Switch where change from 2nd Monday to Monday before 3rd Wednesday rule (default is False).
- Returns:
date.
-
sigtech.framework.infra.calendar.dates.is_business_day(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[bool, ndarray]
Check if a date
day
is a valid business day in the given calendar.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
bool or array of bool.
-
sigtech.framework.infra.calendar.dates.is_holiday(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[bool, ndarray]
Check if a date
day
is a valid business day in the given calendar.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
bool or array of bool.
-
sigtech.framework.infra.calendar.dates.next_business_day(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[date, ndarray]
Return the next business day after
day
.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
Date or array of dates.
-
sigtech.framework.infra.calendar.dates.non_business_days(calendar: Union[str, list[str], FrameworkObjectCalendarType], start_date: date, end_date: date) list[datetime.date]
List of non-weekend, non-business dates for calendar in
[start_date, end_date]
inclusive.- Parameters:
calendar – Calendar string identifier or calendar instance.
start_date – Start date of the range.
end_date – End date of the range.
- Returns:
List of dates.
-
sigtech.framework.infra.calendar.dates.nth_day_in_month(base_date: date, day: str, n: int) date
Return the n-th occurrence of the weekday’s name
day
in the month from the datebase_date
, e.g. third Wednesday. Inputting a negative number will yield the same behaviour as indexing, e.g.-1
will give the last occurrence,-2
second to last.- Parameters:
base_date – Input reference date.
day – String identifier for day of the week, i.e.
'Monday'
,'Tuesday'
, …'Sunday'
.n – N-th day in the month for
day
, or-1
for last,-2
for second to last, etc.
- Returns:
date.
-
sigtech.framework.infra.calendar.dates.nth_week_day(n: int, day_of_week: Union[str, int], month: int, year: int) date
Return the date for the n-th weekday for a given month and a year.
- Parameters:
n – Ordinal number of weekday occurrence.
day_of_week – String identifier for the weekday, i.e.
'Monday'
,'Tuesday'
,'Wednesday'
,'Thursday'
,'Friday'
. Integers are also accepted, ranging from1
(Monday) to7
(Sunday).month – Month reference.
year – Year reference.
- Returns:
date.
-
sigtech.framework.infra.calendar.dates.parse_increment(increment: str) tuple
Parse the increment string into 3 types (forward/backward, increment type, raw numerical amount).
- Parameters:
increment – Increment string stub.
- Returns:
tuple (forward/backward, increment type, raw numerical amount).
-
sigtech.framework.infra.calendar.dates.previous_business_day(calendar: Union[str, list[str], FrameworkObjectCalendarType], day: Union[date, ndarray]) Union[date, ndarray]
Return the previous business day before
day
.- Parameters:
calendar – Calendar string identifier or calendar instance.
day – Input date.
- Returns:
Date or array of dates.
-
sigtech.framework.utils.numeric_utils.date_to_datetime(d: Union[date, datetime], tz_aware=False) datetime
Converts date (or datetime) to a tz-naive datetime.
- Parameters:
d –
date
ordatetime
.tz_aware – Convert UTC tz-unaware datetime to UTC tz-aware datetime (default is False).
- Returns:
datetime
.
-
sigtech.framework.utils.numeric_utils.date_to_midnight_datetime(d: Union[date, datetime, DatetimeIndex]) datetime
Convert a Timestamp, date or datetime to midnight datetime. :param d: input Timestamp, date and datetime: :return: Midnight datetime.
-
sigtech.framework.utils.numeric_utils.datetime_to_date(dt: Union[date, datetime]) date
Convert datetime to date.
- Parameters:
dt –
date
ordatetime
.- Returns:
date