Algorithm Search⌘K

Algorithmintro

Vickrey auction

Also called second-price sealed-bid auction, second-price auction.

Each bidder submits one sealed bid. The highest bidder wins and pays the second highest bid, so bidding one's true value is a weakly dominant strategy.

Time
O(n) worst
Space
O(1) extra
Where
n = the number of bidders
Properties
comparison baseddeterministiciterative
Origin
William Vickrey, 1961

The Vickrey auction, also called the second-price sealed-bid auction, sells one item. Each bidder submits one sealed bid, the highest bid wins, and the winner pays the highest of the other bids, not its own. Because the price does not depend on the winner's own bid, bidding the true value is a weakly dominant strategy, so the auction is DSIC and gives the item to the bidder who values it most. With private values it has the same outcome as the English auction, in which the price rises until one bidder is left, and it is the one-item case of the VCG mechanism.

In plain words

Everyone writes a price in an envelope. The person with the highest price gets the item, but pays only the second highest price written by someone else. This rule takes away the reason to lie. If you write less than the item is worth to you, you do not lower what you pay when you win, you only risk losing an item you wanted at a good price. If you write more, you only add the risk of winning at a price above your worth. So the best thing to write is exactly what the item is worth to you, whatever the others write.

The problem

One item is for sale to nn bidders. Bidder ii has a private value vi≥0v_i \ge 0 and quasilinear utility: vi−pv_i - p if it wins and pays pp, and 00 if it loses. The seller sets a reserve r≥0r \ge 0, the lowest price at which it sells. The auction is a direct revelation mechanism: it receives bids b1,…,bnb_1, \ldots, b_n and must choose a winner (or no sale) and a price. The goal is a rule under which truthful bidding is dominant, the item goes to the highest value at least rr, and losers pay nothing.

The algorithm

A bid is eligible if it is at least rr. The variable ss holds the highest bid seen so far other than that of the current leader ww, and never less than rr.

  1. VICKREY(b_1, ..., b_n, r)
  2. 1w ← NIL; s ← r
  3. 2for i ← 1 to n:
  4. 3if b_i ≥ r and (w = NIL or b_i > b_w): ▷ i is the new leader
  5. 4if w ≠ NIL: s ← b_w ▷ the old leader's bid is now the best other bid
  6. 5w ← i
  7. 6else: s ← max(s, b_i)
  8. 7if w = NIL: return NIL, 0 ▷ no bid reaches the reserve
  9. 8return w, s ▷ w wins and pays s; all others pay 0

The winner ww is the smallest index among the highest eligible bids, because line L3 replaces the leader only on a strictly larger bid. The price is s=max⁡(r,max⁡j≠wbj)s = \max(r, \max_{j \ne w} b_j). This is the critical bid of the winner: the smallest bid with which it would still win against the same b−wb_{-w}.

Example

Three bidders bid their values (10,7,3)(10, 7, 3) and r=0r = 0.

step bib_i leader ww ss
start NIL 0
i=1i = 1 10 1 0
i=2i = 2 7 1 7
i=3i = 3 3 1 7

Bidder 1 wins and pays 7, so its utility is 10−7=310 - 7 = 3. With r=8r = 8 bidder 1 pays 8. With r=12r = 12 the item is not sold. With bids (7,7,3)(7, 7, 3) the tie goes to bidder 1, which pays 7.

Lies do not help. If bidder 1 bids 6 instead of 10, it loses and gets 0 instead of 3. If it bids 20, it still pays 7. If bidder 2 bids 11 instead of 7, it wins, pays 10, and gets 7−10=−37 - 10 = -3.

With nn values drawn independently and uniformly from [0,1][0, 1] (independent private values), the price is the second-highest value, whose expected value is (n−1)/(n+1)(n-1)/(n+1): 1/31/3 for two bidders and 1/21/2 for three. With two bidders and the reserve r=1/2r = 1/2, the expected revenue rises to 5/125/12, the most that any auction can earn here (Myerson's optimal auction). The tests check these numbers by simulation.

Correctness

The proof is in proofs/correctness.md. It shows three facts.

  • The output. The loop keeps the invariant that ww is the first highest eligible bid among the bids seen and ss is the largest of rr and the other bids seen. So line L8 returns the first highest eligible bidder and the price max⁡(r,max⁡j≠wbj)\max(r, \max_{j \ne w} b_j).
  • Truthful bidding is weakly dominant. Fix the bids b−ib_{-i} of the others and let mi=max⁡(r,max⁡j≠ibj)m_i = \max(r, \max_{j \ne i} b_j), which bidder ii cannot change. A bid above mim_i wins and pays mim_i, and a bid below mim_i loses. So the truthful bid gets max⁡(0,vi−mi)\max(0, v_i - m_i), the best of the two outcomes. A bid that changes the outcome either gives up a gain vi−mi>0v_i - m_i > 0 or buys a loss vi−mi<0v_i - m_i < 0.
  • Individual rationality and efficiency. A truthful bidder never gets a negative utility (individual rationality), and with truthful bids the item goes to a highest value that is at least rr.

The dominance holds for every b−ib_{-i}, with no prior on the values and no assumption that the others are truthful.

Proof: The Vickrey auction picks the highest bid, charges the critical price and makes truthful bidding dominantfull

We use the pseudocode of the page, with bids b1,…,bnb_1, \ldots, b_n and a reserve rr. Call bidder ii eligible if bi≥rb_i \ge r. Let w∗w^* be the smallest index among the eligible bidders with the largest bid, and w∗=NILw^* = \mathrm{NIL} if no bidder is eligible. For a bidder ii, let mi=max⁡({r}∪{bj:j≠i})m_i = \max(\{r\} \cup \{b_j : j \ne i\}).

Claim 1. VICKREY returns (w∗,mw∗)(w^*, m_{w^*}) if some bidder is eligible, and (NIL,0)(\mathrm{NIL}, 0) otherwise.

Proof. We use this invariant of the loop of line L2.

(I) Before the iteration for ii, with 1≤i≤n+11 \le i \le n + 1: (a) ww is the smallest index among the eligible bidders of 1,…,i−11, \ldots, i - 1 with the largest bid, or NIL if none of them is eligible; (b) s=max⁡({r}∪{bj:j<i,j≠w})s = \max(\{r\} \cup \{b_j : j < i, j \ne w\}).

Initialization. For i=1i = 1, line L1 gives w=NILw = \mathrm{NIL} and s=rs = r, and both sets are empty.

Maintenance. Assume (I) for i≤ni \le n.

  • If line L3 is true, bi≥rb_i \ge r and either no earlier bidder is eligible or bib_i is strictly larger than the best earlier eligible bid. So ii is the new leader, and it is the smallest index with that bid, because every earlier bid is smaller; (a) holds for i+1i + 1. If ww was NIL, all earlier bids are below rr and s=rs = r is still correct. Otherwise line L4 sets s=bws = b_w. This is correct, because bw≥rb_w \ge r, and bw≥bjb_w \ge b_j for every earlier jj: an earlier eligible jj has bj≤bwb_j \le b_w by (a), and an earlier ineligible jj has bj<r≤bwb_j < r \le b_w. Line L5 makes ii the leader, so (b) holds for i+1i + 1.
  • If line L3 is false, either bi<rb_i < r, or bi≤bwb_i \le b_w. In both cases ii does not become the leader: an ineligible bid cannot lead, and a tie with bwb_w goes to the smaller index ww. So (a) holds for i+1i + 1. Line L6 adds bib_i to the maximum, so (b) holds for i+1i + 1.

Termination. For i=n+1i = n + 1, (a) says w=w∗w = w^* and (b) says s=mws = m_w. Lines L7 and L8 return the claimed pair. □\square

Claim 2 (truthful bidding is a weakly dominant strategy). Fix ii, a value viv_i and bids b−ib_{-i} of the others. Let u(bi)u(b_i) be the utility vi−miv_i - m_i if ii wins and 0 if it loses. Then u(vi)≥u(bi)u(v_i) \ge u(b_i) for every bid bib_i, and u(vi)≥0u(v_i) \ge 0.

Proof. The value mim_i does not depend on bib_i. By Claim 1, bidder ii wins if and only if bi≥rb_i \ge r and bib_i beats every other eligible bid with the tie rule. So there is a threshold: ii wins when bi>mib_i > m_i, loses when bi<mib_i < m_i, and at bi=mib_i = m_i the tie rule decides, with an outcome that depends only on b−ib_{-i}. When ii wins, it pays mim_i, whatever its bid.

  • If vi>miv_i > m_i, the bid viv_i wins and gives vi−mi>0v_i - m_i > 0. Any other bid gives either vi−miv_i - m_i (if it wins) or 0.
  • If vi<miv_i < m_i, the bid viv_i loses and gives 0. Any winning bid gives vi−mi<0v_i - m_i < 0.
  • If vi=miv_i = m_i, every bid gives 0, as a win pays mi=vim_i = v_i.

In all three cases u(vi)=max⁡(0,vi−mi)u(v_i) = \max(0, v_i - m_i), which is at least u(bi)u(b_i) and at least 0. □\square

Claim 3 (efficiency). If every bidder bids its value and r=0r = 0, the winner has the largest value. With a reserve rr, the item goes to a bidder of the largest value if that value is at least rr, and is not sold otherwise.

Proof. Immediate from Claim 1 with b=vb = v. □\square

Cost. The loop runs nn times, and each iteration does at most two comparisons in line L3 and one maximum in line L6. The time is Θ(n)\Theta(n) and the extra space is O(1)O(1).

Complexity

One pass over the bids, with at most two comparisons in line L3 and one in line L6 per bid, so the time is Θ(n)\Theta(n) and the extra space is O(1)O(1). This is optimal up to the constant, since each bid must be read. The fewest comparisons that find the largest and the second-largest of nn numbers is n+⌈log⁡2n⌉−2n + \lceil \log_2 n \rceil - 2, with a knockout tournament (selection problem). The implementation uses exact comparisons, so it works with integers, fractions or floats.

Properties

  • DSIC. Truthful bidding is a weakly dominant strategy for every bidder.
  • Efficient. With truthful bids and r=0r = 0, the item goes to the highest value.
  • Ex post individually rational and no positive transfers. A truthful bidder has utility at least 0, and no bidder is ever paid.
  • Prior-free. The rule and the bidders' strategies need no distribution of values.
  • Revenue. In the symmetric independent private values model, the expected revenue is the expected second-highest value. By the revenue equivalence theorem it equals the revenue of the first-price, Dutch, English and all-pay auctions.
  • Not strictly dominant. For a fixed b−ib_{-i} many bids are as good as the truth, for example any bid above mim_i when vi>miv_i > m_i. Dominance is weak.

Variants and improvements

  • Reserve price. The parameter rr above. With nn symmetric bidders whose values have a regular distribution, the Vickrey auction with the reserve ϕ−1(0)\phi^{-1}(0), where ϕ\phi is the virtual valuation, is optimal for revenue (reserve price). For asymmetric bidders the optimal auction is no longer a Vickrey auction with one reserve.
  • kk identical items. The kk highest bids win and each pays the (k+1)(k+1)-th highest bid. This is the VCG mechanism for kk units and unit demand, and it is DSIC.
  • VCG. For many items and general valuations, the VCG mechanism charges each bidder the welfare loss it causes the others. The Vickrey auction is its one-item case.
  • English auction and proxy bidding. The English auction reaches the same outcome by an open, rising price. Online auctions use proxy bidding: the bidder states a maximum, and a program raises its bid by one increment at a time, which is close to a second-price rule.
  • Generalized second-price auction. For ranked ad slots, each bidder pays the next bid below. This is not DSIC for more than one slot (generalized second-price auction).

When to use it

Use it when the goal is to give the item to the bidder who values it most and the bidders should not have to guess what the others will bid. It suits automated bidders, since the best strategy is simple and the same for every belief about the others. It is a poor choice when the seller cannot be trusted to report the second bid honestly, when bidders fear that their bid reveals their value to a later negotiation, or when the bidders can collude (Rothkopf, Teisberg and Kahn 1990). Many display advertising exchanges used second-price rules for years and moved to first-price rules around 2019.

Pitfalls

  • Weak dominance does not exclude other equilibria. With two bidders of values 10 and 3, the bids (0,100)(0, 100) form a Nash equilibrium: the low-value bidder wins and pays 0. The truthful equilibrium is the one in dominant strategies, but it is not the only one.
  • A cheating seller. The seller sees the bids and can add a fake bid just below the winning bid (a shill bid). The winner then pays nearly its full value, and it cannot detect the change from the outcome alone.
  • Collusion. If the second and third bidders agree that only one of them bids, the price drops. DSIC holds for each bidder alone, not for groups.
  • Ties. A tie at the top must go to one bidder by a fixed rule, and the winner then pays its own bid. Tests of DSIC must compare utilities with ≥\ge, not >>, and must use exact arithmetic.
  • The reserve is a bid of the seller. The price is max⁡(r,⋅)\max(r, \cdot), not the second bid alone. Forgetting rr in line L1 makes the winner pay less than the reserve.
  • Values must be private. If a bidder's value depends on what the others know, as in a common value auction, the truthful bid is no longer dominant and the winner's curse appears.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

vickrey_auction.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vickrey-auction/. The authors are listed in prov/3GCYFC.jsonl.

from fractions import Fraction
from typing import Sequence, Union

Number = Union[int, Fraction, float]


def vickrey_auction(
    bids: Sequence[Number], reserve: Number = 0
) -> tuple[int | None, Number]:
    """Run a second-price sealed-bid auction with a reserve price.

    A bid can win only if it is at least the reserve. The highest such bid
    wins, and a tie goes to the smallest index. The winner pays the larger of
    the reserve and the highest bid of the other bidders. Return the 0-based
    index of the winner and the price, or (None, 0) if no bid reaches the
    reserve. Losers pay 0.
    """
    winner: int | None = None
    second: Number = reserve  # @line L1
    for i in range(len(bids)):  # @line L2
        b = bids[i]
        if b >= reserve and (winner is None or b > bids[winner]):  # @line L3
            if winner is not None:  # @line L4
                second = bids[winner]  # @line L4
            winner = i  # @line L5
        else:
            second = max(second, b)  # @line L6
    if winner is None:  # @line L7
        return None, 0  # @line L7
    return winner, second  # @line L8


def utility(value: Number, bids: Sequence[Number], i: int, reserve: Number = 0) -> Number:
    """Quasilinear utility of bidder i with the given value when the bids are bids."""
    winner, price = vickrey_auction(bids, reserve)
    if winner != i:
        return 0
    return value - price
test_vickrey_auction.py 86 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vickrey-auction/. The authors are listed in prov/3GCYFC.jsonl.

import itertools
import random
from fractions import Fraction

from vickrey_auction import utility, vickrey_auction


def reference(bids, reserve=0):
    eligible = [i for i in range(len(bids)) if bids[i] >= reserve]
    if not eligible:
        return None, 0
    top = max(bids[i] for i in eligible)
    winner = min(i for i in eligible if bids[i] == top)
    others = [bids[j] for j in range(len(bids)) if j != winner]
    return winner, max([reserve] + others)


def test_example() -> None:
    assert vickrey_auction([10, 7, 3]) == (0, 7)
    assert vickrey_auction([3, 7, 10]) == (2, 7)
    assert vickrey_auction([10, 7, 3], reserve=8) == (0, 8)
    assert vickrey_auction([10, 7, 3], reserve=12) == (None, 0)


def test_edges() -> None:
    assert vickrey_auction([]) == (None, 0)
    assert vickrey_auction([5]) == (0, 0)
    assert vickrey_auction([5], reserve=2) == (0, 2)
    assert vickrey_auction([7, 7, 3]) == (0, 7)
    assert vickrey_auction([3, 7, 7]) == (1, 7)
    assert vickrey_auction([2, 2], reserve=2) == (0, 2)
    assert vickrey_auction([Fraction(1, 3), Fraction(1, 2)]) == (1, Fraction(1, 3))


def test_against_reference() -> None:
    rng = random.Random(1)
    for _ in range(2000):
        n = rng.randrange(0, 7)
        bids = [rng.randrange(0, 6) for _ in range(n)]
        r = rng.randrange(0, 5)
        assert vickrey_auction(bids, r) == reference(bids, r)


def test_truthful_bidding_is_dominant() -> None:
    grid = range(0, 6)
    for reserve in (0, 2):
        for others in itertools.product(grid, repeat=2):
            for i in range(3):
                for value in grid:
                    truthful = list(others[:i]) + [value] + list(others[i:])
                    u_true = utility(value, truthful, i, reserve)
                    assert u_true >= 0
                    for lie in grid:
                        bids = list(others[:i]) + [lie] + list(others[i:])
                        assert u_true >= utility(value, bids, i, reserve)


def test_price_does_not_depend_on_winning_bid() -> None:
    rng = random.Random(2)
    for _ in range(500):
        bids = [rng.randrange(0, 20) for _ in range(4)]
        w, p = vickrey_auction(bids)
        raised = list(bids)
        raised[w] += rng.randrange(0, 10)
        assert vickrey_auction(raised) == (w, p)


def mean_revenue(n, reserve, trials, seed):
    rng = random.Random(seed)
    total = 0.0
    for _ in range(trials):
        _, price = vickrey_auction([rng.random() for _ in range(n)], reserve)
        total += price
    return total / trials


def test_revenue_uniform() -> None:
    # Each price is in [0, 1]. With 20000 trials, Hoeffding gives
    # P(|mean - expectation| > 0.02) <= 2 exp(-16) < 1e-6.
    assert abs(mean_revenue(2, 0, 20000, 3) - 1 / 3) < 0.02
    assert abs(mean_revenue(3, 0, 20000, 4) - 1 / 2) < 0.02
    assert abs(mean_revenue(2, 0.5, 20000, 5) - 5 / 12) < 0.02
    assert abs(mean_revenue(1, 0.5, 20000, 6) - 1 / 4) < 0.02

History

Vickrey (1961) studied auctions as games of incomplete information. He defined the sealed-bid auction in which the winner pays the second-highest bid, proved that bidding the true value is dominant, and noted that it gives the same result as the English auction with private values. He also computed, for uniform values, that the first-price auction earns the same expected revenue, which is an early case of revenue equivalence. Second-price rules were in use earlier: stamp dealers who ran auctions by mail in the nineteenth century charged the winner the second-highest mailed bid, plus one increment (Lucking-Reiley 2000). Vickrey received the Nobel Memorial Prize in Economic Sciences in 1996, together with James Mirrlees. Clarke (1971) and Groves (1973) extended the idea of charging the externality to general decisions, which led to the VCG mechanism.

References

  1. William Vickrey, Counterspeculation, auctions, and competitive sealed tenders, Journal of Finance 16(1) (1961), 8-37, the second-price sealed-bid auction, the proof that bidding the true value is dominant, and its relation to the English auction
  2. Vijay Krishna, Auction Theory, 2nd edition, Academic Press, 2010, Chapter 2, Section 2.2 (second-price auctions, the weakly dominant strategy and the expected payment) and the section on reserve prices in the same chapter
  3. Tim Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016, Lecture 2, Section 2.4 (second-price auctions and dominant strategies)
  4. David Lucking-Reiley, Vickrey auctions in practice, from nineteenth-century philately to twenty-first-century e-commerce, Journal of Economic Perspectives 14(3) (2000), 183-192, the use of second-price rules in stamp auctions by mail before 1961 and the proxy bidding of online auctions
  5. Michael H. Rothkopf, Thomas J. Teisberg and Edward P. Kahn, Why are Vickrey auctions rare?, Journal of Political Economy 98(1) (1990), 94-109, the reasons why real auctioneers avoid the sealed second-price rule, with the fear that bids reveal values to later negotiations and a cheating auctioneer

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example