.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/risk/expected_shortfall/plot_01_coherence.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_risk_expected_shortfall_plot_01_coherence.py: Artzner-Delbaen-Eber-Heath: coherent risk measures ================================================== Artzner, Delbaen, Eber and Heath (1999) listed four properties a capital requirement should have: monotonicity, subadditivity, positive homogeneity and translation invariance. VaR fails subadditivity: two desks can each look safe while their merger needs capital. The classic counterexample is a pair of independent bonds that each default with 4% probability. At 95% neither default is in the tail, so each bond's VaR is negative; together, a default happens with probability 7.8%, and the portfolio's VaR is a loss. .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.risk import ExpectedShortfall, ValueAtRisk, check_coherence .. GENERATED FROM PYTHON SOURCE LINES 22-27 Two defaultable bonds --------------------- Each bond pays 2 if it survives and loses 100 on default. The 10,000 equally likely states reproduce the joint default probabilities exactly. .. GENERATED FROM PYTHON SOURCE LINES 27-42 .. code-block:: Python p = 0.04 n = 10_000 counts = np.round(np.array([(1 - p) ** 2, p * (1 - p), p * (1 - p), p**2]) * n).astype(int) A = np.repeat([2.0, -100.0, 2.0, -100.0], counts) B = np.repeat([2.0, 2.0, -100.0, -100.0], counts) for measure in (ValueAtRisk(0.95), ExpectedShortfall(0.95)): res = check_coherence(measure, A, B) print(f"{measure.name}: rho(A) = {res.rho_x:7.2f}, rho(B) = {res.rho_y:7.2f}, rho(A + B) = {res.rho_sum:7.2f}") print( f" subadditive {res.subadditivity}, monotone {res.monotonicity}, homogeneous {res.positive_homogeneity}, " f"translation invariant {res.translation_invariance}: coherent = {res.coherent}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none VaR: rho(A) = -2.00, rho(B) = -2.00, rho(A + B) = 98.00 subadditive False, monotone True, homogeneous True, translation invariant True: coherent = False ES: rho(A) = 79.60, rho(B) = 79.60, rho(A + B) = 101.26 subadditive True, monotone True, homogeneous True, translation invariant True: coherent = True .. GENERATED FROM PYTHON SOURCE LINES 43-49 Merging gets punished, at some levels only ------------------------------------------ The diversification benefit, :math:`\rho(A) + \rho(B) - \rho(A + B)`, is negative for VaR at confidence levels between 92.2% and 96%, and never for ES. .. GENERATED FROM PYTHON SOURCE LINES 49-65 .. code-block:: Python levels = np.linspace(0.90, 0.995, 200) benefit = { m: [(lambda r: r.rho_x + r.rho_y - r.rho_sum)(check_coherence(cls(a), A, B)) for a in levels] for m, cls in [("VaR", ValueAtRisk), ("ES", ExpectedShortfall)] } fig, ax = plt.subplots(figsize=(7, 3.8)) for m, b in benefit.items(): ax.plot(levels, b, label=m) ax.axhline(0, color="k", lw=0.8) ax.set_xlabel("confidence level") ax.set_ylabel("diversification benefit") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/risk/expected_shortfall/images/sphx_glr_plot_01_coherence_001.png :alt: plot 01 coherence :srcset: /api/gallery/risk/expected_shortfall/images/sphx_glr_plot_01_coherence_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.167 seconds) .. _sphx_glr_download_api_gallery_risk_expected_shortfall_plot_01_coherence.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/risk/expected_shortfall/plot_01_coherence.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_coherence.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_coherence.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_coherence.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_