API Documentation

Class List

businessdate.BusinessDate fundamental date class
businessdate.BusinessPeriod class managing date periods like days, weeks, years etc.
businessdate.BusinessRange range like class to build date list
businessdate.BusinessSchedule class to build date schedules incl. start and end date
businessdate.BusinessHolidays holiday calendar class

Inheritance Diagram

Inheritance diagram of businessdate

Business Object Classes

businessdate.BASE_DATE = 42369

int – Excel representation of 31.12.2015

class businessdate.BusinessDate[source]

Bases: basedate.BaseDate

fundamental date class

Parameters:date_value (int, float, string or datetime.date) – input value to create BusinessDate instance
Returns:BusinessDate

creates new BusinessDate either from int, float, string, datetime.date therefore the following will create the same

BusinessDate(datetime.date(2015, 12, 31))
BusinessDate(20151231)
BusinessDate(2015-12-31)
BusinessDate(31.12.2015)
BusinessDate(12/31/2015)
BusinessDate(42369)
BusinessDate(42369.0)
BusinessDate(735963)
BusinessDate(735963.0)
BusinessDate()

caution: recommended is the use of classmethods BusinessDate.from_string, from_date etc.

add_business_days(days_int, holiday_obj=None)[source]

private method for the addition of business days, used in the addition of a BusinessPeriod only

Parameters:
  • d (BusinessDate) –
  • days_int (int) –
  • holiday_obj (list) –
Returns:

BusinessDate

add_businessdays(days_int, holiday_obj=None)[source]
add_days(days)[source]
add_months(month_int)[source]

addition of a number of months

Parameters:
Return bankdate:
 
add_period(p, holiday_obj=None)[source]

addition of a period object

Parameters:
Return bankdate:
 
add_years(years)[source]
adjust_cds_imm(holidays_obj=None)[source]
adjust_end_of_month(holidays_obj=None)[source]
adjust_follow(holidays_obj=None)[source]
adjust_imm(holidays_obj=None)[source]
adjust_mod_follow(holidays_obj=None)[source]
adjust_mod_previous(holidays_obj=None)[source]
adjust_previous(holidays_obj=None)[source]
adjust_start_of_month(holidays_obj=None)[source]
static days_in_month(year, month)[source]

returns number of days for the given year and month

Parameters:
  • year (int) – calendar year
  • month (int) – calendar month
Return int:
static days_in_year(year)[source]

returns number of days in the given calendar year

Parameters:year (int) – calendar year
Return int:
diff(end_date)[source]

difference expressed as a tuple of years, months, days (see also the python lib dateutils.relativedelta)

Parameters:
Return (int, int, int):
 
diff_in_days(end_bd)[source]
diff_in_years(end_bd)[source]
static end_of_month(year, month)[source]
static end_of_quarter(year, month)[source]
static from_bankdate(d)[source]
static from_businessdate(d)[source]

copy constructor

Parameters:d (BusinessDate) –
Return bankdate:
 
static from_date(datetime_date)[source]

construct BusinessDate instance from datetime.date instance, raise ValueError exception if not possible

Parameters:datetime_date (datetime.date) – calendar day
Return bool:
static from_excel(excel_int)[source]
static from_ordinal(ordinal_int)[source]
static from_string(date_str)[source]

construction from the following string patterns ‘%Y-%m-%d’ ‘%d.%m.%Y’ ‘%m/%d/%Y’ ‘%Y%m%d’

Parameters:date_str (str) –
Return BusinessDate:
 
static from_ymd(y, m, d)[source]
get_30_360(end)[source]

implements 30/360 day count convention

get_act_360(end)[source]

implements Act/360 day count convention

get_act_365(end)[source]

implements Act/365 day count convention

get_act_36525(end)[source]

implements Act/365.25 day count convention

get_act_act(end)[source]

implements Act/Act day count convention

is_business_day(holiday_obj=None)[source]

:param list holiday_obj : datetime.date list defining businessholidays :return: bool

method to check if a date falls neither on weekend nor is holiday

static is_businessdate(in_date)[source]

checks whether the provided date is a date :param BusinessDate, int or float in_date: :return bool:

is_businessday(holiday_obj=None)[source]
Parameters:holiday_obj
Returns:

deprecated method

static is_date(in_date)[source]
static is_leap_year(year)[source]

returns True for leap year and False otherwise

Parameters:year (int) – calendar year
Return bool:
to_bankdate(origin_date)[source]
to_businessdate(origin_date=None)[source]
to_businessperiod(origin_date=None)[source]
to_date()[source]

construct datetime.date instance represented calendar date of BusinessDate instance

Return datetime.date:
 
to_excel()[source]
to_ordinal()[source]
to_period(origin_date=None)[source]
to_string()[source]

return BusinessDate as ‘date.strftime(DATE_FORMAT)’

Return string:
to_ymd()[source]
class businessdate.BusinessHolidays(iterable=None)[source]

Bases: list

holiday calendar class

Parameters:iterable (iterable) – sequence of holiday dates
class businessdate.BusinessPeriod(period_in='', holiday=None, years=0, months=0, days=0, businessdays=0)[source]

Bases: baseperiod.BasePeriod

class managing date periods like days, weeks, years etc.

Parameters:
  • period_in
  • holiday
  • years
  • months
  • days
  • businessdays

representation of a time BusinessPeriod, similar to dateutils.relativedelta, but with additional business day logic

add_businessdays(days_int)[source]
add_businessperiod(p)[source]
add_days(days_int)[source]
add_months(months_int)[source]
add_years(years_int)[source]
classmethod from_string(period_in)[source]
classmethod is_businessperiod(in_period)[source]
Parameters:in_period (object, str, timedelta) – object to be checked
Returns:True if cast works
Return type:Boolean

checks is argument con becasted to BusinessPeriod

classmethod is_period(in_period)[source]
classmethod parse(period_str)[source]
to_bankdate(start_date=None)[source]
to_businessdate(start_date=None)[source]
to_businessperiod(start_date=None)[source]
to_date(start_date=None)[source]
to_datetime(start_date=None)[source]
to_period(start_date=None)[source]
to_string()[source]
class businessdate.BusinessRange(start, stop=None, step=None, rolling=None)[source]

Bases: list

range like class to build date list

Parameters:
  • start (BusinessDate or int or str) – date to begin schedule, if stop not given, start will be used as stop and default in rolling to BusinessDate()
  • stop (BusinessDate or int or str) – date to stop before, if not given, start will be used for stop instead
  • step (BusinessPeriod or str) – period to step schedule, if not given 1 year is default
  • rolling (BusinessDate or int or str) – date to roll on (forward and backward) between start and stop, if not given default will be start

range like class to build BusinessDate schedule from rolling date and BusinessPeriod

adjust(convention=None, holidays_obj=None)[source]
adjust_cds_imm(holidays_obj=None)[source]
adjust_end_of_month(holidays_obj=None)[source]
adjust_follow(holidays_obj=None)[source]
adjust_imm(holidays_obj=None)[source]
adjust_mod_follow(holidays_obj=None)[source]
adjust_mod_previous(holidays_obj=None)[source]
adjust_previous(holidays_obj=None)[source]
adjust_start_of_month(holidays_obj=None)[source]
class businessdate.BusinessSchedule(start, end, step, roll=None)[source]

Bases: businessdate.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]
last_stub_long()[source]
businessdate.DATE_FORMAT = '%Y%m%d'

string – basic date format as string

businessdate.DEFAULT_HOLIDAYS = []

list – list of dates of default holiday calendar

businessdate.easter(year)[source]

This method was ported from the work done by GM Arts, on top of the algorithm by Claus Tondering, which was based in part on the algorithm of Ouding (1940), as quoted in “Explanatory Supplement to the Astronomical Almanac”, P. Kenneth Seidelmann, editor.

More about the algorithm may be found at:

http://users.chariot.net.au/~gmarts/eastalg.htm

and

http://www.tondering.dk/claus/calendar.html

businessdate.target_days(year)[source]

Base Object Classes

class basedate.BaseDate[source]

Bases: basedate.BaseDateFloat

base class for BusinessDate

class basedate.BaseDateFloat[source]

Bases: float

static add_days(d, days_int)[source]

adds number of days to a date :param BaseDateFloat d: date to add days to :param int days_int: number of days to add :return BaseDate: resulting date

static add_years(d, years_int)[source]

adds number of years to a date :param BaseDateFloat d: date to add years to :param int years_int: number of years to add :return BaseDate: resulting date

day

day of date :return int:

static diff_in_days(start, end)[source]

returns distance of two dates as number of days :param BaseDateFloat start: start date :param BaseDateFloat end: end date :return float: difference between end date and start date in days

static diff_in_years(start, end)[source]

calculate difference between given dates in years. The difference corresponds to Act/365.25 year fraction

Parameters:
Return float:

difference between end date and start date in years

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

creates date for year, month and day :param int year: :param int month: :param int day: :return BaseDate:

month

month of date :return int:

static to_ymd(d)[source]

returns date represented as tuple year, month, day :param BaseDateFloat d: :return tuple(int, int, int):

year

year of date :return int:

class basedate.BaseDatetimeDate[source]

Bases: datetime.date

static add_days(d, days_int)[source]

addition of a number of days

Parameters:
Return BaseDatetimeDate:
 
static add_years(d, years_int)[source]

addition of a number of years

Parameters:
Return BaseDatetimeDate:
 
static diff_in_days(start, end)[source]

calculate difference between given dates in days

Parameters:
Return float:

difference between end date and start date in days

static diff_in_years(start, end)[source]

calculate difference between given dates in years. The difference corresponds to Act/365.25 year fraction

Parameters:
Return float:

difference between end date and start date in years

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

converts date as (year, month, day) tuple into Microsoft Excel representation style

Parameters:int, int) (tuple(int,) – int tuple year, month, day
Return BaseDatetimeDate:
 
static to_ymd(d)[source]

returns date represented as tuple year, month, day :param BaseDatetimeDate d: :return tuple(int, int, int):

basedate.DAYS_IN_YEAR = 365.25

float – basis for diff_in_years method

basedate.days_in_month(year, month)[source]

returns number of days for the given year and month

Parameters:
  • year (int) – calendar year
  • month (int) – calendar month
Return int:
basedate.days_in_year(year)[source]

returns number of days in the given calendar year

Parameters:year (int) – calendar year
Return int:
basedate.from_excel_to_ymd(excel_int)[source]

converts date in Microsoft Excel representation style and returns (year, month, day) tuple

Parameters:excel_int (int) – date as int (days since 1899-12-31)
Return tuple(int, int, int):
 
basedate.from_ymd_to_excel(year, month, day)[source]

converts date as (year, month, day) tuple into Microsoft Excel representation style

Parameters:int, int) (tuple(int,) – int tuple year, month, day
Return int:
basedate.is_leap_year(year)[source]

returns True for leap year and False otherwise

Parameters:year (int) – calendar year
Return bool:
basedate.is_valid_ymd(year, month, day)[source]

return True if (year,month, day) can be represented in Excel-notation (number of days since 30.12.1899) for calendar days, otherwise False

Parameters:
  • year (int) – calendar year
  • month (int) – calendar month
  • day (int) – calendar day
Return bool:
class baseperiod.BasePeriod[source]

Bases: object

class baseperiod.BasePeriodFloat[source]

Bases: float

class baseperiod.BasePeriodTimedelta[source]

Bases: datetime.timedelta

baseperiod.set_base_period(mode='float')[source]