.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/economics/auctions/plot_02_myerson_optimal_auction.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_economics_auctions_plot_02_myerson_optimal_auction.py: Myerson's optimal auction and revenue equivalence (1981) ======================================================== Which auction earns the seller the most? Myerson replaced each bidder's value :math:`v` by its *virtual value*, the marginal revenue of selling to it, .. math:: \varphi(v) = v - \frac{1 - F(v)}{f(v)}, and showed that expected revenue equals the expected virtual value of the winner. The optimal auction therefore sells to the highest nonnegative virtual value: for identical bidders, a second-price auction with a *reserve price* :math:`\varphi^{-1}(0)`, which is :math:`1/2` for values uniform on :math:`[0, 1]`, however many bidders there are. The same identity gives *revenue equivalence*: any two auctions that allocate alike earn the same on average. A first-price auction, in which bidders shade their bids, and a second-price one, in which they bid their values, raise exactly the same expected revenue. .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import blockchainkit as bk .. GENERATED FROM PYTHON SOURCE LINES 32-34 Revenue against the reserve --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-54 .. code-block:: Python reserves = np.linspace(0, 0.95, 39) fig, ax = plt.subplots(figsize=(7, 4.5)) for n, color in ((1, "#dc2626"), (2, "#2563eb"), (4, "#16a34a")): revenue = [bk.economics.expected_revenue(n, reserve=r) for r in reserves] ax.plot(reserves, revenue, color=color, label=f"{n} bidder{'s' * (n > 1)}") best = reserves[int(np.argmax(revenue))] assert abs(best - bk.economics.optimal_reserve()) < 0.03 for auction, marker in (("first-price", "o"), ("second-price", "s")): measured = [ bk.economics.simulate_revenue(auction, n, rounds=4_000, reserve=r, seed=3) for r in (0.0, 0.5, 0.8) ] ax.plot((0.0, 0.5, 0.8), measured, marker, color=color, fillstyle="none") ax.axvline(bk.economics.optimal_reserve(), color="black", linestyle=":", label="phi(r) = 0") ax.set(xlabel="reserve price", ylabel="expected revenue") ax.set_title("Myerson's reserve; circles first-price, squares second-price") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/economics/auctions/images/sphx_glr_plot_02_myerson_optimal_auction_001.png :alt: Myerson's reserve; circles first-price, squares second-price :srcset: /api/gallery/economics/auctions/images/sphx_glr_plot_02_myerson_optimal_auction_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 55-57 Revenue equivalence ------------------- .. GENERATED FROM PYTHON SOURCE LINES 57-67 .. code-block:: Python for n in (2, 5): theory = bk.economics.expected_revenue(n, reserve=0.5) first = bk.economics.simulate_revenue("first-price", n, rounds=30_000, reserve=0.5, seed=8) second = bk.economics.simulate_revenue("second-price", n, rounds=30_000, reserve=0.5, seed=8) print(f"{n} bidders: theory {theory:.4f}, first-price {first:.4f}, second-price {second:.4f}") assert abs(first - theory) < 0.01 and abs(second - theory) < 0.01 plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 2 bidders: theory 0.4167, first-price 0.4142, second-price 0.4132 5 bidders: theory 0.6719, first-price 0.6711, second-price 0.6708 .. GENERATED FROM PYTHON SOURCE LINES 68-74 Exercise -------- The reserve helps most with one bidder. With a single bidder whose value is uniform on [0, 1], the seller just posts a price p. Show that its revenue is p (1 - p) and that the best price is Myerson's reserve. A worked solution is in :doc:`/exercises/economics`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.481 seconds) .. _sphx_glr_download_api_gallery_economics_auctions_plot_02_myerson_optimal_auction.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/economics/auctions/plot_02_myerson_optimal_auction.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_myerson_optimal_auction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_myerson_optimal_auction.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_myerson_optimal_auction.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_