Skip to content

Commit

Permalink
update README.rst to work as long_description
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntagsgesicht committed Oct 10, 2020
1 parent b346db3 commit ca25caf
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 20 deletions.
92 changes: 92 additions & 0 deletions HOWTO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,101 @@ Cashflow Objects and Valuation
Payment Plans
-------------

>>> from businessdate import BusinessDate, BusinessSchedule

>>> today = BusinessDate(20201031)

>>> schedule = BusinessSchedule(today, today + "8q", step="1q")
>>> schedule
[BusinessDate(20201031), BusinessDate(20210131), BusinessDate(20210430), BusinessDate(20210731), BusinessDate(20211031), BusinessDate(20220131), BusinessDate(20220430), BusinessDate(20220731), BusinessDate(20221031)]

To build payment plans for, e.g. annuity loans, pick a plan function
and generate an redemption amount list for paying back the loan notional amount.

.. doctest::

>>> from dcf import annuity, outstanding

>>> number_of_payments = 8
>>> interest_rate = 0.02
>>> notional = 1000.

>>> plan = annuity(number_of_payments, amount=notional, fixed_rate=interest_rate)
>>> plan
[116.50979913376267, 118.83999511643792, 121.21679501876667, 123.64113091914203, 126.11395353752485, 128.63623260827535, 131.20895726044085, 133.83313640564967]


>>> sum(plan)
1000.0

>>> out = outstanding(plan, amount=notional)
>>> out
[1000.0, 883.4902008662373, 764.6502057497994, 643.4334107310327, 519.7922798118907, 393.6783262743659, 265.0420936660905, 133.83313640564967]

>>> compound = [o * interest_rate + p for o, p in zip(out, plan)]
>>> compound
[136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267]

CashFlowList Objects
--------------------

Putting all together and feeding the plan into a `FixedCashFlowList
and the list of outstanding into a `RateCashflowList` gives the legs of a loan.

.. doctest::

>>> from businessdate import BusinessDate, BusinessSchedule
>>> from dcf import amortize, outstanding
>>> from dcf import FixedCashFlowList, RateCashFlowList

Again, build a date schedule.

.. doctest::

>>> today = BusinessDate(20201031)

>>> schedule = BusinessSchedule(today, today + "8q", step="1q")

>>> start_date, payment_dates = schedule[0], schedule[1:]

Fixing the properties of the product and rolling out the payment plan and list of notional outstanding.

.. doctest::

>>> number_of_payments = 8
>>> interest_rate = 0.01
>>> notional = 1000.

>>> plan = amortize(number_of_payments, amount=notional)
>>> out = outstanding(plan, amount=notional)

Finally, create for each leg a |CashFlowList|.

.. doctest::

>>> principal = FixedCashFlowList([start_date], [-notional], origin=start_date)
>>> print(principal)
FixedCashFlowList([BusinessDate(20201031) ... BusinessDate(20201031)], [-1000.0 ... -1000.0], origin=BusinessDate(20201031), day_count=day_count)

>>> redemption = FixedCashFlowList(payment_dates, plan, origin=start_date)
>>> print(redemption)
FixedCashFlowList([BusinessDate(20210131) ... BusinessDate(20221031)], [125.0 ... 125.0], origin=BusinessDate(20201031), day_count=day_count)

>>> interest = RateCashFlowList(payment_dates, out, origin=start_date, fixed_rate=interest_rate)
>>> print(interest)
RateCashFlowList([BusinessDate(20210131) ... BusinessDate(20221031)], [1000.0 ... 125.0], origin=BusinessDate(20201031), day_count=day_count)

Valuation
---------

Add those legs to |CashFlowLegList| provides a smart container for valuation (|get_present_value()|).

.. doctest::

>>> from dcf import CashFlowLegList, ZeroRateCurve, get_present_value

>>> loan = CashFlowLegList([principal, redemption, interest])
>>> curve = ZeroRateCurve([today, today + '2y'], [-.005, .01])
>>> pv = get_present_value(cashflow_list=loan, discount_curve=curve, valuation_date=today)
>>> pv
4.935421637918779
30 changes: 12 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ discounting and fx.
Example Usage
-------------

.. testsetup::

from datetime import date
from businessdate import BusinessDate, BusinessSchedule
from dcf import *

.. doctest::
.. code-block:: python
>>> from datetime import date
>>> from dcf import ZeroRateCurve
Expand All @@ -92,7 +86,7 @@ The framework works fine with native `datetime <https://docs.python.org/3/librar
but we recommend `businessdate <https://pypi.org/project/businessdate/>`_ package
for more convenient functionality to roll out date schedules.

.. doctest::
.. code-block:: python
>>> from businessdate import BusinessDate, BusinessSchedule
Expand All @@ -105,7 +99,7 @@ for more convenient functionality to roll out date schedules.
To build payment plans for, e.g. annuity loans, pick a plan function
and generate an redemption amount list for paying back the loan notional amount.

.. doctest::
.. code-block:: python
>>> from dcf import annuity, outstanding
Expand All @@ -130,18 +124,18 @@ and generate an redemption amount list for paying back the loan notional amount.
[136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267, 136.50979913376267]
Putting all together and feeding the plan into a |FixedCashFlowList|
and the list of outstanding into a |RateCashflowList| gives the legs of a loan.
Putting all together and feeding the plan into a `FixedCashFlowList`
and the list of outstanding into a `RateCashflowList` gives the legs of a loan.

.. doctest::
.. code-block:: python
>>> from businessdate import BusinessDate, BusinessSchedule
>>> from dcf import amortize, outstanding
>>> from dcf import FixedCashFlowList, RateCashFlowList
Again, build a date schedule.

.. doctest::
.. code-block:: python
>>> today = BusinessDate(20201031)
Expand All @@ -151,7 +145,7 @@ Again, build a date schedule.
Fixing the properties of the product and rolling out the payment plan and list of notional outstanding.

.. doctest::
.. code-block:: python
>>> number_of_payments = 8
>>> interest_rate = 0.01
Expand All @@ -160,9 +154,9 @@ Fixing the properties of the product and rolling out the payment plan and list o
>>> plan = amortize(number_of_payments, amount=notional)
>>> out = outstanding(plan, amount=notional)
Finally, create for each leg a |CashFlowList|.
Finally, create for each leg a `CashFlowList`.

.. doctest::
.. code-block:: python
>>> principal = FixedCashFlowList([start_date], [-notional], origin=start_date)
>>> print(principal)
Expand All @@ -176,9 +170,9 @@ Finally, create for each leg a |CashFlowList|.
>>> print(interest)
RateCashFlowList([BusinessDate(20210131) ... BusinessDate(20221031)], [1000.0 ... 125.0], origin=BusinessDate(20201031), day_count=day_count)
Add those legs to |CashFlowLegList| provides a smart container for valuation (|get_present_value()|).
Add those legs to `CashFlowLegList` provides a smart container for valuation (`get_present_value()`).

.. doctest::
.. code-block:: python
>>> from dcf import CashFlowLegList, ZeroRateCurve, get_present_value
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# dcf
# ---
# A Python library for generating discounted cashflows.
#
#
# Author: sonntagsgesicht, based on a fork of Deutsche Postbank [pbrisk]
# Version: 0.3, copyright Saturday, 10 October 2020
# Website: https://github.com/sonntagsgesicht/dcf
Expand Down Expand Up @@ -32,7 +32,8 @@
scripts=pkg.__scripts__,
install_requires=pkg.__dependencies__,
dependency_links=pkg.__dependency_links__,
long_description='\n'+codecs.open('README.rst', encoding='utf-8').read(),
long_description='\n' + codecs.open('README.rst', encoding='utf-8').read(),
long_description_content_type='text/x-rst',
platforms='any',
classifiers=[
'Development Status :: ' + pkg.__dev_status__,
Expand Down

0 comments on commit ca25caf

Please sign in to comment.