# Simulating a market economy

This topic is 3787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I am designing a market economy for my game. I would like some opinions on it before I start implementing it, to see if there's anything I've overlooked. The post is rather long, but well thought through, I think. The game is a realtime, single player, strategy sim game. There are around 200 agents (or NPCs) in the game - they are autonomous. There will be a number of types of goods in the game - max. 10-20 I think. Each agent can hold a stock of items of a given type. Items are regularly consumed and disappear from the agent's stock. To create demand, I will equip each agent with a utility function for each good. The function relates quantity of the good that the agent already owns, to a utility value of gaining one more item. The utility value will be 'per price' so that comparing the utitlity of high priced items with cheap items will be easier. When it is time for the agent to go shopping, he will have to decide what to buy with the money he has. This means solving the 'Utility maximization problem' - picking a package of goods that gives him the most utility for his money. I will make this package a sorted list of goods types. To keep it simple, a greedy algorithm will select goods items in the order of highest utility per price, by looking at the utility functions using the current market price for each good and the number of owned (or previously selected for buying) goods items as input. This algorithm repeats until there is no money left. Once he has his shopping list, he will find a vendor for each item on his list and buy them at the market price. If an item is not for sale anywhere, then he will try the next item. The unavailable good will by saved in a map, to record it as unsatisfied demand. Total unsatisfied demand will be used when the market price is corrected later. This situation (out-of-stock goods) creates two problems. The first "problem" is that the agent will not have spent all of his money like he intended. The second problem is that it may be possible for the agent to create 'too much' demand this way, he creates demand for both the good(s) that he didn't buy, and for the goods he bought instead. To set prices, I will have a routine that runs every so often at a time where nobody is buying. It will look at each goods type over a time period. It will calculate the shortage per time for each good from the recorded unsatisfied demand. Surplus per time uses the size of stockpiles at the vendors. In the case of a shortage, the price will be increased. By how much? I am thinking that it should go up relative to the shortage divided by the total supply (per time unit), which is also the amount bought in that time period. The price will then be capped with a minimum and maximum price. Similarly in the case of a surplus, the price will be decreased. Once this is in place, I want to make it possible for suppliers to enter and exit the market depending on their profits. I also want trade with the outside world. Prices on these markets will have to be simulated more abstractly, since there are no agents. What do you think? Will this design create a smooth-running economy, or else what problems could there be?

##### Share on other sites
I am afraid the design is still not good enough.

I want consumers to take distance to the supplier into account, since they need to transport themselves to get there. And I want suppliers located far from consumers to sell less.
So in the consumer's eyes the price should have an added cost based on distance.

This means that the package of goods to buy can not simply be a list of goods types, but must be a list of goods types + vendor information.

This will also make it necessary for each supplier to set his own prices. Otherwise they cannot compensate the buyer for being in an out-of-the way location, and selling less because of it.

##### Share on other sites
What a buyer does is select a list of (seller, money) pairs determining who they give money to, and how much money they give. A seller is a pair (retailer, commodity). The objective is that the utility function of that list is maximum, under the constraints that the sum of all money spent is less than the buyer's initial money amount, and that the money given to a seller divided by the price of that seller's commodity is less than the seller's stock. The utility function is a function of the total distance to be traveled (not taking into account multiple trips to the same retailer) and the amount of each commodity.

Since your utility function does not saturate (that is, buying twice as many is twice as good), the consumer will always want to buy as much as possible from any given seller. So, given your remaining money, you compute the utility of buying the entire stock (or as much as your money can buy) from every remaining seller with stock, and then select the transaction that provides the highest utility.

This, of course, does not solve the issue of movement entirely (since you don't take into account the fact that a given retailer may sell several commodities). That is a harder problem, since you need more look-ahead in your optimization function. To solve the movement issue, you need a more dynamic approach, where you will explore the tree of possibilities. This is exponential or factorial depending on whether you can move from retailer to retailer or can stay at home.

##### Share on other sites
These are good points. They lead me to make the following changes:

- Each supplier will set his own prices.

- Travel time will have a negative utility value assigned to it.

- When picking the goods to buy, I will evaluate only in-stock suppliers for each good type. All in-stock suppliers are evaluated, and the utility will be that supplier's price times the U/C value from the utility function MINUS the penalty from travel time.

- Only make a trip to one supplier at a time, then go home. At this point I don't want to go into minimizing route problems (like 'The travelling salesman').
More trips can be made however. Trips to the same supplier could be easily grouped together into one.

- There will not be a recorded shortage anymore, because buyers will (mostly) go to in-stock suppliers. Instead, the 'Raise price' signal for the supplier will be derived from the rate of his dwindling stock.

I am going to make some examples on paper to see if this would work...

##### Share on other sites
Have you found any interesting research papers or books on the topic? I'm interested in doing something similar (an economic simulation along the lines of Patrician II), and I'm sure it's a topic that's been explored in academia. I mean, Wikipedia turns up "agent-based computational economics" as a recognized field of study. I'll have to spend some time searching JSTOR before my university account expires.

##### Share on other sites
I hadn't looked before, but Wikipedia led me to this paper on Agent-based Computational Economics:

http://www.econ.iastate.edu/tesfatsi/hbintlt.pdf

It is a good introduction at least, and made me aware of the terms used in this field, such as 'Walrasian Auctioneer' - the process of setting the market price from demand and supply curves directly. This was sort of the method I considered in the original post. Then it goes on to look at what happens when it is up to agents to set the price themselves. I guess the paper shows the baseline of what is needed in a program to make the economy work.

Apparently there is a C# implementation of their program (Cook & Tesfatsion: ACE Trading World) somewhere but I have not found it yet.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633718
• Total Posts
3013522
×