.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/risk/var/plot_03_parametric_var.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_var_plot_03_parametric_var.py: RiskMetrics: parametric (delta-normal) VaR ========================================== In October 1994 J.P. Morgan published *RiskMetrics*, its methodology and daily covariance data, free. A portfolio with money exposures :math:`w` to factors with covariance :math:`\Sigma` has, under joint normality, .. math:: \mathrm{VaR}_\alpha = z_\alpha \sqrt{h\, w^\top \Sigma w}, computable in a spreadsheet for a whole bank. Diversification is explicit: the portfolio VaR is less than the sum of the stand-alone VaRs unless every correlation is one. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.risk import delta_normal_var, parametric_var .. GENERATED FROM PYTHON SOURCE LINES 23-29 Hull's two-asset example ------------------------ Hull (*Options, Futures, and Other Derivatives*, 10th ed., Ch. 22): $10 million of Microsoft (2% daily volatility) and $5 million of AT&T (1%), correlation 0.3. .. GENERATED FROM PYTHON SOURCE LINES 29-38 .. code-block:: Python w = np.array([10e6, 5e6]) vols = np.array([0.02, 0.01]) cov = np.array([[1.0, 0.3], [0.3, 1.0]]) * np.outer(vols, vols) stand_alone = [parametric_var(0.0, wi * si, 0.99, horizon=10) for wi, si in zip(w, vols, strict=True)] total = delta_normal_var(w, cov, 0.99, horizon=10) print(f"ten-day 99% VaR: Microsoft {stand_alone[0]:,.0f}, AT&T {stand_alone[1]:,.0f}") print(f"portfolio {total:,.0f}; diversification benefit {sum(stand_alone) - total:,.0f}") .. rst-class:: sphx-glr-script-out .. code-block:: none ten-day 99% VaR: Microsoft 1,471,312, AT&T 367,828 portfolio 1,620,114; diversification benefit 219,026 .. GENERATED FROM PYTHON SOURCE LINES 39-41 Diversification and the square-root-of-time rule ------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 41-59 .. code-block:: Python rho = np.linspace(-1, 1, 81) var_rho = [delta_normal_var(w, np.array([[1.0, c], [c, 1.0]]) * np.outer(vols, vols), 0.99, 10) for c in rho] h = np.arange(1, 31) fig, axes = plt.subplots(1, 2, figsize=(11, 4)) axes[0].plot(rho, np.array(var_rho) / 1e6) axes[0].axhline(sum(stand_alone) / 1e6, color="k", ls="--", lw=1, label="sum of stand-alone VaRs") axes[0].set_xlabel("correlation") axes[0].set_ylabel("ten-day 99% VaR ($m)") axes[0].legend() axes[1].plot(h, [delta_normal_var(w, cov, 0.99, k) / 1e6 for k in h], label="99%") axes[1].plot(h, [delta_normal_var(w, cov, 0.95, k) / 1e6 for k in h], label="95%") axes[1].set_xlabel("horizon (days)") axes[1].set_ylabel("VaR ($m)") axes[1].legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/risk/var/images/sphx_glr_plot_03_parametric_var_001.png :alt: plot 03 parametric var :srcset: /api/gallery/risk/var/images/sphx_glr_plot_03_parametric_var_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.061 seconds) .. _sphx_glr_download_api_gallery_risk_var_plot_03_parametric_var.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/var/plot_03_parametric_var.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_parametric_var.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_parametric_var.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_parametric_var.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_