.. 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_01_pacioli_rule_of_72.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_01_pacioli_rule_of_72.py: Pacioli's rule of 72 ==================== Luca Pacioli's *Summa de arithmetica* (1494) gives, without proof, a rule for how long money takes to double: divide 72 by the annual interest rate in percent. The exact doubling time with annual compounding is :math:`\ln 2 / \ln(1 + r)`, and since :math:`\ln(1 + r) \approx r - r^2/2` the best constant drifts upward with the rate; 72 is close to right near 8% and has many convenient divisors. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.time_value import doubling_time, rule_of_72 .. GENERATED FROM PYTHON SOURCE LINES 20-22 The rule against the exact answer --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python for r in (0.02, 0.06, 0.08, 0.12, 0.24): print(f"{r:5.0%}: rule {rule_of_72(r):6.2f} years, exact {doubling_time(r, compounding=1):6.2f} years") .. rst-class:: sphx-glr-script-out .. code-block:: none 2%: rule 36.00 years, exact 35.00 years 6%: rule 12.00 years, exact 11.90 years 8%: rule 9.00 years, exact 9.01 years 12%: rule 6.00 years, exact 6.12 years 24%: rule 3.00 years, exact 3.22 years .. GENERATED FROM PYTHON SOURCE LINES 27-31 Relative error of the rules of 69.3, 70 and 72 ----------------------------------------------- 69.3 is exact for continuous compounding; with annual compounding a larger constant is better. .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: Python r = np.linspace(0.01, 0.30, 300) exact = doubling_time(r, compounding=1) fig, ax = plt.subplots(figsize=(7, 4.5)) for c in (69.3, 70.0, 72.0): ax.plot(100 * r, 100 * (rule_of_72(r, numerator=c) / exact - 1), label=f"rule of {c:g}") ax.axhline(0.0, color="k", lw=0.8) ax.set_xlabel("annual rate (%)") ax.set_ylabel("error vs exact doubling time (%)") ax.set_title("Pacioli's rule of 72") ax.legend() plt.show() .. image-sg:: /api/gallery/time_value/compounding/images/sphx_glr_plot_01_pacioli_rule_of_72_001.png :alt: Pacioli's rule of 72 :srcset: /api/gallery/time_value/compounding/images/sphx_glr_plot_01_pacioli_rule_of_72_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.031 seconds) .. _sphx_glr_download_api_gallery_time_value_compounding_plot_01_pacioli_rule_of_72.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_01_pacioli_rule_of_72.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_pacioli_rule_of_72.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_pacioli_rule_of_72.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_pacioli_rule_of_72.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_