Agent-based modeling and simulation in US equity markets – Part 2

This is the second of an occasional series of posts on the application of agent-based modeling to US equity markets. We left off with the definition of a model and a brief overview of how economists use models to simplify reality. Agent-based models can be used to simplify reality as well. This post will tackle the nuts and bolts of ABMs.

Simulation

According to Wikipedia:

  1. Simulation is the imitation of the operation of a real-world process or system.
  2. Monte Carlo methods (or Monte Carlo experiments) are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results.
  3. discrete-event simulation (DES) models the operation of a system as a discrete sequence of events in time.

In my agent-based model of the US equity Tick Pilot, I employ simulation to imitate the real world process of order submission to a centralized limit order book and the system that book uses to match orders and generate prices and sizes for trades. Note: the US equity markets are not centralized – they are fragmented. The model simplification makes the simulation much easier to code and faster to run without harming any inference regarding market-maker profits or participation. I also employ Monte Carlo methods with pseudo random number generators to produce distributions of results, thereby facilitating statistical tests for significance. And finally, the model employs discrete-event simulation. The first discrete event is the time step. For each step, a subset of the traders is chosen and randomly queued. Only one agent trader can be interacting with the order book at a particular instant in computer time. This is a very simple discrete-event simulation. In reality, many traders are attempting to interact with the order book. But, there too, only one event can be processed at any very small point in time. Otherwise, there is indeterminacy in the book – much like when a database is being updated and accessed at the same time.

How would you explain simulation to an accountant, attorney or MBA?

Agent-based modeling

According to Wikipedia, an agent-based model (ABM) is a class of computational models for simulating the actions and interactions of autonomous agents (both individual or collective entities such as organizations or groups) with a view to assessing their effects on the system as a whole. This definition is simple enough but doesn’t really describe what an agent-based model is or even what an agent is. Bookstaber (2017) distills the essence of ABMs:

  1. A set of agents that are typically heterogeneous and that can act with some degree of independence or autonomy. No centralized control.
  2. At the start of each time period each agent observes its environment and acts according to its own heuristic. The agent’s environment is only a local view of the overall system.
  3. Agent’s actions change the environment.
  4. In the next period, each agent sees its new environment, altered based on the actions of the previous period, and takes action again. Thus there is an interaction between the agents and the environment, and between agents.
  5. The components are the agents, the environment, heuristics, interactions, and dynamics.

Let’s apply the essence of ABMs to my Tick Pilot model to see if it satisfies Bookstaber’s view of an ABM.

  1. The agents in my model are heterogeneous. There are a variety of agents, including generic liquidity providers, market makers, liquidity takers, and penny jumpers. Many of these agents have randomly generated arrival times (i.e., there is heterogeneity within agent classes in addition to among agent classes). Some agents choose limit order prices at random. The choice of their arrival times is independent and no agent is constrained by the activities of other agents.
  2. All of the agents view the top of the book (i.e., the best bid and ask prices and associated sizes at those prices are the agent’s environment). The agents take actions based on that specific view of the book. The agents have no insight into what other agents have done or will do in the future.
  3. When liquidity providers, market makers and penny jumpers arrive, they (usually) add orders to the book, thereby altering the state of the environment. These agents potentially cancel outstanding orders, which also alters the state of the environment. And finally, liquidity takers alter the book when they trade with standing limit orders.
  4. After each discrete event in the queue during one time step, the selected agents view any changes to the top of the book and act accordingly. The takers and providers interact with each other via the book.
  5. The components are the trader agents, the limit order book, the rules that the traders use to generate orders, the interactions with the limit order book, and the dynamics of price and size traded and available at each discrete step.

My model varies somewhat from Bookstaber’s essence of ABMs because of the artificiality of the time step and the fact that several events can occur in one time step. It is best to view each discrete event as occurring at a specific fraction of a time step. This is consistent with how real market data is generated: if two or more messages or transactions occur within the minimum time step (a microsecond in most US equity market feeds), then we do not know their exact time stamps, but we do know the order of the events within that microsecond. And, in my model, each selected (queued) agent receives an up-to-date view of the top of book before they act within each time step.

Tesfatsion provides seven requirements for agents and agent-based models (MP1 – MP7 are taken directly from the linked website without alteration):

 (MP1) Agent Definition: An agent is a software entity within a computationally constructed world capable of acting over time on the basis of its own state, i.e., its own internal data, attributes, and methods.

(MP2) Agent Scope: Agents can represent individuals, social groupings, institutions, biological entities, and/or physical entities.

(MP3) Agent Local Constructivity: The action of an agent at any given time is determined as a function of the agent’s own state at that time.

(MP4) Agent Autonomy: Coordination of agent interactions cannot be externally imposed by means of free-floating restrictions, i.e., restrictions not embodied within agent states.

(MP5) System Constructivity: The state of the modeled system at any given time is determined by the ensemble of agent states at that time.

(MP6) System Historicity: Given initial agent states, all subsequent events in the modeled system are determined solely by agent interactions.

(MP7) Modeler as Culture-Dish Experimenter: The role of the modeler is limited to the setting of initial agent states and to the non-perturbational observation, analysis, and reporting of model outcomes.

Many of these are consistent with Bookstaber’s characterization of ABMs. But there doesn’t appear to be any role for the environment. I think if we re-characterize the limit order book as an institutional agent as defined in MP2, then there is some consistency.

How would you explain agents and agent-based modeling to an accountant, attorney or MBA?

Published by

Chuck Collver

Quant, Programmer, Data Scientist, Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s