Project Documentation
date class to perform calculations coming from financial businesses |
|
|
class for 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:
BaseDateDatetimeDatedate class to perform calculations coming from financial businesses
- Parameters:
year – number of year or some other input value t o create
BusinessDateinstance. When applying other input, this can be eitherint,float,datetime.dateorstringwhich will be parsed and transformed into equivalenttupleofintitems (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
- soy()
returns the day of the start of the year as BusinessDate
- eoy()
returns the day of the end of the year as BusinessDate
- soq()
returns the day of the start of the quarter as BusinessDate
- eoq()
returns the day of the end of the quarter as BusinessDate
- som()
returns the day of the start of the month as BusinessDate
- eom()
returns the day of the end of the month as BusinessDate
- 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
BusinessPeriodobject or anythings that create one and returnsBusinessDateobject.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
BusinessDatein 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.To get the year fraction for a day count convention provide one of the following convention key words:
30_360implements 30/360 Day Count Convention.30360implements 30/360 Day Count Convention.thirty360implements 30/360 Day Count Convention.30e_360implements the 30E/360 Day Count Convention.30e360implements the 30E/360 Day Count Convention.thirtye360implements the 30E/360 Day Count Convention.30e_360_iimplements the 30E/360 Italian Day Count Convention.30e360iimplements the 30E/360 Italian Day Count Convention.thirtye360iimplements the 30E/360 Italian Day Count Convention.act_360implements Act/360 day count convention.act360implements Act/360 day count convention.act_365implements Act/365 day count convention.act365implements Act/365 day count convention.act_36525implements Act/365.25 Day Count Conventionact_365.25implements Act/365.25 Day Count Conventionact36525implements Act/365.25 Day Count Conventionact_actimplements Act/Act day count convention.actactimplements 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
- yf(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
BusinessDateif 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.conventionsIn order to adjust according a business day convention provide one of the following convention key words:
nodoes no adjustment.previousadjusts to Business Day Convention “Preceding”.prevadjusts to Business Day Convention “Preceding”.prvadjusts to Business Day Convention “Preceding”.mod_previousadjusts to Business Day Convention “Modified Preceding”.modpreviousadjusts to Business Day Convention “Modified Preceding”.modprevadjusts to Business Day Convention “Modified Preceding”.modprvadjusts to Business Day Convention “Modified Preceding”.followadjusts to Business Day Convention “Following”.flwadjusts to Business Day Convention “Following”.modifiedadjusts to Business Day Convention “Modified [Following]”.mod_followadjusts to Business Day Convention “Modified [Following]”.modfollowadjusts to Business Day Convention “Modified [Following]”.modflwadjusts to Business Day Convention “Modified [Following]”.start_of_monthadjusts to Business Day Convention “Start of month”, i.e. first business day.startofmonthadjusts to Business Day Convention “Start of month”, i.e. first business day.somadjusts to Business Day Convention “Start of month”, i.e. first business day.end_of_monthadjusts to Business Day Convention “End of month”, i.e. last business day.endofmonthadjusts to Business Day Convention “End of month”, i.e. last business day.eomadjusts to Business Day Convention “End of month”, i.e. last business day.immadjusts to Business Day Convention of IMM, i.e. “International Monetary Market”.cds_immadjusts to Business Day Convention “Single Name CDS”.cdsimmadjusts to Business Day Convention “Single Name CDS”.cdsadjusts to Business Day Convention “Single Name CDS”.
- convention
- holidays
- origin
- day_count
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:
floatnative 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, origin=None)[source]
Bases:
objectclass for 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
intfollowed 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.
- MAXITER = 1000000
- origin
- property years
- property months
- property days
- property businessdays
BusinessSchedule
- class businessdate.businessschedule.BusinessSchedule(start, end, step, roll=None)[source]
Bases:
BusinessRangeclass 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:
BusinessDateListclass 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
businessdate.businessrange.BusinessRangefollowing given conventionFor details of adjusting
BusinessDateseeBusinessDate.adjust().For possible conventions invoke
BusinessDate().adjust()For more details on the conventions see module
conventions)
BusinessHolidays
- class businessdate.businessholidays.TargetHolidays(iterable=())[source]
Bases:
BusinessHolidaysholiday 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:
listholiday calendar class
A
businessdate.businessholidays.BusinessHolidaysinstance imitated a list ofdatetime.datewhich can be used to check if aBusinessDateis included as holiday.For convenience input need not tobe of type
datetime.date. Duck typing is enough, i.e. having properties year, month and day.
Convention Functions
Day Count
- businessdate.daycount.get_30_360b(start, end)[source]
implements 30/360 Bond Basis Count Convention.
- businessdate.daycount.get_30e_360b(start, end)[source]
implements the 30E/360 Bond Basis Day Count Convention.
- businessdate.daycount.get_30e_360g(start, end)[source]
implements the 30E/360 German Day Count Convention.
- businessdate.daycount.get_30e_360i(start, end)[source]
implements the 30E/360 Italian Day Count Convention.
- businessdate.daycount.get_act_act_isda(start, end)[source]
implements Act/Act day count convention as defined by ISDA.
- businessdate.daycount.get_act_act_bond(start, end)[source]
implements Act/Act day count convention known as bond basis.
- class businessdate.daycount.icma(frequency=1, rolling=None)[source]
Bases:
objectimplements ICMA day count conventions.
- Parameters:
frequency – coupon frequency. Either integer 1, 2, 4, 12 or string starting with ‘a’, ‘s’, ‘q’, ‘m’ (optional: default is 1)
rolling – rolling date for reference periods (optional: default is None, i.e. rolling date will be coupon end date )
>>> from businessdate import BusinessDate >>> today = BusinessDate() >>> from businessdate.daycount import icma >>> yf = icma(2)
>>> s, e = today, today + '12m' >>> yf.get_act_act(s, e) 1.0
>>> yf.get_30_360(s, e) 1.0
>>> s, e = today, today + '9m' >>> icma(4).get_act_act(s, e) 0.75
>>> icma().get_30_360(s, e) 0.75
- businessdate.daycount.get_act_act_icma(start, end, *, frequency=None, rolling=None)[source]
implements Act/Act day count convention as defined by ICMA/ISMA.
- businessdate.daycount.get_act_act_euro(start, end)[source]
implements Act/Act day count convention known as euro bond.
- businessdate.daycount.get_act_act_hist(start, end)[source]
implements Act/Act day count convention known as historical.
- businessdate.daycount.get_act_act_365(start, end)[source]
implements Act/Act day count convention known as 365 basis.
- businessdate.daycount.get_act_act_afb(start, end)[source]
implements Act/Act day count convention as defined by AFB.
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.