Calendars

The Calendar can be built in three ways:

  • using the constructor Calendar passing the arguments

  • with the Calendar.load(name="<calendar name>") passing the name of a calendar delivered with the package (B3, ANBIMA, Actual) or calendars from pandas_market_calendar package

  • with the Calendar.load(filename="<calendar filename>") passing a file that describes a valid calendar

Calendars from file

The file describing the calendar is a text file with the weekdays and holidays that represents the nonworking days.

[1]:
! type Test.cal
Saturday
Sunday
2001-01-01
2002-01-01
2012-12-25
2013-01-01

Here Saturday and Sunday are nonworking week days and the other lines bring the holidays.

[2]:
from bizdays import Calendar

Calendar.load(filename='Test.cal')
[2]:
Calendar: Test
Start: 2001-01-01
End: 2013-01-01
Weekdays: Saturday, Sunday
Holidays: 4
Financial: True

Predefined Calendars

bizdays comes with some predefined calendars: ANBIMA, B3, Actual, that can be directly loaded by its names.

ANBIMA is the standard calendar used in the brazilian fixed income markets.

[3]:
Calendar.load("ANBIMA")
[3]:
Calendar: ANBIMA
Start: 2000-01-01
End: 2078-12-25
Weekdays: Saturday, Sunday
Holidays: 948
Financial: True

Actual is a calendar with no holiday and nonworking days.

[4]:
Calendar.load("Actual")
[4]:
Calendar: Actual
Start: 1970-01-01
End: 2071-01-01
Weekdays:
Holidays: 0
Financial: True

Calendars from pandas_market_calendars

The package `pandas_market_calendars <https://github.com/rsheftel/pandas_market_calendars>`__ comes with many predefined calendars.

[5]:
import pandas_market_calendars as mcal

mcal.get_calendar_names()
[5]:
['ASX',
 'BMF',
 'B3',
 'BSE',
 'NSE',
 'CFE',
 'CBOE_Futures',
 'CBOE_Equity_Options',
 'CBOE_Index_Options',
 'CME_Equity',
 'CBOT_Equity',
 'CME_Agriculture',
 'CBOT_Agriculture',
 'COMEX_Agriculture',
 'NYMEX_Agriculture',
 'CME_Rate',
 'CBOT_Rate',
 'CME_InterestRate',
 'CBOT_InterestRate',
 'CME_Bond',
 'CBOT_Bond',
 'CMEGlobex_Livestock',
 'CMEGlobex_Live_Cattle',
 'CMEGlobex_Feeder_Cattle',
 'CMEGlobex_Lean_Hog',
 'CMEGlobex_Port_Cutout',
 'CME Globex Cryptocurrencies',
 'CME Globex Crypto',
 'CMEGlobex_EnergyAndMetals',
 'CMEGlobex_Energy',
 'CMEGlobex_CrudeAndRefined',
 'CMEGlobex_NYHarbor',
 'CMEGlobex_HO',
 'HO',
 'CMEGlobex_Crude',
 'CMEGlobex_CL',
 'CL',
 'CMEGlobex_Gas',
 'CMEGlobex_RB',
 'RB',
 'CMEGlobex_MicroCrude',
 'CMEGlobex_MCL',
 'MCL',
 'CMEGlobex_NatGas',
 'CMEGlobex_NG',
 'NG',
 'CMEGlobex_Dutch_NatGas',
 'CMEGlobex_TTF',
 'TTF',
 'CMEGlobex_LastDay_NatGas',
 'CMEGlobex_NN',
 'NN',
 'CMEGlobex_CarbonOffset',
 'CMEGlobex_CGO',
 'CGO',
 'C-GEO',
 'CMEGlobex_NGO',
 'NGO',
 'CMEGlobex_GEO',
 'GEO',
 'CMEGlobex_Metals',
 'CMEGlobex_PreciousMetals',
 'CMEGlobex_Gold',
 'CMEGlobex_GC',
 'GC',
 'CMEGlobex_SilverCMEGlobex_SI',
 'SI',
 'CMEGlobex_Platinum',
 'CMEGlobex_PL',
 'PL',
 'CMEGlobex_BaseMetals',
 'CMEGlobex_Copper',
 'CMEGlobex_HG',
 'HG',
 'CMEGlobex_Aluminum',
 'CMEGlobex_ALI',
 'ALI',
 'CMEGlobex_QC',
 'QC',
 'CMEGlobex_FerrousMetals',
 'CMEGlobex_HRC',
 'HRC',
 'CMEGlobex_BUS',
 'BUS',
 'CMEGlobex_TIO',
 'TIO',
 'CME Globex Equity',
 'CMEGlobex_FX',
 'CME_FX',
 'CME_Currency',
 'CME Globex Fixed Income',
 'CME Globex Interest Rate Products',
 'EUREX',
 'HKEX',
 'ICE',
 'ICEUS',
 'NYFE',
 'NYSE',
 'stock',
 'NASDAQ',
 'BATS',
 'DJIA',
 'DOW',
 'IEX',
 'Investors_Exchange',
 'JPX',
 'LSE',
 'OSE',
 'SIFMAUS',
 'SIFMA_US',
 'Capital_Markets_US',
 'Financial_Markets_US',
 'Bond_Markets_US',
 'SIFMAUK',
 'SIFMA_UK',
 'Capital_Markets_UK',
 'Financial_Markets_UK',
 'Bond_Markets_UK',
 'SIFMAJP',
 'SIFMA_JP',
 'Capital_Markets_JP',
 'Financial_Markets_JP',
 'Bond_Markets_JP',
 'SIX',
 'SSE',
 'TASE',
 'TSX',
 'TSXV',
 'AIXK',
 'ASEX',
 'BVMF',
 'CMES',
 'IEPA',
 'XAMS',
 'XASX',
 'XBKK',
 'XBOG',
 'XBOM',
 'XBRU',
 'XBSE',
 'XBUD',
 'XBUE',
 'XCBF',
 'XCSE',
 'XDUB',
 'XFRA',
 'XETR',
 'XHEL',
 'XHKG',
 'XICE',
 'XIDX',
 'XIST',
 'XJSE',
 'XKAR',
 'XKLS',
 'XKRX',
 'XLIM',
 'XLIS',
 'XLON',
 'XMAD',
 'XMEX',
 'XMIL',
 'XMOS',
 'XNYS',
 'XNZE',
 'XOSL',
 'XPAR',
 'XPHS',
 'XPRA',
 'XSAU',
 'XSES',
 'XSGO',
 'XSHG',
 'XSTO',
 'XSWX',
 'XTAE',
 'XTAI',
 'XTKS',
 'XTSE',
 'XWAR',
 'XWBO',
 'us_futures',
 '24/7',
 '24/5']

These calendars can be loaded in bizdays with the prefix PMC/ in its name. For example, use PMC/NYSE to load the NYSE calendar.

[6]:
Calendar.load("PMC/NYSE")
[6]:
Calendar: PMC/NYSE
Start: 1885-01-01
End: 2200-12-25
Weekdays: Saturday, Sunday
Holidays: 3552
Financial: True

Create your own Calendars

Calendar can be called with no arguments and it returns a calendar without nonworking days.

[4]:
Calendar()
[4]:
Calendar: None
Start: 1970-01-01
End: 2071-01-01
Weekdays:
Holidays: 0
Financial: True

Naming the calendar is a good idea.

[5]:
Calendar(name='actual')
[5]:
Calendar: actual
Start: 1970-01-01
End: 2071-01-01
Weekdays:
Holidays: 0
Financial: True

Financial Calendars

bizdays was designed to be used with financial calculations, for this reason all calendars are financial by default.

In finance, the amount of business days between two consecutive dates is 1, which indicates one day of compounding interest rates.

For example.

[6]:
cal = Calendar()
cal.bizdays('2021-01-01', '2021-01-02')
[6]:
1

For this calendar both dates are business days, but the return is one business day.

This behavior can changed by setting the attribute financial to False.

[7]:
cal.financial = False
cal.bizdays('2021-01-01', '2021-01-02')
[7]:
2