Project Documentation

BusinessDate

date class to perform calculations coming from financial businesses

BusinessPeriod

class to store and calculate date periods as combinations of days, weeks, years etc.

BusinessRange

class to build list of business days

BusinessSchedule

class to build date schedules incl start and end date

BusinessHolidays

holiday calendar class

Business Object Classes

BusinessDate

class businessdate.businessdate.BusinessDate(year=None, month=0, day=0, convention=None, holidays=None, day_count=None)[source]

Bases: businessdate.basedate.BaseDateDatetimeDate

date class to perform calculations coming from financial businesses

Parameters
  • year – number of year or some other input value t o create BusinessDate instance. When applying other input, this can be either int, float, datetime.date or string which will be parsed and transformed into equivalent tuple of int items (year,month,day) (See tutorial for details).

  • month (int) – number of month in year 1 … 12 (default: 0, required to be 0 when other input of year is used)

  • days (int) – number of day in month 1 … 31 (default: 0, required to be 0 when other input of year is used)

For all input arguments exits read only properties.

ADJUST = 'No'
BASE_DATE = None
DATE_FORMAT = '%Y%m%d'
DAY_COUNT = 'act_36525'
DEFAULT_CONVENTION(holidays=())

does no adjustment.

DEFAULT_HOLIDAYS = []
DEFAULT_DAY_COUNT(end)

implements Act/365.25 Day Count Convention

classmethod is_businessdate(d)[source]

checks whether the provided input can be a date

is_leap_year()[source]

returns True for leap year and False otherwise

days_in_year()[source]

returns number of days in the given calendar year

days_in_month()[source]

returns number of days for the month

end_of_month()[source]

returns the day of the end of the month as BusinessDate object

end_of_quarter()[source]

returns the day of the end of the quarter as BusinessDate object

is_business_day(holidays=None)[source]

returns True if date falls neither on weekend nor is in holidays (if given as container object)

add_period(period_obj, holidays=None)[source]

adds a BusinessPeriod object or anythings that create one and returns BusinessDate object.

It is simply adding the number of years, months and days or if businessdays given the number of business days, i.e. days neither weekend nor in holidays (see also BusinessDate.is_business_day())

diff_in_days(end_date)[source]

calculates the distance to a BusinessDate in days

diff_in_ymd(end_date)[source]
get_day_count(end=None, day_count=None)[source]

counts the days as a year fraction to given date following the specified convention.

For more details on the conventions see module businessdate.daycount.

In order to get the year fraction according a day count convention provide one of the following convention key words:

  • 30_360 implements 30/360 Day Count Convention.

  • 30360 implements 30/360 Day Count Convention.

  • thirty360 implements 30/360 Day Count Convention.

  • 30e_360 implements the 30E/360 Day Count Convention.

  • 30e360 implements the 30E/360 Day Count Convention.

  • thirtye360 implements the 30E/360 Day Count Convention.

  • 30e_360_i implements the 30E/360 I. Day Count Convention.

  • 30e360i implements the 30E/360 I. Day Count Convention.

  • thirtye360i implements the 30E/360 I. Day Count Convention.

  • act_360 implements Act/360 day count convention.

  • act360 implements Act/360 day count convention.

  • act_365 implements Act/365 day count convention.

  • act365 implements Act/365 day count convention.

  • act_36525 implements Act/365.25 Day Count Convention

  • act_365.25 implements Act/365.25 Day Count Convention

  • act36525 implements Act/365.25 Day Count Convention

  • act_act implements Act/Act day count convention.

  • actact implements Act/Act day count convention.

get_year_fraction(end=None, day_count=None)[source]

wrapper for BusinessDate.get_day_count() method for different naming preferences

adjust(convention=None, holidays=None)[source]

returns an adjusted BusinessDate if it was not a business day following the specified convention.

For details on business days see BusinessDate.is_business_day().

For more details on the conventions see module businessdate.conventions

In order to adjust according a business day convention provide one of the following convention key words:

  • no does no adjustment.

  • previous adjusts to Business Day Convention “Preceding”.

  • prev adjusts to Business Day Convention “Preceding”.

  • prv adjusts to Business Day Convention “Preceding”.

  • mod_previous adjusts to Business Day Convention “Modified Preceding”.

  • modprevious adjusts to Business Day Convention “Modified Preceding”.

  • modprev adjusts to Business Day Convention “Modified Preceding”.

  • modprv adjusts to Business Day Convention “Modified Preceding”.

  • follow adjusts to Business Day Convention “Following”.

  • flw adjusts to Business Day Convention “Following”.

  • modified adjusts to Business Day Convention “Modified [Following]”.

  • mod_follow adjusts to Business Day Convention “Modified [Following]”.

  • modfollow adjusts to Business Day Convention “Modified [Following]”.

  • modflw adjusts to Business Day Convention “Modified [Following]”.

  • start_of_month adjusts to Business Day Convention “Start of month”, i.e. first business day.

  • startofmonth adjusts to Business Day Convention “Start of month”, i.e. first business day.

  • som adjusts to Business Day Convention “Start of month”, i.e. first business day.

  • end_of_month adjusts to Business Day Convention “End of month”, i.e. last business day.

  • endofmonth adjusts to Business Day Convention “End of month”, i.e. last business day.

  • eom adjusts to Business Day Convention “End of month”, i.e. last business day.

  • imm adjusts to Business Day Convention of “International Monetary Market”.

  • cds_imm adjusts to Business Day Convention “Single Name CDS”.

  • cdsimm adjusts to Business Day Convention “Single Name CDS”.

  • cds adjusts to Business Day Convention “Single Name CDS”.

BusinessDate Base Classes

businessdate.businessdate.BusinessDate inherits from one of two possible base classes. One itself inherited by a native float class. The other inherited from datetime.date class.

Both classes are implemented to offer future releases the flexibility to switch from one super class to another if such offers better performance.

Currently businessdate.businessdate.BusinessDate inherits from businessdate.basedate.BaseDateDatetimeDate which offers more elaborated functionality.

Warning

Future releases of businessdate may be backed by different base classes.

class businessdate.basedate.BaseDateFloat(x=0)[source]

Bases: float

native float backed base class for a performing date calculations counting days since Jan, 1st 1900

property day
property month
property year
weekday()[source]
classmethod from_ymd(year, month, day)[source]

creates instance from a tuple of int items (year, month, day)

classmethod from_date(d)[source]

creates instance from a datetime.date object d

classmethod from_float(x)[source]

creates from a float x counting the days since Jan, 1st 1900

to_ymd()[source]

returns the tuple of int items (year, month, day)

to_date()[source]

returns datetime.date(year, month, day)

to_float()[source]

returns float counting the days since Jan, 1st 1900

class businessdate.basedate.BaseDateDatetimeDate[source]

Bases: datetime.date

datetime.date backed base class for a performing date calculations

classmethod from_ymd(year, month, day)[source]

creates instance from a tuple of int items (year, month, day)

classmethod from_date(d)[source]

creates instance from a datetime.date object d

classmethod from_float(x)[source]

creates from a float x counting the days since Jan, 1st 1900

to_ymd()[source]

returns the tuple of int items (year, month, day)

to_date()[source]

returns datetime.date(year, month, day)

to_float()[source]

returns float counting the days since Jan, 1st 1900

to_serializable(*args, **kwargs)[source]

BusinessPeriod

class businessdate.businessperiod.BusinessPeriod(period='', years=0, quarters=0, months=0, weeks=0, days=0, businessdays=0)[source]

Bases: object

class to store and calculate date periods as combinations of days, weeks, years etc.

Parameters
  • period (str) – encoding a business period. Such is given by a sequence of digits as int followed by a char - indicating the number of years Y, quarters Q (which is equivalent to 3 month), month M, weeks W (which is equivalent to 7 days), days D, business days B. E.g. 1Y2W3D what gives a period of 1 year plus 2 weeks and 3 days (see tutorial for details).

  • years (int) – number of years in the period (equivalent to 12 months)

  • quarters (int) – number of quarters in the period (equivalent to 3 months)

  • months (int) – number of month in the period

  • weeks (int) – number of weeks in the period (equivalent to 7 days)

  • days (int) – number of days in the period

  • businessdays (int) – number of business days, i.e. days which are neither weekend nor holidays, in the period. Only either businessdays or the others can be given. Both at the same time is not allowed.

property years
property months
property days
property businessdays
classmethod is_businessperiod(period)[source]

returns true if the argument can be understood as BusinessPeriod

max_days()[source]
min_days()[source]

BusinessSchedule

class businessdate.businessschedule.BusinessSchedule(start, end, step, roll=None)[source]

Bases: businessdate.businessrange.BusinessRange

class to build date schedules incl start and end date

Parameters

convenient class to build date schedules a schedule includes always start and end date and rolls on roll, i.e. builds a sequence by adding and/or substracting step to/from roll. start and end slice the relevant dates.

first_stub_long()[source]

adjusts the schedule to have a long stub at the beginning, i.e. first period is longer a regular step.

last_stub_long()[source]

adjusts the schedule to have a long stub at the end, i.e. last period is longer a regular step.

class businessdate.businessrange.BusinessRange(start, stop=None, step=None, rolling=None)[source]

Bases: list

class to build list of business days

Parameters
  • start (BusinessDate) – date to begin schedule, if stop not given, start will be used as stop and default in rolling to BusinessDate()

  • stop (BusinessDate) – date to stop before, if not given, start will be used for stop instead

  • step (BusinessPeriod) – period to step schedule, if not given 1 day is default

  • rolling (BusinessDate) – date to roll on (forward and backward) between start and stop, if not given default will be start

Ansatz First, rolling and step defines a infinite grid of dates. Second, this grid is sliced by start (included , if meeting the grid) and end (excluded).

All dates will have same convention, holidays and day_count property as rolling.

adjust(convention=None, holidays=None)[source]

returns adjusted BusinessRange following given convention

For details of adjusting BusinessDate see BusinessDate.adjust().

For possible conventions invoke BusinessDate().adjust()

For more details on the conventions see module conventions)

BusinessHolidays

class businessdate.businessholidays.TargetHolidays(iterable=())[source]

Bases: businessdate.businessholidays.BusinessHolidays

holiday calendar class of ecb target2 holidays

Target holidays are

  • Jan, 1st

  • Good Friday

  • Easter Monday

  • May, 1st

  • December, 25th (Christmas Day)

  • December, 25th (Boxing Day)

class businessdate.businessholidays.BusinessHolidays(iterable=())[source]

Bases: list

holiday calendar class

A BusinessHolidays instance imitated a list of datetime.date which can be used to check if a BusinessDate is included as holiday.

For convenience input need not to be of type datetime.date. Duck typing is enough, i.e. having properties year, month and day.

Convention Functions

Day Count

businessdate.daycount.diff_in_days(start, end)[source]

calculates days between start and end date

businessdate.daycount.get_30_360(start, end)[source]

implements 30/360 Day Count Convention.

businessdate.daycount.get_30e_360(start, end)[source]

implements the 30E/360 Day Count Convention.

businessdate.daycount.get_30e_360i(start, end)[source]

implements the 30E/360 I. Day Count Convention.

businessdate.daycount.get_act_360(start, end)[source]

implements Act/360 day count convention.

businessdate.daycount.get_act_365(start, end)[source]

implements Act/365 day count convention.

businessdate.daycount.get_act_36525(start, end)[source]

implements Act/365.25 Day Count Convention

businessdate.daycount.get_act_act(start, end)[source]

implements Act/Act day count convention.

Business Day Adjustment

businessdate.conventions.is_business_day(business_date, holidays=[])[source]

method to check if a date falls neither on weekend nor is in holidays.

businessdate.conventions.adjust_no(business_date, holidays=())[source]

does no adjustment.

businessdate.conventions.adjust_previous(business_date, holidays=())[source]

adjusts to Business Day Convention “Preceding”.

businessdate.conventions.adjust_follow(business_date, holidays=())[source]

adjusts to Business Day Convention “Following”.

businessdate.conventions.adjust_mod_follow(business_date, holidays=())[source]

adjusts to Business Day Convention “Modified [Following]”.

businessdate.conventions.adjust_mod_previous(business_date, holidays=())[source]

adjusts to Business Day Convention “Modified Preceding”.

businessdate.conventions.adjust_start_of_month(business_date, holidays=())[source]

adjusts to Business Day Convention “Start of month”, i.e. first business day.

businessdate.conventions.adjust_end_of_month(business_date, holidays=())[source]

adjusts to Business Day Convention “End of month”, i.e. last business day.

businessdate.conventions.adjust_imm(business_date, holidays=())[source]

adjusts to Business Day Convention of “International Monetary Market”.

businessdate.conventions.adjust_cds_imm(business_date, holidays=())[source]

adjusts to Business Day Convention “Single Name CDS”.