Agent-based Market Model

Excerpt source code available in my Github 

This is my largest agent-based modeling for a realistic economy model I developed since 2018. At first this was only a part of my project for building a sustainable and realistic economy game. Later I find that the design of the macroeconomy simulation is already an interesting project. Since then I gradually added more and more components in the model. It aims at studying the interaction among consumers, firms, banks within and across countries. 

Algorithm

The simulation includes five major components: 

Routine

In the simulation, one step corresponds to one business day (therefore 251 business days per year). The firms, banks and markets take turns for their preparation and operations. Some important ones are:

Morning

Afternoon

There are other routines by the bank, firms in the monthly and annual basis, such as:

Random Events

The majority of the simulation is based on deterministic rules. To allow diversity in the simulations, random events are triggered spontaneously to create "shocks" in the system, and we studied how the agents adopt to these events. They include:

Good Market 

The dynamical evolution of demand and supply constantly changes the prices of products in the market. The price is output as ohlc (open-high-low-close) structure every 21 steps (days, i.e. a month). For simplicity I only plot the close price. 

The difference of two types of product can be clearly seen. Some common service, like research, has a similar shape in its price, meaning that the price is closer to equilibrium, and differs due to the currency exchange rate. For some more advanced product, the demand and supply shows deviation among countries. This suggests that the price is more elastic due to the scarcity of supply. 

Sudden changes of the price usually corresponds to a change of fiscal policy, where the consumers become richer/poorer for their consumable. 

Forex Market

Another feature in this agent-based model is that agents can sell their product in one of the market of neighbouring cities. In this program, when the net price of goods in neighbouring cities is higher, shops will sell the goods in those cities. As a result, the shop earns foreign currency. Then the shops will exchange the earned foreign budget back to its local currency, so that it can buy new material for the next round. 

For illustration purpose, I set the liquidity comparable to the goods to make the effect more visible. W can see there are short pleateau when there is no economy state change. But when it changes, it leads to rapid rise or drop (~20 - 40%) in the exchange rate. 

Production

I also completed a GUI interface so that I can understand the current flow of product and currency in the system. This will assist me to get more insight about the complex interaction among all agents, so that I can improve the models to reproduce more realistic behaviour.

The design of my GUI attempts to be as simple as possible.