.. 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_04_basel_irb.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_04_basel_irb.py: The Basel II IRB formula ======================== The Basel Committee (2004) set bank capital for credit risk with Vasicek's model: capital per unit of exposure is the 99.9% quantile of the large-pool loss rate, minus the expected loss already covered by provisions, times a maturity adjustment. The supervisory asset correlation falls from 24% to 12% as the PD rises. Gordy (2003) showed this is the only setting where each loan's capital charge does not depend on the rest of the portfolio. .. GENERATED FROM PYTHON SOURCE LINES 15-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.credit import basel_correlation, basel_irb_capital, basel_risk_weight, one_factor_loss_distribution pd = np.geomspace(3e-4, 0.3, 200) fig, ax = plt.subplots(1, 2, figsize=(12, 4)) for cls in ("corporate", "mortgage", "revolving", "retail"): ax[0].semilogx(pd, 100 * np.asarray(basel_risk_weight(pd, asset_class=cls)), label=cls) ax[1].semilogx(pd, 100 * np.asarray(basel_correlation(pd, cls)), label=cls) ax[0].set_xlabel("PD") ax[0].set_ylabel("risk weight (%), LGD 45%") ax[0].legend() ax[1].set_xlabel("PD") ax[1].set_ylabel("asset correlation (%)") print("illustrative corporate risk weights:", {f"{p:.2%}": f"{100 * basel_risk_weight(p):.2f}%" for p in (0.0003, 0.001, 0.01, 0.05, 0.2)}) .. image-sg:: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_04_basel_irb_001.png :alt: plot 04 basel irb :srcset: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_04_basel_irb_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none illustrative corporate risk weights: {'0.03%': '14.44%', '0.10%': '29.65%', '1.00%': '92.32%', '5.00%': '149.85%', '20.00%': '238.23%'} .. GENERATED FROM PYTHON SOURCE LINES 33-35 Capital is the gap between the 99.9% quantile and the expected loss ------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-50 .. code-block:: Python p, lgd = 0.01, 0.45 R = float(basel_correlation(p)) dist = one_factor_loss_distribution(p, R, 2000, lgd=lgd) fig, ax = plt.subplots(figsize=(7, 4)) ax.plot(dist.losses, np.cumsum(dist.pmf)) ax.axvline(dist.mean, color="C0", ls=":", label=f"expected loss {dist.mean:.2%}") ax.axvline(dist.quantile(0.999), color="C3", ls="--", label=f"99.9% quantile {dist.quantile(0.999):.2%}") ax.set_xlim(0, 0.08) ax.set_xlabel("portfolio loss rate") ax.set_ylabel("cumulative probability") ax.set_title(f"K at M = 1: {basel_irb_capital(p, lgd, maturity=1.0):.2%} of exposure") ax.legend() plt.show() .. image-sg:: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_04_basel_irb_002.png :alt: K at M = 1: 5.86% of exposure :srcset: /api/gallery/credit/portfolio_loss/images/sphx_glr_plot_04_basel_irb_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.095 seconds) .. _sphx_glr_download_api_gallery_credit_portfolio_loss_plot_04_basel_irb.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_04_basel_irb.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_basel_irb.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_basel_irb.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_basel_irb.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_