Date Utilities
Date Handling Functions
- openseries.datefixer.date_fix(fixerdate)[source]
Parse different date formats into datetime.date.
- Parameters:
fixerdate (DateType) – The data item to parse.
- Returns:
Parsed date.
- Raises:
TypeError – If the provided
fixerdatetype is not supported.- Return type:
dt.date
- openseries.datefixer.date_offset_foll(raw_date, months_offset=12, countries='SE', markets=None, custom_holidays=None, *, adjust=False, following=True)[source]
Offset dates according to a given calendar.
- Parameters:
raw_date (DateType) – The date to offset from.
months_offset (int) – Number of months as integer. Defaults to 12.
countries (CountriesType) – (List of) country code(s) according to ISO 3166-1 alpha-2. Defaults to “SE”.
markets (list[str] | str | None) – (List of) markets code(s) supported by exchange_calendars.
custom_holidays (list[str] | str | None) – Argument where missing holidays can be added.
adjust (bool) – Determines if offset should adjust for business days. Defaults to False.
following (bool) – Determines if days should be offset forward (following) or backward. Defaults to True.
- Returns:
Offset date.
- Return type:
dt.date
- openseries.datefixer.generate_calendar_date_range(trading_days, start=None, end=None, countries='SE', markets=None, custom_holidays=None)[source]
Generate a list of business day calendar dates.
- Parameters:
trading_days (int) – Number of days to generate. Must be greater than zero.
start (dt.date | None) – Date when the range starts.
end (dt.date | None) – Date when the range ends.
countries (CountriesType) – (List of) country code(s) according to ISO 3166-1 alpha-2. Defaults to “SE”.
markets (list[str] | str | None) – (List of) markets code(s) supported by exchange_calendars.
custom_holidays (list[str] | str | None) – Argument where missing holidays can be added.
- Returns:
List of business day calendar dates.
- Return type:
list[dt.date]
- openseries.datefixer.get_previous_business_day_before_today(today=None, countries='SE', markets=None, custom_holidays=None)[source]
Bump date backwards to find the previous business day.
- Parameters:
today (dt.date | None) – Manual input of the day from where the previous business day is found.
countries (CountriesType) – (List of) country code(s) according to ISO 3166-1 alpha-2. Defaults to “SE”.
markets (list[str] | str | None) – (List of) markets code(s) supported by exchange_calendars.
custom_holidays (list[str] | str | None) – Argument where missing holidays can be added.
- Returns:
The previous business day.
- Return type:
dt.date
- openseries.datefixer.holiday_calendar(startyear, endyear, countries='SE', markets=None, custom_holidays=None)[source]
Generate a business calendar.
- Parameters:
startyear (int) – First year in date range generated.
endyear (int) – Last year in date range generated.
countries (CountriesType) – (List of) country code(s) according to ISO 3166-1 alpha-2. Defaults to “SE”.
markets (list[str] | str | None) – (List of) markets code(s) supported by exchange_calendars.
custom_holidays (list[str] | str | None) – Argument where missing holidays can be added.
- Returns:
Generate a business calendar.
- Raises:
CountriesNotStringNorListStrError – If
countriesis not a supported ISO 3166-1 alpha-2 string or a list of such strings.- Return type:
busdaycalendar
- openseries.datefixer.offset_business_days(ddate, days, countries='SE', markets=None, custom_holidays=None)[source]
Bump date by business days.
It first adjusts to a valid business day and then bumps with given number of business days from there.
- Parameters:
ddate (dt.date) – A starting date that does not have to be a business day.
days (int) – The number of business days to offset from the business day that is given. If days is set as anything other than an integer its value is set to zero.
countries (CountriesType) – (List of) country code(s) according to ISO 3166-1 alpha-2. Defaults to “SE”.
markets (list[str] | str | None) – (List of) markets code(s) supported by exchange_calendars.
custom_holidays (list[str] | str | None) – Argument where missing holidays can be added.
- Returns:
The new offset business day.
- Return type:
dt.date
The datefixer module provides utilities for handling business days, holidays, and date calculations commonly needed in financial analysis.