(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.