Skip to main content

Functions to handle business days calculations

Project description

That version has been completely rewritten and many functions have been redesigned and became slightly different from the earlier version.

In several countries and markets, to account the value of financial instruments, mainly bonds and derivatives, it is necessary the use of different rules to compute the way the days go by. Those rules are related to holidays which are intrinsically related to counties and local markets. Usually you have a list with the holidays and all you want is to find out the number of business days between two dates, nothing more. It is necessary for pricing properly the financial instrument. bizdays was implemented to do that, compute business days between two dates and other collateral effects like adjust a given date for the next or previous business day, and so forth. bizdays is a module without dependencies, what makes it appropriate for simple implementations.

bizdays is a small set of functions to help with calculations which make use of business days. It works based on a list of holidays which is passed as an argument. Its interface is simple and flexible operating on vector of dates. bizdays can be fairly used for fixed income calculations. Many countries make intense use of business days to price financial instruments, like bonds and derivatives.


>>> from bizdays import Calendar, load_holidays
>>> holidays = load_holidays('Brazil.txt') # Brazilian financial market holidays
>>> cal = Calendar(holidays, ['Sunday', 'Saturday'], name='Brazil')
>>> cal
Calendar: Brazil
Start: 2000-01-01
End: 2078-12-25
Holidays: 948

>>> cal.isbizday('2014-01-12')

>>> cal.isbizday('2014-01-13')

>>> cal.bizdays('2014-01-13', '2015-01-13')

>>> cal.adjust_next('2015-12-25'), 12, 28)

>>> cal.adjust_next('2015-12-28'), 12, 28)

>>> cal.adjust_previous('2014-01-01'), 12, 31)

>>> cal.adjust_previous('2014-01-02'), 1, 2)

>>> cal.seq('2014-01-02', '2014-01-07')
<generator object seq at 0x1092b02d0>

>>> list(cal.seq('2014-01-02', '2014-01-07'))
[, 1, 2),, 1, 3),, 1, 6),, 1, 7)]

>>> cal.offset('2014-01-02', 5), 1, 9)

>>> cal.getdate('15th day', 2002, 5), 5, 15)

>>> cal.getdate('15th bizday', 2002, 5), 5, 22)

>>> cal.getdate('last wed', 2002, 5), 5, 29)

>>> cal.getdate('first fri before last day ', 2002, 5), 5, 24)

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
bizdays-v0.2.0.tar.gz (7.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page