from bizdays import set_option, Calendar

set_option('mode', 'pandas')

"""
Explanation: pandas Integration
bizdays has a very handy integration with pandas DataFrame.
End of explanation
"""


cal = Calendar.load(filename='ANBIMA.cal')
cal

cal.isbizday(['2014-01-12', '2014-01-13'])

cal.bizdays('2014-01-13', ['2015-01-13', '2016-01-13', None])

cal.following('2015-12-25')

cal.following(['2015-12-28', '2015-12-25'])

cal.seq('2014-01-02', '2014-01-07')

cal.offset('2014-01-02', range(10))

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

cal.getdate('15th day', 2002, range(1, 13))

cal.getbizdays(2021, range(1, 13))

"""
Explanation: When the option mode is set to pandas the calendar methods will return

Timestamp instead of datetime.date
DatetimeIndex instead of lists of dates
numpy.ndarray instead of lists of integers (bizdays) and bools (isbizday)
End of explanation
"""


import pandas as pd

df = pd.DataFrame({
    'year': 2021,
    'month': range(1,13)
})
df

"""
Explanation: Example: series of payments
Let's create a series of payment dates and compute the business days between each payment date.
The payments are scheduled to occur in the 15th days of each month of 2021.
Start creating a DataFrame with year and month columns.
End of explanation
"""


df['payment_dates'] = cal.getdate('15th day', df['year'], df['month'])
df

"""
Explanation: Use getdate to get the payment dates.
End of explanation
"""


df['fixing'] = cal.following(df['payment_dates'])
df

"""
Explanation: The payments happen in business days so the dates must be shifted to the next working date.
End of explanation
"""


df['business_days'] = cal.bizdays(df['fixing'].shift(), df['fixing'])
df

"""
Explanation: bizdays compute the amount of business days between each payment.
End of explanation
"""


