Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bond.py to allow to define the BusDayAdjustTypes and DateGenRu… #154

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions financepy/products/bonds/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ def __init__(self,
freq_type: FrequencyTypes,
accrual_type: DayCountTypes,
face_amount: float = 100.0,
calendar_type: CalendarTypes = CalendarTypes.WEEKEND):
calendar_type: CalendarTypes = CalendarTypes.WEEKEND,
bus_day_rule_type: BusDayAdjustTypes =BusDayAdjustTypes.FOLLOWING,
date_gen_rule_type: DateGenRuleTypes = DateGenRuleTypes.BACKWARD):

""" Create Bond object by providing the issue date, maturity Date,
coupon frequency, annualised coupon, the accrual convention type, face
amount and the number of ex-dividend days. A calendar type is used
to determine holidays from which coupon dates might be shifted."""
to determine holidays from which coupon dates might be shifted.
BusDayAdjustTypes are used to calculate the actual payment dates.
DateGenRuleTypes are used to calculate coupon dates either from backward
from the maturity dates or forward from the issue date.
"""

check_argument_types(self.__init__, locals())

Expand All @@ -125,6 +132,9 @@ def __init__(self,
self._par = 100.0 # This is how price is quoted and amount at maturity
self._redemption = 1.0 # This is amount paid at maturity
self._calendar_type = calendar_type

self._bus_day_rule_type = bus_day_rule_type
self._date_gen_rule_type = date_gen_rule_type

self._coupon_dates = []
self._payment_dates = [] # Actual payment dates are adjusted
Expand All @@ -145,16 +155,13 @@ def _calculate_coupon_dates(self):
weekend or holiday.
"""

# This should only be called once from init
bus_day_rule_type = BusDayAdjustTypes.FOLLOWING
date_gen_rule_type = DateGenRuleTypes.BACKWARD

self._coupon_dates = Schedule(self._issue_date,
self._maturity_date,
self._freq_type,
CalendarTypes.NONE,
bus_day_rule_type,
date_gen_rule_type)._generate()
self._bus_day_rule_type,
self._date_gen_rule_type)._generate()

###########################################################################

Expand Down
11 changes: 11 additions & 0 deletions financepy/products/inflation/FinInflationBond.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def __init__(self,
base_cpi_value: float,
num_ex_dividend_days: int = 0,
calendar_type: CalendarTypes = CalendarTypes.NONE): # Value of CPI index at bond issue date

super().__init__(issue_date: Date,
maturity_date: Date,
coupon: float, # Annualised bond coupon
freq_type: FrequencyTypes,
accrual_type: DayCountTypes,
face_amount: float,
calendar_type: CalendarTypes = CalendarTypes.NONE,
bus_day_rule_type: BusDayAdjustTypes =BusDayAdjustTypes.FOLLOWING,
date_gen_rule_type: DateGenRuleTypes = DateGenRuleTypes.BACKWARD) #since we have overriden parent methods, we need to call super so that parent methods are available here

""" Create FinInflationBond object by providing Maturity, Frequency,
coupon, frequency and the accrual convention type. You must also supply
the base CPI used for all coupon and principal related calculations.
Expand Down