Skip to content

Commit

Permalink
Add code style consistency changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyas Srinivasan committed Feb 23, 2022
1 parent b004e18 commit 7bd6982
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/fixedincome/bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def coupon_dates(settlement : datetime.date, maturity : datetime.date, frequency
_coupon_dates = [maturity]

# Calculate length of coupon period in months
coupon_period = dateutil.relativedelta.relativedelta(months=-MONTHS_IN_YEAR//frequency)
coupon_period = dateutil.relativedelta.relativedelta(months=-MONTHS_IN_YEAR // frequency)

# Calculate coupon dates backwards from maturity to issuance
while _coupon_dates[-1] > settlement:
Expand Down Expand Up @@ -183,6 +183,6 @@ def yield_(settlement : datetime.date, maturity : datetime.date, rate : float, p
# Special case for when no remaining coupons to be paid (only principal)
if len(_coupon_dates) <= 2:
_day_count_factor = day_count_factor(start=issue, end=settlement, basis=basis, next_=first_interest, freq=frequency)
return ((redemption/100 + rate/frequency) - (_PAR/100 + (_day_count_factor * rate))) / (_PAR/100 + (_day_count_factor * rate)) * (frequency / (1 - _day_count_factor * frequency))
return ((redemption / 100 + rate / frequency) - (_PAR / 100 + (_day_count_factor * rate))) / (_PAR / 100 + (_day_count_factor * rate)) * (frequency / (1 - _day_count_factor * frequency))
else: # Use optimization to identify the yield that matches quoted clean price
return scipy.optimize.newton(func=lambda y : price(settlement=settlement, maturity=maturity, rate=rate, yld=y, redemption=redemption, frequency=frequency, basis=basis) - price_, x0=rate, tol=0.0000001, maxiter=100)
10 changes: 5 additions & 5 deletions src/fixedincome/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def pv(rate_ : float, nper : int, pmt : float, fv_ : float = 0, type_ : int = 0)
"""

if rate != 0:
_pv = -(pmt*(1 + rate_*type_)*(((1 + rate_)**nper - 1)/rate_) + fv_)/((1 + rate_)**nper)
_pv = -(pmt*(1 + rate_ * type_)*(((1 + rate_)**nper - 1)/rate_) + fv_)/((1 + rate_)**nper)
else:
_pv = -(pmt*nper + fv_)
_pv = -(pmt * nper + fv_)

return _pv

Expand Down Expand Up @@ -143,9 +143,9 @@ def fv(rate_ : float, nper : int, pmt : float, pv_ : float = 0, type_ : int = 0)
"""

if rate_ != 0:
_fv = -(pv_*(1 + rate_)**nper + pmt*(1 + rate_*type_)*(((1 + rate_)**nper - 1)/rate_))
_fv = -(pv_ * (1 + rate_)**nper + pmt * (1 + rate_*type_) * (((1 + rate_)**nper - 1)/rate_))
else:
_fv = -(pmt*nper + pv_)
_fv = -(pmt * nper + pv_)

return _fv

Expand Down Expand Up @@ -180,7 +180,7 @@ def day_count_factor(start : datetime.date, end : datetime.date, basis : int = 0
Returns
-------
float
The day count factor, or percentage of interest that has linearly accrued, for the interest payment period.
The day count factor, or percentage of annual interest that has linearly accrued, for the interest payment period.
"""

# Switch calculation methodology by specified basis
Expand Down

0 comments on commit 7bd6982

Please sign in to comment.