Skip to content

Commit

Permalink
fixed minor issues (created by auxilium)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntagsgesicht committed Jan 14, 2022
1 parent db83116 commit 4374417
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 22 deletions.
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ Example Usage

>>> from dcf import ZeroRateCurve

>>> ZeroRateCurve([0, 2], [.03, .05]).get_zero_rate(0, 1)
>>> time_grid = [0, 2]
>>> rate_grid = [.03, .05]

>>> ZeroRateCurve(time_grid, rate_grid).get_zero_rate(0, 1)
0.04

>>> ZeroRateCurve([0, 2], [.03, .05]).get_discount_factor(0, 1)
>>> ZeroRateCurve(time_grid, rate_grid).get_discount_factor(0, 1)
0.9607894391523232


Expand Down
6 changes: 3 additions & 3 deletions dcf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# A Python library for generating discounted cashflows.
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.6, copyright Wednesday, 22 December 2021
# Version: 0.6.1, copyright Tuesday, 11 January 2022
# Website: https://github.com/sonntagsgesicht/dcf
# License: Apache License 2.0 (see LICENSE file)


__doc__ = 'A Python library for generating discounted cashflows.'
__version__ = '0.6'
__version__ = '0.6.1'
__dev_status__ = '4 - Beta'
__date__ = 'Tuesday, 11 January 2022'
__date__ = 'Friday, 14 January 2022'
__author__ = 'sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]'
__email__ = 'sonntagsgesicht@icloud.com'
__url__ = 'https://github.com/sonntagsgesicht/' + __name__
Expand Down
6 changes: 3 additions & 3 deletions dcf/cashflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# A Python library for generating discounted cashflows.
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.6, copyright Wednesday, 22 December 2021
# Version: 0.6.1, copyright Tuesday, 11 January 2022
# Website: https://github.com/sonntagsgesicht/dcf
# License: Apache License 2.0 (see LICENSE file)

Expand Down Expand Up @@ -125,7 +125,7 @@ class FixedCashFlowList(CashFlowList):
@property
def table(self):
""" cashflow details as list of tuples """
header = [('cashflow', 'pay_date')]
header = [('cashflow', 'pay date')]
table = list((self[d], d,) for d in self.domain)
return header + table

Expand Down Expand Up @@ -206,7 +206,7 @@ def __init__(self, payment_date_list, amount_list=DEFAULT_AMOUNT,
$d_i = s_i - \epsilon$
for **pay_offset** $\delta$ and **fixing_offset** $\epsilon$,
$$cf_i = N_i \cdot \tau(s_i,e_i) \cdot c \cdot f(d_i).$$
$$cf_i = N_i \cdot \tau(s_i,e_i) \cdot (c + f(d_i)).$$
Note, the **pay_offset** $\delta$ is not applied
in case of the first cashflow, then $s_1=t_0$.
Expand Down
4 changes: 3 additions & 1 deletion dcf/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# A Python library for generating discounted cashflows.
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.6, copyright Wednesday, 22 December 2021
# Version: 0.6.1, copyright Tuesday, 11 January 2022
# Website: https://github.com/sonntagsgesicht/dcf
# License: Apache License 2.0 (see LICENSE file)

Expand All @@ -23,6 +23,8 @@

except ImportError:

BusinessDate = BusinessPeriod = None

today = 0.0
b = 1 / 365.25
d = 1 / 365.25
Expand Down
16 changes: 9 additions & 7 deletions dcf/pricer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# A Python library for generating discounted cashflows.
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.6, copyright Wednesday, 22 December 2021
# Version: 0.6.1, copyright Tuesday, 11 January 2022
# Website: https://github.com/sonntagsgesicht/dcf
# License: Apache License 2.0 (see LICENSE file)

Expand Down Expand Up @@ -174,17 +174,18 @@ def get_interest_accrued(cashflow_list, valuation_date):


def get_fair_rate(cashflow_list, discount_curve,
valuation_date=None, present_value=0.):
valuation_date=None, present_value=0., precision=1e-7):
r""" coupon rate to meet given value
:param cashflow_list: list of cashflows
:param discount_curve: discount factors are obtained from this curve
:param valuation_date: date to discount to
:param present_value: price to meet by discounting
:param precision: max distance of present value to par
:return: `float` - the fair coupon rate as
**fixed_rate** of a |RateCashFlowList()|
Let $cf_i(c) = N_i \cdot \tau(s_i,e_i) \cdot c \cdot f(d_i)$
Let $cf_i(c) = N_i \cdot \tau(s_i,e_i) \cdot (c + f(d_i))$
be the $i$-th cashflow in the **cashflow_list**.
Here, the fair rate is the fixed_rate $c=\hat{c}$ such that
Expand Down Expand Up @@ -212,18 +213,18 @@ def err(current):
return pv - present_value

# run bracketing
_, par, _ = _simple_bracketing(err, -0.1, .2, 1e-7)
_, par, _ = _simple_bracketing(err, -0.1, .2, precision)

# restore fixed rate
cashflow_list.fixed_rate = fixed_rate
return par


def get_par_rate(cashflow_list, discount_curve,
valuation_date=None, present_value=0.):
valuation_date=None, present_value=0., precision=1e-7):
""" same as |get_fair_rate()| """
return get_fair_rate(cashflow_list, discount_curve, valuation_date,
present_value)
present_value, precision)


def get_basis_point_value(cashflow_list, discount_curve, valuation_date=None,
Expand Down Expand Up @@ -375,7 +376,8 @@ def get_bucketed_delta(cashflow_list, discount_curve, valuation_date=None,

buckets = list()
for g, s in zip(grid, shifts):
shifted_curve = delta_curve + basis_point_curve_type(g, s)
shifted_curve = delta_curve + basis_point_curve_type(
g, s, forward_tenor=delta_curve.forward_tenor)
# todo: cashflow_list.payoff_model.forward_curve
fwd_curve = getattr(cashflow_list, 'forward_curve', None)
if fwd_curve == delta_curve:
Expand Down
12 changes: 6 additions & 6 deletions dcf/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# A Python library for generating discounted cashflows.
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.6, copyright Wednesday, 22 December 2021
# Version: 0.6.1, copyright Tuesday, 11 January 2022
# Website: https://github.com/sonntagsgesicht/dcf
# License: Apache License 2.0 (see LICENSE file)

Expand Down Expand Up @@ -39,7 +39,7 @@ def _interest_payment_dates(
else:
payment_date_list = [end_date]
cnt = 1
while start_date + period < payment_date_list[0]:
while start_date + period <= payment_date_list[0]:
payment_date_list.append(end_date - period * cnt)
cnt += 1
payment_date_list.reverse()
Expand All @@ -60,7 +60,7 @@ def bond(start_date=TODAY,
forward_curve=None,
fixing_offset=None,
pay_offset=None):
''' simple bond product
""" simple bond product
:param start_date: pay date of inital notional amount
:param end_date: rolling date for interest pay dates
Expand All @@ -79,7 +79,7 @@ def bond(start_date=TODAY,
interest period end date and interest payment date
:return: |CashFlowLegList|
'''
"""
interest_payment_date_list = _interest_payment_dates(
start_date, end_date, period, convention, holidays)

Expand Down Expand Up @@ -140,7 +140,7 @@ def interest_rate_swap(start_date=TODAY,
rec_leg_day_count='actact',
rec_leg_fixed_rate=0.0,
rec_leg_forward_curve=None):
''' plain vanilla swap
""" plain vanilla swap
:param start_date: pay date of inital notional amount
:param end_date: rolling date for interest pay dates
Expand Down Expand Up @@ -171,7 +171,7 @@ def interest_rate_swap(start_date=TODAY,
if not mentioned explicitly all arguments are applied to both legs,
pay and receive leg.
'''
"""

pay_leg_payment_date_list = _interest_payment_dates(
start_date, end_date,
Expand Down

0 comments on commit 4374417

Please sign in to comment.