🤔 efficient markets

(This was originally part of an application to Recurse Center, until I realized I went way over the character limit. So now it serves as a devlog for Georgetown.)

I’ve been working on a multi-player city simulation game (Georgetown); one of my primary motivations for working on the project is to develop a better understanding of various aspects of micro- and macro- economics; I find that reading only gets me so far, I have to model something to really understand it. Initially, I implemented markets for food and shelter as one-sided auctions (ex. a fixed demand for food, but a variable-priced supply). To add more realism and more interesting behaviour, I realized I would have to implement two-sided markets (variable-price supply and variable price demand), and I was mulling over how to do it. 

In a two-sided market multiple “sellers” offer widgets, each having their own cost of supplying that widget. Various “buyers” are interested in acquiring widgets, each with their own value ascribed to having a widget (thus the maximum they are willing to pay). Who should get which widget from whom, at what price?

How does a food market “figure this out” in the real world? (multiple vendors selling apples, etc.)

Perhaps, I could randomize the order of the buyers and have each one purchase from the lowest cost supplier, until no more deals could be made. Or, the inverse (randomize the order of the sellers). Or, randomize both lists, and repeatedly “pop” off the top-most pair that is satisfied, and set each transaction price in the middle. Or something else? (All of these seemed pretty arbitrary. I set things aside for a few days to stew in my subconscious.)

Ah. Could I maybe use the “economics 101” diagram of intersecting supply-demand curves? That is: order the sellers from cheapest-to-most-expensive, and the buyers from most-to-least-willing, find where they intersect, use that as the price, and charge it to those who are willing to transact at that price. But is that how it “really works”, or is it just a toy example for textbooks? (Some googling and LLMing later… Yes, it does model real-world results.) We’re going to call this “Strategy A”.

But what about all those market participants that don’t get to participate in this model? (ie. the ones where the price was too high for buyers and too low for sellers). Aren’t there buyer-seller match-ups where everyone could participate? For example, match the highest buyer with the highest seller and so on. This wouldn’t guarantee that everyone participates, but would definitely increase participation compared to “Strategy A”. We’re going to call this “Strategy B”.

Ah… but is “maximizing participation” or “maximizing the number of transactions” something that matters? If real-world buyers and sellers had to delegate their decisions to a black-box, what would they look for?

Some internet sleuthing later… and it turns out we could measure “the total gain in utility”, ie. the difference between the utility of all participants before all the transactions, and the utility after. More plainly: based on the value ascribed by the buyers and sellers to the widgets, we could sum up the value of what the buyers and sellers own before and after the transactions (sellers losing their widgets but getting money instead, buyers losing their money and getting widgets instead). 

Perfect, now I had a metric to use to prove that “Strategy B” is better. I wrote a script to try out the two market strategies and score them. And… “Strategy A” had a higher score. Hmmm. I changed the script to generate hundreds of random markets. “Strategy A” always tied or beat “Strategy B”. Dang. 

Then I decided to simulate all potential match-ups for a small market (using a trusty combinatorics library), and… the best solutions always scored the same as “Strategy A”.

Now, of course, the Wikipedia page for “Double Auctions” mentions that the “Average Mechanism” (the academic term for “Strategy A”) is “Economically Efficient” (the academic term for “results in the highest gain in utility”). But I’m happy to have proved it to myself.

And so, the “most fascinating” bit of all of this for me is that the “simple solution” (“Strategy A”) is optimal AND what tends to happen naturally in an open marketplace. The invisible hand at work! Beautiful.

(Turns out that “Strategy A” does have a flaw: in an auction scenario, it doesn’t incentivize participants to be truthful about how they value their widgets. Other strategies fix that, but that is a story for another day…)

☙

And for posterity, the 1500-character version:

I’ve been working on a SimCity-like game, partly to develop a better intuition of economics; reading only gets me so far, I like to model things to really understand them.

Recently I was considering how to simulate two-sided markets: where multiple sellers offer widgets (each with their own cost-to-supply) to various buyers (each with a max price they are willing to pay). Who should get which widget, from whom, at what price?

After some half-baked ideas (elided for brevity), I considered the “Econ 101” diagram of intersecting supply-demand curves. That is: match the cheapest sellers with the highest buyers, until they intersect and use that price.

Apparently it is realistic… but I was annoyed that many buyers and sellers were excluded (because the resulting price doesn’t work for them). Aren’t there other match-ups that might be better? 

What is “better”? 

…we could measure “the total gain in utility”, ie. the difference between the utility of the buyers and sellers before all the transactions, and after.

I wrote a script that simulated various market strategies in thousands of random markets… and… “the classic” always did best (or tied for best).

Then I decided to simulate all possible match-ups for a given set of participants, and… “the classic” still “won”.

So the fascinating thing is that the simple greedy algorithm is optimal. 

Now, of course, the relevant Wiki page mentions that the “Average Mechanism is Economically Efficient”, but I’m happy to have proved it to myself.

2026-01-21