.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/time_value/compounding/plot_03_bernoulli_continuous_compounding.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_compounding_plot_03_bernoulli_continuous_compounding.py: Bernoulli and continuous compounding ==================================== In 1683 Jacob Bernoulli asked what a sum lent at interest becomes if the interest is added not yearly but half-yearly, monthly, daily, at every instant. At 100% a year, 1 grows to :math:`(1 + 1/m)^m` with ``m`` compounding periods, which increases with ``m`` but stays bounded; he showed the limit lies between 2.5 and 3. The limit is :math:`e`, and continuous compounding, :math:`e^{rt}`, is the convention financialkit uses by default. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.time_value import equivalent_rate, future_value, plot_compounding_growth .. GENERATED FROM PYTHON SOURCE LINES 21-23 Approaching e ------------- .. GENERATED FROM PYTHON SOURCE LINES 23-28 .. code-block:: Python for m in (1, 2, 4, 12, 52, 365, 8760): print(f"m = {m:5d}: {future_value(1.0, 1.0, 1.0, m):.6f}") print(f"continuous: {future_value(1.0, 1.0, 1.0):.6f} (e = {np.e:.6f})") .. rst-class:: sphx-glr-script-out .. code-block:: none m = 1: 2.000000 m = 2: 2.250000 m = 4: 2.441406 m = 12: 2.613035 m = 52: 2.692597 m = 365: 2.714567 m = 8760: 2.718127 continuous: 2.718282 (e = 2.718282) .. GENERATED FROM PYTHON SOURCE LINES 29-33 Equivalent rates ---------------- The continuously compounded rate giving the same growth as 100% annual interest is ln 2. .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python print(f"100% annual = {equivalent_rate(1.0, 1, None):.4%} continuous") .. rst-class:: sphx-glr-script-out .. code-block:: none 100% annual = 69.3147% continuous .. GENERATED FROM PYTHON SOURCE LINES 37-39 Growth paths and the limit -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-51 .. code-block:: Python m = np.unique(np.logspace(0, 4, 60).astype(int)) fig, axes = plt.subplots(1, 2, figsize=(11, 4)) plot_compounding_growth(1.0, 1.0, compoundings=(1, 2, 4, 12, None), ax=axes[0]) axes[1].semilogx(m, [future_value(1.0, 1.0, 1.0, int(k)) for k in m], "o", ms=3, label="(1 + 1/m)^m") axes[1].axhline(np.e, color="k", ls="--", label="e") axes[1].set_xlabel("compounding periods per year, m") axes[1].set_ylabel("value after one year") axes[1].legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/time_value/compounding/images/sphx_glr_plot_03_bernoulli_continuous_compounding_001.png :alt: Compounding at 100% :srcset: /api/gallery/time_value/compounding/images/sphx_glr_plot_03_bernoulli_continuous_compounding_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.192 seconds) .. _sphx_glr_download_api_gallery_time_value_compounding_plot_03_bernoulli_continuous_compounding.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/compounding/plot_03_bernoulli_continuous_compounding.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_bernoulli_continuous_compounding.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_bernoulli_continuous_compounding.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_bernoulli_continuous_compounding.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_