.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/credit/portfolio_loss/plot_05_tranche_expected_loss.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_portfolio_loss_plot_05_tranche_expected_loss.py: Hull and White: pricing CDO tranches without Monte Carlo ======================================================== A tranche of a synthetic CDO absorbs portfolio losses between its attachment and detachment points. Hull and White (2004) priced tranches in Li's one-factor Gaussian copula by conditioning on the common factor: given it, defaults are independent and the pool loss is binomial, so the expected tranche loss at each date is one integral over the factor. Raising the correlation moves risk from the equity tranche, which loses less, to the senior tranches, which lose more. .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.credit import HazardCurve, expected_tranche_loss, tranche_spread from financialkit.credit.visualizers import plot_tranche_losses curve = HazardCurve.flat(0.012) tranches = [(0.0, 0.03), (0.03, 0.07), (0.07, 0.10), (0.10, 0.15), (0.15, 0.30)] res = [tranche_spread(a, d, curve, 0.25, 5.0, 0.03, n_names=125) for a, d in tranches] ax = plot_tranche_losses(res) ax.set_title("125 names, 5 years, copula correlation 0.25") .. image-sg:: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_05_tranche_expected_loss_001.png :alt: 125 names, 5 years, copula correlation 0.25 :srcset: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_05_tranche_expected_loss_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, '125 names, 5 years, copula correlation 0.25') .. GENERATED FROM PYTHON SOURCE LINES 28-30 Spreads against correlation --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-40 .. code-block:: Python rhos = np.linspace(0.02, 0.9, 15) fig, ax = plt.subplots(figsize=(7, 4)) for a, d in tranches: s = [tranche_spread(a, d, curve, rho, 5.0, 0.03).par_spread for rho in rhos] ax.semilogy(rhos, 1e4 * np.array(s), label=f"{100 * a:g}-{100 * d:g}%") ax.set_xlabel("copula correlation") ax.set_ylabel("par spread (bp, large pool)") ax.legend() .. image-sg:: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_05_tranche_expected_loss_002.png :alt: plot 05 tranche expected loss :srcset: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_05_tranche_expected_loss_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 41-43 Finite pool versus the large-pool limit --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 43-50 .. code-block:: Python p = float(curve.default_probability(5.0)) for n in (25, 125, 1000, None): el = expected_tranche_loss(0.03, 0.07, p, 0.25, n_names=n) print(f"{'LHP' if n is None else n:>5}: expected 3-7% tranche loss at 5y = {el:.4f}") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 25: expected 3-7% tranche loss at 5y = 0.2634 125: expected 3-7% tranche loss at 5y = 0.2454 1000: expected 3-7% tranche loss at 5y = 0.2409 LHP: expected 3-7% tranche loss at 5y = 0.2398 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.528 seconds) .. _sphx_glr_download_api_gallery_credit_portfolio_loss_plot_05_tranche_expected_loss.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/portfolio_loss/plot_05_tranche_expected_loss.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_tranche_expected_loss.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_tranche_expected_loss.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_tranche_expected_loss.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_