Project Documentation¶
date class to perform calculations coming from financial businesses |
|
|
class to store and calculate date periods as combinations of days, weeks, years etc. |
|
class to build list of business days |
|
class to build date schedules incl start and end date |
|
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 eitherint
,float
,datetime.date
orstring
which will be parsed and transformed into equivalenttuple
ofint
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
- 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 returnsBusinessDate
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
- 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 Conventionact_365.25
implements Act/365.25 Day Count Conventionact36525
implements Act/365.25 Day Count Conventionact_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¶
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 achar
- 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
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
start (BusinessDate) – start date of schedule
end (BusinessDate) – end date of schedule
step (BusinessPeriod) – period distance of two dates
roll (BusinessDate) – origin of schedule
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.
- 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 conventionFor details of adjusting
BusinessDate
seeBusinessDate.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 ofdatetime.date
which can be used to check if aBusinessDate
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¶
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_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.