.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/time_value/day_counts/plot_02_isda_actual_actual.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_day_counts_plot_02_isda_actual_actual.py: ISDA's actual/actual and the day-count zoo ========================================== When the euro replaced its legacy currencies, markets had to agree on how to count days. ISDA's 1998 memo *EMU and Market Conventions* set the competing "actual/actual" methods side by side; under the ISDA variant, the days falling in each calendar year are divided by that year's length, 365 or 366. Its example: November 1, 2003 to May 1, 2004 is 61/365 + 121/366 = 0.49772. This script compares that with the other conventions in :class:`~financialkit.constants.DayCount`. .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.constants import DayCount from financialkit.time_value import year_fraction .. GENERATED FROM PYTHON SOURCE LINES 22-24 ISDA's example under every convention ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python for dc in DayCount: print(f"{dc.value:13s} {year_fraction('2003-11-01', '2004-05-01', dc):.5f}") .. rst-class:: sphx-glr-script-out .. code-block:: none ACT/360 0.50556 ACT/365F 0.49863 30/360 US 0.50000 30E/360 0.50000 ACT/ACT ISDA 0.49772 .. GENERATED FROM PYTHON SOURCE LINES 29-32 Six-month periods through a leap year ------------------------------------- The same calendar period earns different interest under each convention. .. GENERATED FROM PYTHON SOURCE LINES 32-45 .. code-block:: Python starts = np.arange(np.datetime64("2023-01-01"), np.datetime64("2025-01-01"), 7) ends = (starts.astype("datetime64[M]") + 6).astype("datetime64[D]") + (starts - starts.astype("datetime64[M]").astype("datetime64[D]")) fig, ax = plt.subplots(figsize=(8, 4.5)) for dc in DayCount: ax.plot(starts, year_fraction(starts, ends, dc), label=dc.value) ax.axhline(0.5, color="k", lw=0.8, ls=":") ax.set_ylabel("year fraction of a six-month period") ax.set_title("The day-count zoo") ax.legend(fontsize=8) fig.autofmt_xdate() plt.show() .. image-sg:: /api/gallery/time_value/day_counts/images/sphx_glr_plot_02_isda_actual_actual_001.png :alt: The day-count zoo :srcset: /api/gallery/time_value/day_counts/images/sphx_glr_plot_02_isda_actual_actual_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /Users/cpoli/Code/financialkit/examples/time_value/day_counts/plot_02_isda_actual_actual.py:33: DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`). Please use a specific unit instead. starts = np.arange(np.datetime64("2023-01-01"), np.datetime64("2025-01-01"), 7) /Users/cpoli/Code/financialkit/examples/time_value/day_counts/plot_02_isda_actual_actual.py:34: DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`). Please use a specific unit instead. ends = (starts.astype("datetime64[M]") + 6).astype("datetime64[D]") + (starts - starts.astype("datetime64[M]").astype("datetime64[D]")) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.046 seconds) .. _sphx_glr_download_api_gallery_time_value_day_counts_plot_02_isda_actual_actual.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/day_counts/plot_02_isda_actual_actual.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_isda_actual_actual.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_isda_actual_actual.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_isda_actual_actual.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_