.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/asset_pricing/capm/plot_03_zero_beta.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_asset_pricing_capm_plot_03_zero_beta.py: Black's zero-beta CAPM ====================== Sharpe's CAPM assumes unlimited riskless borrowing. Fischer Black (1972) dropped it: every frontier portfolio :math:`m` still prices all assets linearly, with the expected return of :math:`z`, the minimum-variance portfolio uncorrelated with :math:`m`, in place of the riskless rate, .. math:: E[r_i] = E[r_z] + \beta_{im} (E[r_m] - E[r_z]). Since :math:`E[r_z]` lies above the lending rate, the security market line is flatter than Sharpe's, which matched Black, Jensen and Scholes's (1972) finding that low-beta stocks earn more, and high-beta ones less, than the CAPM predicts. .. GENERATED FROM PYTHON SOURCE LINES 22-34 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.asset_pricing import zero_beta_capm mu = np.array([0.05, 0.07, 0.09, 0.11, 0.13]) vol = np.array([0.12, 0.16, 0.20, 0.25, 0.32]) cov = (0.3 + 0.7 * np.eye(5)) * np.outer(vol, vol) res = zero_beta_capm(mu, cov, zero_beta_rate=0.02) wz, wm = res.zero_beta_weights, res.market_weights print(f"E[r_z] = {res.zero_beta_rate:.4f}, cov(z, m) = {wz @ cov @ wm:.2e}") .. rst-class:: sphx-glr-script-out .. code-block:: none E[r_z] = 0.0200, cov(z, m) = 1.52e-18 .. GENERATED FROM PYTHON SOURCE LINES 35-37 The frontier, the market and its zero-beta portfolio ---------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 37-53 .. code-block:: Python ones = np.ones(5) Ci = np.linalg.inv(cov) A, B, C = ones @ Ci @ mu, mu @ Ci @ mu, ones @ Ci @ ones targets = np.linspace(0.02, 0.14, 200) sd = np.sqrt((C * targets**2 - 2 * A * targets + B) / (B * C - A**2)) fig, axes = plt.subplots(1, 2, figsize=(10, 4)) axes[0].plot(sd, targets, "k", lw=1, label="minimum-variance frontier") axes[0].plot(np.sqrt(wm @ cov @ wm), res.market_return, "s", color="C3", label="market m") axes[0].plot(np.sqrt(wz @ cov @ wz), res.zero_beta_rate, "o", color="C0", label="zero-beta z") x = np.linspace(0, 0.3, 2) axes[0].plot(x, res.zero_beta_rate + (res.market_return - res.zero_beta_rate) / np.sqrt(wm @ cov @ wm) * x, "C0", ls=":", lw=1) axes[0].set_xlabel("volatility") axes[0].set_ylabel("expected return") axes[0].legend(fontsize=8) .. image-sg:: /api/gallery/asset_pricing/capm/images/sphx_glr_plot_03_zero_beta_001.png :alt: plot 03 zero beta :srcset: /api/gallery/asset_pricing/capm/images/sphx_glr_plot_03_zero_beta_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 54-56 The security market line starts at E[r_z] ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 56-67 .. code-block:: Python b = np.linspace(0, 1.6, 2) axes[1].plot(res.betas, mu, "o", color="C1", label="assets") axes[1].plot(b, res.zero_beta_rate + b * (res.market_return - res.zero_beta_rate), "C0", label="zero-beta SML") rf = 0.005 axes[1].plot(b, rf + b * (res.market_return - rf), "C3", ls="--", label=f"Sharpe SML with r_f = {rf:.1%}") axes[1].set_xlabel("beta on m") axes[1].legend(fontsize=8) fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.055 seconds) .. _sphx_glr_download_api_gallery_asset_pricing_capm_plot_03_zero_beta.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/asset_pricing/capm/plot_03_zero_beta.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_zero_beta.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_zero_beta.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_zero_beta.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_