.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/asset_pricing/factors/plot_02_ross_apt.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_factors_plot_02_ross_apt.py: Ross's arbitrage pricing theory =============================== Stephen Ross (1976) derived linear pricing without an equilibrium model. If returns follow a factor model :math:`r_i = E[r_i] + \beta_i' f + \varepsilon_i` with diversifiable :math:`\varepsilon_i`, then any asset off the plane :math:`E[r_i] = r_f + \beta_i'\lambda` can be combined with others into a portfolio with no cost and no factor risk that still earns a positive expected return. In a large market its idiosyncratic risk diversifies away, and the portfolio becomes an arbitrage. The pricing errors therefore have to be small for all but finitely many assets. .. GENERATED FROM PYTHON SOURCE LINES 17-45 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.asset_pricing import apt_arbitrage_portfolio, apt_expected_returns rng = np.random.default_rng(1976) lam = np.array([0.05, 0.02]) idio = 0.25 sizes = np.array([10, 30, 100, 300, 1000, 3000]) sharpe = [] for n in sizes: B = np.column_stack([rng.uniform(0.5, 1.5, n), rng.normal(0, 1, n)]) mu = apt_expected_returns(B, lam, 0.03) + rng.normal(0, 0.01, n) # 1% pricing errors w = apt_arbitrage_portfolio(mu, B) sharpe.append((w @ mu) / (idio * np.linalg.norm(w))) if n == 100: print(f"n = 100: cost {w.sum():.1e}, factor exposure {np.abs(w @ B).max():.1e}, expected return {w @ mu:.4f}") fig, ax = plt.subplots(figsize=(7, 4)) ax.loglog(sizes, sharpe, "o-", label="arbitrage portfolio") ax.loglog(sizes, sharpe[0] * np.sqrt(sizes / sizes[0]), "k:", label="~ sqrt(n)") ax.set_xlabel("number of assets") ax.set_ylabel("Sharpe ratio of the zero-cost, zero-beta portfolio") ax.set_title("constant pricing errors allow unbounded Sharpe ratios") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/asset_pricing/factors/images/sphx_glr_plot_02_ross_apt_001.png :alt: constant pricing errors allow unbounded Sharpe ratios :srcset: /api/gallery/asset_pricing/factors/images/sphx_glr_plot_02_ross_apt_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none n = 100: cost 1.9e-15, factor exposure 2.1e-15, expected return 0.0094 .. GENERATED FROM PYTHON SOURCE LINES 46-50 When pricing errors die out --------------------------- If only a handful of assets are mispriced, the Sharpe ratio stays bounded. .. GENERATED FROM PYTHON SOURCE LINES 50-63 .. code-block:: Python sharpe_sparse = [] for n in sizes: B = np.column_stack([rng.uniform(0.5, 1.5, n), rng.normal(0, 1, n)]) err = np.zeros(n) err[:5] = 0.01 mu = apt_expected_returns(B, lam, 0.03) + err w = apt_arbitrage_portfolio(mu, B) sharpe_sparse.append((w @ mu) / (idio * np.linalg.norm(w))) ax.loglog(sizes, sharpe_sparse, "s-", label="five mispriced assets") ax.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.059 seconds) .. _sphx_glr_download_api_gallery_asset_pricing_factors_plot_02_ross_apt.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/factors/plot_02_ross_apt.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_ross_apt.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_ross_apt.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_ross_apt.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_