API

Calendar

class bizdays.Calendar(holidays=[], weekdays=[], startdate=None, enddate=None, name=None, financial=True)

Calendar class

Calendar representation where holidays and nonworking weekdays are defined.

name
Type:

str

holidays
Type:

list of dates

enddate
Type:

date

startdate
Type:

date

weekdays
Type:

list of str

financial
Type:

bool

Parameters:
  • holidays (list with dates) – Dates can be ISO formated string, datetime.date or datetime.datetime.

  • weekdays (list) –

    A list with weekdays representing nonworking days.

    Accepts: ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’,

    ’Saturday’, ‘Sunday’

  • startdate (str or datetime.date) – Calendar’s start date

  • enddate (str or datetime.date) – Calendar’s end date

  • name (str) – Calendar’s name

  • financial (bool) – Defines a financial calendar

bizdays(date_from, date_to)

Calculate the amount of business days between two dates

Parameters:
  • date_from (datetime.date, datetime.datetime, pandas.Timestamp, str) – Start date

  • date_to (datetime.date, datetime.datetime, pandas.Timestamp, str) – End date

Returns:

The number of business days between date_from and date_to

Return type:

int, list, numpy.ndarray

diff(dts)

Compute the number of business days between dates in a given vector of dates.

Parameters:

dts (list of date) – Sequence containing the dates to be differenced.

Returns:

The number of business days between given dates.

Return type:

list of int

following(dt)

Adjusts the given dates to the next business day

Rolls the given date to the next business day, unless it is a business day.

Parameters:

dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be adjusted

Returns:

return the next business day if the given date is not a business day.

Return type:

datetime.date, datetime.datetime, pandas.Timestamp, str

getbizdays(year, month=None)

Business days in a specific year or month.

Parameters:
  • year (int, list of int) – Year

  • month (int, list of int) – Month

Returns:

Returns the number of business days in the given time span.

Return type:

int, list of int

getdate(expr, year, month=None)

Get dates using other dates (or month or year) as reference.

Imagine you have one date and want the first or last day of this date’s month. For example, you have the date 2018-02-01 and want the last day of its month. You have to check whether or not its year is a leap year, and this sounds a tough task. getdate helps with returning specific dates according to a reference than can be another date, a month or an year.

Parameters:
  • expr (str, list of str) –

    String specifying the date to be returned.

    See getdate for more information.

  • year (int, list of int) – Year

  • month (int, list of int) – Month

Returns:

Returns dates according to a reference that can be a month or an year.

Return type:

date, list of dates, pandas.DatetimeIndex

isbizday(dt)

Checks if the given dates are business days.

Parameters:

dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be checked

Returns:

Returns True if the given date is a business day and False otherwise.

Return type:

bool, list of bool, array of bool

classmethod load(name=None, filename=None)

Load calendars from a file.

Parameters:
  • name (str) –

    Name of the calendar. The calendar is loaded from a file delivered with the package. The calendars:

    • B3

    • ANBIMA

    • Actual

    • calendars from pandas_market_calendars - use the prefix “PMC/<calendar name>” to name the calendar

    are delivered with the package.

  • filename (str) – Text file with holidays and weekdays.

Returns:

A Calendar object.

Return type:

Calendar

modified_following(dt)

Adjusts the given dates to the next business day with a small difference.

Rolls the given date to the next business day, unless it happens in the next month, in this case it returns the previous business day.

Parameters:

dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be adjusted

Returns:

return the next business day if the given date is not a business day.

Return type:

datetime.date, datetime.datetime, pandas.Timestamp, str

modified_preceding(dt)

Adjusts the given dates to the previous business day with a small difference.

Rolls the given date to the previous business day, unless it happens in the previous month, in this case it returns the previous business day.

Parameters:

dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be adjusted

Returns:

return the previous business day if the given date is not a business day.

Return type:

datetime.date, datetime.datetime, pandas.Timestamp, str

offset(dt, n)

Offsets the given dates by n business days.

Parameters:
  • dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be offset

  • n (int, list of int) – the amount of business days to offset

Returns:

Returns the given dates offset by the given amount of n business days.

Return type:

date, list of dates, pandas.DatetimeIndex

preceding(dt)

Adjusts the given dates to the previous business day

Rolls the given date to the previous business day, unless it is a business day.

Parameters:

dt (datetime.date, datetime.datetime, pandas.Timestamp, str) – Dates to be adjusted

Returns:

return the previous business day if the given date is not a business day.

Return type:

datetime.date, datetime.datetime, pandas.Timestamp, str

seq(date_from, date_to)

Sequence of business days.

Parameters:
  • date_from (datetime.date, datetime.datetime, pandas.Timestamp, str) – Start date

  • date_to (datetime.date, datetime.datetime, pandas.Timestamp, str) – End date

Returns:

Returns a sequence of dates with business days only.

Return type:

list of dates, pandas.DatetimeIndex

options

bizdays.set_option(name, val)

sets option value

Parameters:
  • name (str) – option name

  • val (str) – option value

Return type:

No return

Options:

  • mode: accepts pandas and python (default). Pandas mode enable integration with pandas, check out pandas Integration for more information.

  • mode.datetype: specify the date type returned by Calendar’s methods that return dates (seq, following, preceding, …). Accepts date (default), datetime and iso for ISO formated strings. In pandas mode this option is ignored.

from bizdays import set_option
set_option('mode', 'pandas')
bizdays.get_option(name)

gets option value

Parameters:

name (str) – option name

Returns:

val – option value

Return type:

str

from bizdays import get_option
get_option('mode')