Algorithmcore
Generalized second-price auction
Also called GSP auction.
Ranks ad bids, gives the s-th highest bidder slot s and charges it the next bid per click. Not truthful, but it has an envy-free equilibrium with the VCG outcome.
- Time
- O(n log n) worst
- Space
- O(n) extra
- Where
- k = the number of slots; n = the number of bidders
- Model
- Word RAM
- Properties
- comparison baseddeterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Benjamin Edelman, Michael Ostrovsky, Michael Schwarz, Hal Varian, 2002
The generalized second-price auction (GSP) sells the ad slots next to the results of a web search. The slots are ranked, and a higher slot gets more clicks. Each advertiser bids one price per click. GSP sorts the bids, gives the highest bidder the top slot, the second highest the second slot, and so on, and each winner pays, for each click, the bid of the bidder just below it. With one slot this is the Vickrey auction. With two or more slots it is not truthful: a bidder can gain by bidding less and taking a lower slot at a lower price. It is still the standard format of search advertising, because it has a locally envy-free equilibrium with the same slots and payments as the VCG mechanism.
In plain words
Advertisers bid for places on a page of search results, and a place near the top gets more clicks. The page sorts the advertisers by bid. The best bid gets the top place, the next bid the next place, and so on. Each advertiser pays for each click the bid of the advertiser right below it, not its own bid. This looks like the sealed second-price auction, where the honest bid is always best, but it is different. Here an advertiser can bid less, drop one place, lose a few clicks, and pay much less for every click it keeps. So advertisers do not simply bid their values.
The problem
There are slots and bidders. Slot gets clicks, with , the same for every bidder. Bidder has a private value per click and quasilinear utility: in slot at the price per click it gets . This is the position auction model. Each bidder reports a bid per click. The mechanism gives each slot to at most one bidder and sets a price per click for each winner. A reserve price is optional: a bid below takes no part.
The algorithm
GSP(b_1, ..., b_n, α_1, ..., α_k, r)- 1
R ← the bidders with b_i ≥ r, sorted by bid, highest first; ties go to the smaller index - 2
q ← min(k, |R|) - 3
for s ← 1 to q - 4
give slot s to R_s - 5
if R_{s+1} exists: π_s ← b of R_{s+1} - 6
else: π_s ← r - 7
return the slots and the prices per click π_1, ..., π_q
Bidder pays in total. Slots after stay empty.
Example
This is the example of Edelman, Ostrovsky and Schwarz (2007). Three bidders have values per click, and two slots get and clicks. There is no reserve.
| bids | slot of bidder 1 | its price per click | its utility |
|---|---|---|---|
| (truthful) | 1 | 4 | |
| 2 | 2 |
Bidder 1 gains by bidding 3: it loses one click and saves 2 on each of 199 clicks. So truthful bidding is not a dominant strategy.
The VCG payments are for slot 2 (the value 2 of the third bidder times the 199 clicks it would gain) and for slot 1, in total 800. With the bids in GSP, bidder 1 pays and bidder 2 pays . These bids form an equilibrium with the VCG outcome, and the page on the locally envy-free equilibrium explains how to find them.
Correctness
The proof is in proofs/correctness.md. It shows these facts.
- The output. Slot goes to the -th eligible bidder in sorted order and costs the next eligible bid per click, or if there is none. No bidder gets two slots.
- Individual rationality. The price per click is at most the bidder's own bid and at least , so a bidder that bids its value never gets a negative utility.
- One slot is Vickrey. With the winner pays the larger of and the highest other bid.
- Not truthful for two or more slots, by the example above.
- GSP payments are at least VCG payments for the same bids. The VCG payment of slot is , and each bid in the sum is at most , so the sum is at most .
Proof: The generalized second-price auction ranks by bid, charges the next bid, is individually rational, and is not truthfulfull
We use the pseudocode of the page: bidders, slots with click-through rates , and a reserve . A bidder in slot with value per click and price per click gets the utility , and a bidder with no slot gets 0. Let be the eligible bidders (bid at least ) in the order of line L1, and write for the bid of .
Claim 1 (the output). For , slot goes to and its price per click is if , and otherwise. No bidder gets two slots, and every slot after stays empty.
Proof. Line L1 lists each eligible bidder once, in a fixed order. Lines L3 and L4 give slot to the -th bidder of the list, so the slots go to distinct bidders. Lines L5 and L6 set the price as stated.
Claim 2 (no bidder pays more than its bid). For , . So a bidder that bids its value never gets a negative utility, and a bidder that bids at least but gets no slot pays nothing.
Proof. The list is sorted, so , and because is eligible. If , the price is . A bidder that bids and gets slot gets .
Claim 3 (one slot is the Vickrey auction). If , the highest eligible bid wins and pays the larger of and the second-highest eligible bid. A bid below cannot win, so this is the larger of and the highest other bid, which is the price of the Vickrey auction with reserve , with the same tie rule.
Claim 4 (truthful bidding is not dominant when ). Take the example of Edelman, Ostrovsky and Schwarz (2007, Section II): values , two slots with and clicks, and . With truthful bids, bidder 1 gets slot 1 at the price 4, so its utility is . If it bids 3, it is ranked second and pays the next bid 2, so its utility is .
The general reason: the price of slot is the bid of the next bidder, and the price of slot is the bid after that. A bidder trades clicks against a lower price per click on all its clicks, and when the click-through rates are close, the lower price wins.
Claim 5 (for the same bids, GSP charges at least the VCG payments). Let , let all bids be at least 0, and put for and when does not exist. The VCG payment of the bidder in slot , computed from the bids, is . The GSP payment of the same bidder is .
Proof. Each factor is at least 0, and for . So , because the sum telescopes and .
This is Remark 1 of Edelman, Ostrovsky and Schwarz (2007). It does not say that GSP earns more than VCG in equilibrium, because the bids in GSP are not truthful. The equilibrium with the VCG outcome is proved on the page Locally envy-free equilibrium of GSP.
Complexity
Sorting the bids takes time and space, and lines L2 to L7 take time. Only the highest bids matter, so a selection of them and a sort of those bids give time.
Properties
- Not DSIC when and , whatever the rates; the gain from bidding for a lower slot is largest when the click-through rates differ by little.
- Ex post individually rational for truthful bids, and every winner pays at most its bid.
- Efficient equilibrium. Every envy-free equilibrium in the sense of Varian gives the slots in the order of the values and pays at least the VCG payments; the bidder-optimal one has exactly the VCG outcome (Edelman, Ostrovsky and Schwarz 2007; Varian 2007).
- Same bids, more money. For the same bids GSP charges each bidder at least the VCG payment. In the equilibrium with the VCG outcome the revenue is the same as VCG, because the bids are lower.
- Simple prices. The price of a slot depends only on the next bid, which is easy to explain to advertisers.
Variants and improvements
- Weighted GSP. Real systems rank by bid times a quality score, an estimate of the click-through rate of the ad, and charge the smallest bid that keeps the slot: for the weights . The model and the equilibrium results carry over with values scaled by the weights.
- Reserve prices. A reserve price, the same for all bidders or one per bidder, raises revenue in the same way as in Myerson's optimal auction.
- VCG for slots. The VCG mechanism charges slot the sum . It is truthful and gives the same outcome as the bidder-optimal envy-free equilibrium of GSP. Some ad platforms use it.
- Generalized first-price auction. The early format of Overture charged each winner its own bid. Bids then changed all the time in cycles, which led to GSP.
- Budgets. With daily budgets the bidders, or the platform for them, scale the bids down; see pacing equilibrium.
When to use it
Use GSP to sell ranked slots with click-through rates that fall from the top, when the bidders are sophisticated and bid repeatedly, so that they can find an equilibrium. Use VCG when you want truthful bidding to be a dominant strategy, and use a Vickrey auction when there is one slot, where the two agree.
Pitfalls
- "Second price" does not mean truthful. With two or more slots, the truth is not a dominant strategy, and an analysis that assumes it is wrong.
- Many equilibria. GSP has many Nash equilibria, some inefficient. The envy-free refinement picks a set with the VCG outcome or more revenue, but the refinement is an assumption about how bidders behave.
- Ties. Line L1 breaks ties by index. Bidders with equal bids pay the same price per click but get different numbers of clicks.
- Separable click-through rates. The model assumes that the clicks of a slot do not depend on the ad. With quality scores, rank by weighted bid, not by bid.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/generalized-second-price-auction/. The authors are listed in prov/ATPJNQ.jsonl.
from fractions import Fraction
from typing import Sequence, Union
Number = Union[int, Fraction]
def gsp(
bids: Sequence[Number], ctrs: Sequence[Number], reserve: Number = 0
) -> tuple[list[int], list[Number]]:
"""Run the generalized second-price auction for ranked ad slots.
ctrs[s] is the click-through rate of slot s, with ctrs nonincreasing.
Only bids of at least the reserve take part. They are ranked by bid,
highest first, with ties to the smaller index, and the s-th ranked
bidder gets slot s. It pays per click the next bid in the ranking, or the
reserve if there is no next bid. Return (winners, prices): winners[s] is
the 0-based bidder index in slot s, and prices[s] is its price per click.
"""
ranked = sorted((i for i in range(len(bids)) if bids[i] >= reserve), key=lambda i: (-bids[i], i)) # @line L1
filled = min(len(ctrs), len(ranked)) # @line L2
winners: list[int] = []
prices: list[Number] = []
for s in range(filled): # @line L3
winners.append(ranked[s]) # @line L4
if s + 1 < len(ranked): # @line L5
prices.append(bids[ranked[s + 1]]) # @line L5
else: # @line L6
prices.append(reserve) # @line L6
return winners, prices # @line L7
def utility(value: Number, bids: Sequence[Number], ctrs: Sequence[Number], i: int, reserve: Number = 0) -> Number:
"""Utility of bidder i per unit of time: ctr of its slot times value minus price."""
winners, prices = gsp(bids, ctrs, reserve)
for s, w in enumerate(winners):
if w == i:
return ctrs[s] * (value - prices[s])
return 0
def revenue(bids: Sequence[Number], ctrs: Sequence[Number], reserve: Number = 0) -> Number:
"""Total payment of all bidders per unit of time."""
winners, prices = gsp(bids, ctrs, reserve)
return sum(ctrs[s] * prices[s] for s in range(len(winners)))
def vcg_payments(values: Sequence[Number], ctrs: Sequence[Number]) -> tuple[list[int], list[Number]]:
"""VCG outcome of the position auction with reported values.
Rank by value as in gsp. The bidder in slot s pays the externality
sum over t >= s of (ctrs[t] - ctrs[t + 1]) * v(t + 1), where v(t + 1)
is the value ranked t + 1 (0 if it does not exist) and ctrs past the
last slot are 0. Return (winners, total payments per slot).
"""
ranked = sorted(range(len(values)), key=lambda i: (-values[i], i))
k = min(len(ctrs), len(ranked))
alpha = list(ctrs[:k]) + [0]
v = [values[i] for i in ranked] + [0]
pay = [sum((alpha[t] - alpha[t + 1]) * v[t + 1] for t in range(s, k)) for s in range(k)]
return ranked[:k], pay
def eos_bids(values: Sequence[Number], ctrs: Sequence[Number]) -> list[Number]:
"""The bidder-optimal locally envy-free equilibrium of Edelman, Ostrovsky and Schwarz.
The bidder ranked j >= 2 bids the VCG payment of slot j - 1 divided by
ctrs[j - 1], the bidder ranked first bids its value, and bidders ranked
below the first loser bid their values. Click-through rates must be
positive.
"""
ranked = sorted(range(len(values)), key=lambda i: (-values[i], i))
_, pay = vcg_payments(values, ctrs)
bids: list[Number] = [0] * len(values)
for j, i in enumerate(ranked):
if j == 0 or j > len(pay):
bids[i] = values[i]
else:
bids[i] = Fraction(pay[j - 1]) / ctrs[j - 1]
return bids
test_generalized_second_price_auction.py 156 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/generalized-second-price-auction/. The authors are listed in prov/ATPJNQ.jsonl.
import itertools
import random
from fractions import Fraction
from generalized_second_price_auction import eos_bids, gsp, revenue, utility, vcg_payments
DELTA = Fraction(1, 1000)
def is_nash(values, bids, ctrs):
"""Every deviation of every bidder is tried: each slot can be reached by
a bid just above, equal to or just below some other bid, or by 0."""
for i, v in enumerate(values):
current = utility(v, bids, ctrs, i)
others = [bids[j] for j in range(len(bids)) if j != i]
candidates = {0} | {b + d for b in others for d in (-DELTA, 0, DELTA) if b + d >= 0}
for c in candidates:
if utility(v, bids[:i] + [c] + bids[i + 1:], ctrs, i) > current:
return False
return True
def slot_offers(bids, ctrs):
"""Price per click and click-through rate of every slot, plus no slot."""
winners, prices = gsp(bids, ctrs)
return winners, [(ctrs[s], prices[s]) for s in range(len(winners))] + [(0, 0)]
def is_envy_free(values, bids, ctrs):
"""Varian's symmetric Nash equilibrium: nobody prefers another slot at its price."""
winners, offers = slot_offers(bids, ctrs)
for i, v in enumerate(values):
current = utility(v, bids, ctrs, i)
if any(a * (v - p) > current for a, p in offers):
return False
return True
def is_locally_envy_free(values, bids, ctrs):
"""Edelman, Ostrovsky and Schwarz: the bidder at rank r does not envy rank r - 1,
for 2 <= r <= min(slots + 1, bidders)."""
ranked = sorted(range(len(bids)), key=lambda i: (-bids[i], i))
alpha = list(ctrs) + [0]
for r in range(1, min(len(ctrs) + 1, len(bids))):
i = ranked[r]
nxt = bids[ranked[r + 1]] if r + 1 < len(ranked) else 0
if alpha[r] * (values[i] - nxt) < alpha[r - 1] * (values[i] - bids[i]):
return False
return True
def test_example() -> None:
# Edelman, Ostrovsky and Schwarz, Section II: values 10, 4, 2 and 200, 199 clicks.
values, ctrs = [10, 4, 2], [200, 199]
assert gsp(values, ctrs) == ([0, 1], [4, 2])
assert utility(10, values, ctrs, 0) == 1200
assert utility(10, [3, 4, 2], ctrs, 0) == 1592
# The VCG payments and the equilibrium bids b* of Theorem 1.
assert vcg_payments(values, ctrs) == ([0, 1], [402, 398])
assert eos_bids(values, ctrs) == [10, Fraction(402, 200), 2]
b = eos_bids(values, ctrs)
assert revenue(b, ctrs) == 800 == sum(vcg_payments(values, ctrs)[1])
def test_edges() -> None:
assert gsp([], [3, 2]) == ([], [])
assert gsp([5], [3, 2]) == ([0], [0])
assert gsp([5], [3, 2], reserve=2) == ([0], [2])
assert gsp([1, 5], [3, 2], reserve=2) == ([1], [2])
assert gsp([5, 5, 5], [3, 2]) == ([0, 1], [5, 5])
# One slot: GSP is the Vickrey auction.
assert gsp([3, 9, 7], [1]) == ([1], [7])
def test_truthful_revenue_at_least_vcg() -> None:
rng = random.Random(1)
for _ in range(500):
n, k = rng.randrange(1, 6), rng.randrange(1, 4)
values = [rng.randrange(0, 20) for _ in range(n)]
ctrs = sorted((rng.randrange(1, 10) for _ in range(k)), reverse=True)
winners, pay = vcg_payments(values, ctrs)
assert gsp(values, ctrs)[0] == winners
assert revenue(values, ctrs) >= sum(pay)
def random_instance(rng):
n, k = rng.randrange(2, 5), rng.randrange(1, 4)
values = rng.sample(range(1, 30), n)
ctrs = sorted(rng.sample(range(1, 20), k), reverse=True)
return values, ctrs
def test_eos_bids_are_envy_free_equilibrium_with_vcg_outcome() -> None:
rng = random.Random(2)
for _ in range(300):
values, ctrs = random_instance(rng)
b = eos_bids(values, ctrs)
assert is_nash(values, b, ctrs)
assert is_envy_free(values, b, ctrs)
assert is_locally_envy_free(values, b, ctrs)
winners, prices = gsp(b, ctrs)
vcg_winners, vcg_pay = vcg_payments(values, ctrs)
assert winners == vcg_winners
assert [ctrs[s] * prices[s] for s in range(len(winners))] == vcg_pay
def test_envy_free_equilibria_on_a_grid() -> None:
# Every envy-free bid profile (Varian's symmetric Nash equilibrium) is
# efficient and pays for each slot at least its VCG payment.
rng = random.Random(3)
grid = range(0, 8)
count = 0
for slots in (2, 2, 2, 1, 1, 1):
values = rng.sample(range(1, 8), 3)
ctrs = sorted(rng.sample(range(1, 6), slots), reverse=True)
vcg_winners, vcg_pay = vcg_payments(values, ctrs)
for bids in itertools.product(grid, repeat=3):
bids = list(bids)
if not is_envy_free(values, bids, ctrs):
continue
count += 1
winners, prices = gsp(bids, ctrs)
assert winners == vcg_winners
assert all(ctrs[s] * prices[s] >= vcg_pay[s] for s in range(len(winners)))
assert count > 0
def test_locally_envy_free_can_be_below_vcg() -> None:
# One slot, values 5, 1, 8 and bids 10, 2, 0: a locally envy-free Nash
# equilibrium in which the bidder with value 8 loses and revenue is 2 < 5.
values, bids, ctrs = [5, 1, 8], [10, 2, 0], [1]
assert is_nash(values, bids, ctrs)
assert is_locally_envy_free(values, bids, ctrs)
assert not is_envy_free(values, bids, ctrs)
assert gsp(bids, ctrs) == ([0], [2])
assert vcg_payments(values, ctrs) == ([2], [5])
def test_truthful_bidding_is_not_dominant() -> None:
rng = random.Random(4)
found = 0
for _ in range(200):
values, ctrs = random_instance(rng)
if len(ctrs) < 2:
continue
for i, v in enumerate(values):
truthful = utility(v, values, ctrs, i)
others = [values[j] for j in range(len(values)) if j != i]
for c in {o + d for o in others for d in (-DELTA, DELTA) if o + d >= 0}:
if utility(v, values[:i] + [c] + values[i + 1:], ctrs, i) > truthful:
found += 1
break
assert found > 0
History
Overture (formerly GoTo.com) sold search ads from 1997 in a pay-per-click auction where each winner paid its own bid. Bids changed quickly in cycles, and in 2002 Google introduced the rule that each winner pays the next bid, and Overture then adopted it. Edelman, Ostrovsky and Schwarz (2007) named the format the generalized second-price auction, showed that it is not truthful, and found its locally envy-free equilibria; Varian (2007) studied the same equilibria as symmetric Nash equilibria and tested them on data.
References
- Benjamin Edelman, Michael Ostrovsky and Michael Schwarz, Internet advertising and the generalized second-price auction: selling billions of dollars worth of keywords, American Economic Review 97(1) (2007), 242-259, Section II (the rules of GSP and the example in which truthful bidding is not dominant) and Remark 1 (for the same bids, GSP payments are at least the VCG payments)
- Hal R. Varian, Position auctions, International Journal of Industrial Organization 25(6) (2007), 1163-1178, the model of position auctions and the symmetric Nash equilibria of the next-bid price rule
- Tim Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016, Lectures 2 and 3 (sponsored search auctions and the GSP auction)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag ATPJNQ Edit this page History Report an error Markdown