.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/time_value/present_value/plot_01_fibonacci_present_value.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_time_value_present_value_plot_01_fibonacci_present_value.py: Fibonacci's present value: comparing payment schedules ====================================================== Chapter 12 of Fibonacci's *Liber Abaci* (1202) contains problems in which a sum is repaid in instalments at a fixed rate per period, and Fibonacci values each schedule by discounting every instalment back to the start (Goetzmann, 2005). The same idea in modern form: a lender is offered three ways to be repaid a loan of 100 bezants, and the one worth most today depends on the rate. Present value turns each schedule into a single number that can be compared. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.time_value import plot_cash_flows, present_value .. GENERATED FROM PYTHON SOURCE LINES 21-24 Three schedules --------------- Payments in bezants at the end of each year. .. GENERATED FROM PYTHON SOURCE LINES 24-34 .. code-block:: Python schedules = { "lump sum at year 5": ([0, 0, 0, 0, 160.0], np.arange(1, 6)), "level, 5 years": ([36.0] * 5, np.arange(1, 6)), "front-loaded": ([60.0, 45.0, 30.0, 20.0, 10.0], np.arange(1, 6)), } for name, (cf, t) in schedules.items(): pv = present_value(cf, t, 0.10, compounding=1) print(f"{name:20s} total {sum(cf):6.1f} PV at 10% = {pv:6.2f}") .. rst-class:: sphx-glr-script-out .. code-block:: none lump sum at year 5 total 160.0 PV at 10% = 99.35 level, 5 years total 180.0 PV at 10% = 136.47 front-loaded total 165.0 PV at 10% = 134.14 .. GENERATED FROM PYTHON SOURCE LINES 35-38 Which schedule wins depends on the rate --------------------------------------- At low rates the larger total wins; at high rates the earlier money wins. .. GENERATED FROM PYTHON SOURCE LINES 38-52 .. code-block:: Python rates = np.linspace(0.0, 0.25, 101) fig, axes = plt.subplots(1, 2, figsize=(11, 4)) for name, (cf, t) in schedules.items(): axes[1].plot(100 * rates, present_value(cf, t, rates, compounding=1), label=name) axes[1].axhline(100.0, color="k", ls="--", lw=0.8, label="amount lent") axes[1].set_xlabel("rate per year (%)") axes[1].set_ylabel("present value") axes[1].set_title("Present value of each schedule") axes[1].legend() plot_cash_flows(schedules["front-loaded"][0], schedules["front-loaded"][1], ax=axes[0], title="front-loaded schedule") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/time_value/present_value/images/sphx_glr_plot_01_fibonacci_present_value_001.png :alt: front-loaded schedule, Present value of each schedule :srcset: /api/gallery/time_value/present_value/images/sphx_glr_plot_01_fibonacci_present_value_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.064 seconds) .. _sphx_glr_download_api_gallery_time_value_present_value_plot_01_fibonacci_present_value.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/time_value/present_value/plot_01_fibonacci_present_value.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_fibonacci_present_value.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_fibonacci_present_value.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_fibonacci_present_value.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_