Introduction to Agent-Based Models with respect to the Future of Macroeconomics

Introduction to Agent-Based Models

with respect to “The Future of Macroeconomics”

Gosper's Glider Gun (Wikipedia)
Gosper’s Glider Gun (Wikipedia)

Pre-Post: Thank You NYC BlogoTweetosphere

I’m such a spoiled kid. A few months ago I was planning a long labor day weekend in NYC, so I sent out requests to a few of my heroes in the economics, finance, and math blogosphere to meet me for a lunch and/or a dinner. It was amazing getting to meet and interact with people who have been such huge influences on things-I-like-to-think-about — having been reading some of them for over five years now. Sometimes these situations can end poorly, but I am lucky enough to only have increased admiration for everyone I met. I’d like to thank (and plug) the following heroes for showing up and teaching me a thing or two about a thing or two:

I’ll be back soon. Let’s meet up again.

Now for the good stuff…

Rumble in the Econojungle

In sequence:

For those of you just tuning in, I’ll attempt to sort out this clüsterfüken shortly. For now it’s important to know that the heart of this debate is over what an ABM is or isn’t, and what economic researchers can or can’t do with them. And here everyone gets it slightly wrong. But everyone also gets it mostly right. After a few minor corrections, I believe all differences will be reconciled. However, in order to understand these minor differences we have to be able to see things through the lens of a programmer — the person who actually understands and decides how an ABM functions. After all: no software, no ABM.

My perspective on this topic comes from my work where we have designed, coded, and implemented an ABM framework which we use (and improve, and debug) daily to both conduct research and actually trade in various markets. We’ve had a surprising amount of success modeling microstructure and getting simulations to reconcile nearly spot on with reality. It’s pretty damn cool. In my academic spare time over the past few years, I’ve spent much of it thinking through abstractions of the various ways people implement ABMs, trying to arrive at more generalized forms — and then trying manipulate the properties of those forms to discover some interesting things about ABMs themselves.1 Perhaps on some far future day when I’ve automated myself out of this job, I’ll join the others searching for sexy, macro-truths.

In the Beginning: Life, Conway’s Game of

Most broadly, an agent-based model is a computer simulation where things do stuff in an environment. Slightly more specific, the things are called ‘agents’ and are a set of unique separate entities — e.g. cars as agents to model traffic jams, or cells as agents to model tumor growth. The environment is some bounded region, like a grid or a terrain, where the agents do their stuff. The stuff can be anything, or perhaps even nothing — an agent can exist just to take up space (sort of like my blog posts, self burn). Perhaps the most ubiquitous of all possible stuffs is “living” and “dying”. This idea was introduced in what is commonly called the original ABM: John Conway’s Game of Life.

Though not referred to as an agent-based model at the time of its creation, Conway’s has become the universal go-to for explaining what an ABM is. My first encounter with it was in my AP Computer Science class, taught by the amazing Chap Percival, during an introductory lab on simulations where we actually got to code it in. Both House and Sethi refer to Conway’s at various points to make their respective cases about ABMs — which is great because we can apply the structure of the game in several contexts to see where they are each uniquely mistaken.

For nostalgia purposes I’ll quote from my original textbook, c++ for you++ (actual name):

The Game of Life is a simulation game introduced by British mathematician John Conway. It became popular in 1970, when Martin Gardner brought it to the attention of readers of Scientific American. The simulation takes place on a rectangular grid. Each cell of the grid may be “dead” (vacant) or “alive” (occupied by an “organism”). The initial configuration of alive cells goes through a series of generations. In each successive generation, some alive cells die and some new cells are born in vacant places depending on the total number of alive neighbors of the cell.

Putting this in the context of my ABM description:

  • Environment: rectangular grid
  • Things/Agents: a single grid-cell “organism”
  • Stuff/Behavior: live, die, or get born

Every ABM must have rules which govern the behavior of the agents.

The “births” and “deaths” follow the following rules:

  1. A neighbor of a given cell has a common side or corner with that cell. Each cell inside the grid has 8 neighbors.
  2. An alive cell with two or three alive neighbors remains alive in the next generation; an alive cell with less than two alive neighbors dies (of loneliness); a cell with four or more alive neighbors also dies (of overcrowding).
  3. A vacant cell becomes alive in the next generation if it has exactly three alive neighbors.
  4. All births and deaths take place at exactly the same time, so that the change from one generation to the next is instantaneous.

Based on the starting configuration of the grid, commonly referred to as the “initial conditions”, with each iteration (of “time”) cells will either die, get born, or remain unchanged. This procedure typically takes place until either (1) the program terminates because no cells can change according to the rules, or (2) the same pattern repeats itself ad infinitum. That’s pretty much all there is to it. It’s important to note that the rule-book doesn’t specify any particular mechanism for how the cells exhibit their behaviors. Sure, it notes that they might die “of loneliness” or “of overcrowding”, but when it comes time to actually program these rules, there are many different paths which lead to implementing the same rules.

Cat Skin Triptych

“There’s more than one way to skin a cat,” was frequently heard in my early programming classes. If you can get past the literal meaning, the figurative translation is that there are many different ways to write code which achieve the same result. Despite seeming obvious, this has profound implications for how ABMs can behave. Specifically: they can do anything you want them to do. Unfortunately, the economists in the debate clearly do not understand this. Both House and Sethi make horrible assumptions unnecessarily restricting the behavior of ABMs. This is likely a result of them being restricted to using the tools they have, rather than being able to make their own. But life is easier when you get to make the rules. Let’s go through some different implementations.

Environmentally Driven

When discussing the differences between ABMs and DSGE models, Professor House writes:

Probably the most important distinguishing feature is that, in an ABM, the interactions are governed by rules of behavior that the modeler simply encodes directly into the individuals who populate the environment…

A second key difference is that the interactions are often restricted to individual (or at least limited) interactions…

Not so fast. The environment doesn’t need to be inert. It can affect and drive the agents just as much as agent-to-agent interaction. There doesn’t actually need to be any interaction at all.


  • An alive cell with less than two alive neighbors or with four or more alive neighbors gets struck by lightning and dies.
  • The environment spontaneously creates an alive cell in a vacant cell with exactly three alive neighbors.

In this implementation the rules are not encoded into any of the individuals — i.e. they don’t do anything. They are at the whim of the environment. Overall this system is just as deterministic as any other way of coding the rules. Further, a system with different types of agents isn’t bound to any specific type of interactions; the limiting factor is the will of the designer.

(House’s third point doesn’t make any sense so I ignore it)

Individually Driven

When attempting to correct House, Professor Sethi writes:

What you cannot have in an ABM is the assumption that, from the outset, individual plans are mutually consistent. That is, you cannot simply assume that the economy is tracing out an equilibrium path.

Well sure you can. Consider:

  • An alive cell with less than two alive neighbors or with four or more alive neighbors kills itself.
  • If a vacant cell with exactly three alive neighbors exists, the three neighbors get together and have a baby in the vacant cell. (don’t ask, odd species)

None of these plans make the behaviors of the cells inconsistent with each other. Perhaps each cell gains some utility by staying alive, but it can’t change its strategy. So even if a cell knows it’s going to die in some eventual iterations by giving birth to a new cell, it does so anyway. This is fundamentally no different than an equilibrium model.

In fact, studying the macroscopic behavior generated by a set of initial conditions is one of the primary interests in the game. As I previously noted, the game usually persists until no more moves can be made, referred to as stabilization, or continues ad infinitum. ConwayLife is a whole wiki dedicated to researching these various behaviors. Fun facts: the pattern R-pentomino takes 1103 generations to terminate; the Gosper’s Glider Gun at the top of this post repeats forever

Some Combination

By now you’re probably bored of hearing about different ways to achieve the same deterministic result. Fair enough; I agree. Let’s assume we can use some combination of the previous rules and it works just fine.

More interesting behaviors arise when we relax the hard rules a bit. Suppose that the lightning only has a 50% chance of killing its target. Suppose the lonely cell has a small chance of being a happy hermit. Or suppose that during the three-way-child-rearing one of the cells gets jealous and kills another. Each of these adjustments can have tremendous long term effects on the macroscopic view of the environment.

This is where the power of ABMs is really exposed. It can show us which of our rules the overall system is sensitive to. And it has the ability to show us what a deterministic system can evolve into when we add elements of indeterminism.

This Too Is Math

Functionally, there is no difference between a deterministic agent-based model and a numeric solution. Therefore, running an ABM can be thought of as providing a morphism from an ABM specification to some underlying system of equations.

So House is correct when he notes:

In fact, the first time I read Rajiv’s post, my initial thought was that an ABM with a rational decision rule would be essentially a DSGE model. All actions in DSGE models are based on private beliefs about the system. Both the system and the beliefs can change over time.  I for one would be very interested if there were any ABMs that fit Rajiv’s description that are in use today.

Yes, an ABM can be specified to represent any DSGE model.

The unfortunate reality is that the economists working on ABMs, like Sethi, have no interest in doing that. In an email conversation this past winter with Professor Robert Axtell, whose great work on systemic risk I previously covered, he was fairly adamant about eschewing the broad concept of utility in his ABMs:

[As] you probably know, we are living through the ‘behavioral revolution’ in economics and so we try not to use explicit utility functions that are then optimized. Rather, we write down empirically-grounded rules of behavior and let the agents follow these. This implicitly specifies some kind of utility function, I suppose, but that is not the way we normally think about it.

And while I agree that in the long term this is probably the way to go, you have to crawl before you can run. If the people writing down DSGE’s can be shown how much easier it would be to parameterize them as an ABM, and then be shown that they achieve the same answers, this would be a gigantic step toward mainstream acceptance.

Not only that, as previously discussed, having full control over the assumptions and rules which go into the system allows us to alter them at will. Therefore, an ABM which replicates an existing DSGE can be modified to relax certain assumptions and essentially function as a solver of the resulting system, which would have otherwise been unsolvable if not for the original assumptions.

In the end, given that ABMs can represent all canonical economic models, and given the relative ease with which you can specify an ABM, there is no reason that the language of agent-based modeling won’t become the standard for how we understand and teach economics. The economist who shuns these models is, quite literally, using pen and paper while the rest of the world has computers.