.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/market_microstructure/liquidity/plot_01_amihud.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_market_microstructure_liquidity_plot_01_amihud.py: Amihud's illiquidity ratio ========================== Yakov Amihud (2002) proposed a liquidity measure that needs only daily returns and dollar volume: the average of :math:`|r_d| / \mathrm{DVol}_d`, the price move per dollar traded. It approximates Kyle's lambda, which needs signed order flow, and Amihud found that stocks with a higher ratio earn higher expected returns, an illiquidity premium. .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy import stats from financialkit.market_microstructure import amihud_illiquidity, kyle_lambda rng = np.random.default_rng(15) .. GENERATED FROM PYTHON SOURCE LINES 22-28 A cross-section of stocks ------------------------- Each stock's daily return is its Kyle lambda times its signed dollar order flow plus public news. Lambdas span two orders of magnitude, and less liquid stocks trade less. .. GENERATED FROM PYTHON SOURCE LINES 28-52 .. code-block:: Python n_stocks, days = 80, 250 lam = 10 ** rng.uniform(-9, -7, n_stocks) # return per dollar of net order flow scale = 2e5 / np.sqrt(lam / 1e-9) # typical net flow in dollars amihud, kyle = [], [] for i in range(n_stocks): net = scale[i] * rng.standard_normal(days) dvol = np.abs(net) + scale[i] * rng.gamma(2.0, 1.0, days) r = lam[i] * net + 0.005 * rng.standard_normal(days) amihud.append(amihud_illiquidity(r, dvol)) kyle.append(kyle_lambda(r, net).coef[1]) rho = stats.spearmanr(lam, amihud).statistic print(f"rank correlation between Amihud's ratio and the true lambda: {rho:.2f}") fig, ax = plt.subplots(figsize=(6, 4.5)) ax.loglog(lam, amihud, "o", color="C0", label="Amihud ratio (per $1M)") ax.loglog(lam, 1e6 * np.abs(kyle), "x", color="C1", label="regression lambda (per $1M)") ax.set_xlabel("true Kyle lambda") ax.set_ylabel("estimate") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/market_microstructure/liquidity/images/sphx_glr_plot_01_amihud_001.png :alt: plot 01 amihud :srcset: /api/gallery/market_microstructure/liquidity/images/sphx_glr_plot_01_amihud_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none rank correlation between Amihud's ratio and the true lambda: 0.99 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.066 seconds) .. _sphx_glr_download_api_gallery_market_microstructure_liquidity_plot_01_amihud.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/market_microstructure/liquidity/plot_01_amihud.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_amihud.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_amihud.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_amihud.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_