.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/credit/reduced_form/plot_01_jarrow_turnbull.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_credit_reduced_form_plot_01_jarrow_turnbull.py: Jarrow and Turnbull: hazard rates and survival curves ===================================================== Jarrow and Turnbull (1995) modelled the timing of default rather than its cause: default is the first jump of a Poisson process with intensity :math:`\lambda(t)`, so the survival probability is :math:`Q(t) = e^{-\int_0^t \lambda}`. A risky zero-coupon bond that recovers a fraction :math:`\delta` of a riskless one is worth :math:`P(0,T)[\delta + (1-\delta)Q(T)]`, and its spread is close to :math:`\lambda(1 - \delta)`: the credit triangle. .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.credit import HazardCurve, jarrow_turnbull_zero, spread_from_hazard from financialkit.credit.visualizers import plot_survival curve = HazardCurve([1.0, 3.0, 5.0, 10.0], [0.010, 0.015, 0.025, 0.030]) fig, ax = plt.subplots(figsize=(7, 4)) plot_survival(curve, T=10.0, ax=ax, label="piecewise-constant hazard") plot_survival(HazardCurve.flat(0.02), T=10.0, ax=ax, label="flat 2%", hazard=False) ax.legend(loc="lower left") .. image-sg:: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_001.png :alt: plot 01 jarrow turnbull :srcset: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 28-33 Simulated default times ----------------------- Inverting the cumulative hazard of a uniform draw gives default times whose histogram is the default density :math:`\lambda(t) Q(t)`. .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python tau = curve.sample_default_times(100_000, rng=0) t = np.linspace(0, 10, 400) fig, ax = plt.subplots(figsize=(7, 4)) ax.hist(tau[tau < 10], bins=80, density=True, weights=np.full((tau < 10).sum(), (tau < 10).mean()), color="0.7", label="simulated") ax.plot(t, curve.default_density(t), "C3", lw=2, label="lambda(t) Q(t)") ax.set_xlabel("default time (years)") ax.legend() .. image-sg:: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_002.png :alt: plot 01 jarrow turnbull :srcset: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 43-45 Risky bond prices and the credit triangle ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-59 .. code-block:: Python T = np.linspace(0.25, 10, 40) r, delta = 0.04, 0.4 P = jarrow_turnbull_zero(T, r, curve, delta) spread = -np.log(P) / T - r fig, ax = plt.subplots(figsize=(7, 4)) ax.plot(T, 1e4 * spread, label="zero-coupon spread") avg_hazard = np.asarray(curve.cumulative_hazard(T)) / T ax.plot(T, 1e4 * np.asarray(spread_from_hazard(avg_hazard, delta)), "--", label="credit triangle, average hazard x (1 - R)") ax.set_xlabel("maturity") ax.set_ylabel("bp") ax.legend() plt.show() .. image-sg:: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_003.png :alt: plot 01 jarrow turnbull :srcset: /api/gallery/credit/reduced_form/images/sphx_glr_plot_01_jarrow_turnbull_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.133 seconds) .. _sphx_glr_download_api_gallery_credit_reduced_form_plot_01_jarrow_turnbull.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/credit/reduced_form/plot_01_jarrow_turnbull.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_jarrow_turnbull.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_jarrow_turnbull.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_jarrow_turnbull.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_