<blockquote>
<p>a) Can an economic state be boiled down to a mathematical equation like this</p>
</blockquote>
<p>Economic states can be boiled down to equations, but not equations like <span class="math-container">$price=demand/supply$</span> that makes little sense. Of course, in a game development you can model your economy in whatever way you want but if you want it to have at least some economic rationale behind it that would not work.</p>
<p>At a very minimum you should at least model simple linear demand and supply for every market where you want to determine prices. You can also increase the complexity by interconnecting them but I am not game developer and I have no idea if that would be feasible to program it in your  game (although when I was younger I used to play video games and modded version of Victoria II from paradox had quite decent realistic economic system, so it is possible to do it within some games at least. But I do not remember which mods was I using - some mods that claimed to improve realism of the economy, you might want to check that out, although its not necessary best simulation of medieval economy as it was set in Victorian era).</p>
<blockquote>
<p>b) If so, how would I at least approximate an economy like this?</p>
</blockquote>
<p>At a minimum you should model some reasonable supply and demand. If villagers have only 25 units of iron and it is an endowment (villagers do not produce iron just happen to have one) and there are no alternative suppliers then supply will be:</p>
<p><span class="math-container">$$S=25$$</span></p>
<p>Next when it comes to demand the smith might want to have 100 pieces of iron, but not at any price. It is not realistic to think that he would demand 100 pieces at some exorbitant prices.</p>
<p>If you want to take short cut you can simply model it as some downward sloping linear function. For example, the demand of smith could be given by:</p>
<p><span class="math-container">$$D=200-2p$$</span></p>
<p>Then to find a price you just equate supply and demand:</p>
<p><span class="math-container">$$25=200-2p \implies p=87.5$$</span></p>
<p>If you want to make it more realistic you can model smith as a producer where demand will depend on how much profitably he can sell products from iron. You would have some smith's  profit function:</p>
<p><span class="math-container">$$\Pi = p(q(i))q(i) - c(q(i))$$</span></p>
<p>where <span class="math-container">$q$</span> would be quantity of ploughs or swords or whatever produced. The production of <span class="math-container">$q$</span> would depend on iron for example <span class="math-container">$q= \sqrt(i)$</span>, <span class="math-container">$p(q)$</span> would be the inverse demand function of knights/villagers that buy the <span class="math-container">$q$</span> swords/ploughs from the blacksmith. It could be for example, <span class="math-container">$p= 100-q$</span> you can make up some other numbers you consider reasonable. Then the cost function <span class="math-container">$c(q)$</span> would tell you how much it costed to produce the sword/plough which in this case would the cost of iron (assuming for simplicity no labor costs which could be added but it would make the problem more complex as we would have to then model separate labor market). You will want to leave the cost as some <span class="math-container">$c$</span> because you want to find not just quantity of iron demanded at some specific price but at any price.  Then you can simply solve it for the <span class="math-container">$i^*$</span> using calculus in terms of <span class="math-container">$c$</span> and it will give you the demand function of the smith <span class="math-container">$i(c)$</span>. Then this demand function can be equated to supply to find out what the price of iron c would be.</p>
<p>You can add infinite amount of complexity on top of it depending on how realistic you want to get.</p>

CC BY-SA 4.0
2024-09-28T15:12:11.030Z
@1muflon1 Hi, could you clarify the part that follows "Then you can simply solve it for the i*........". What do you mean by "using calculus" to solve i(c). We already know c's formula - just have to describe it in terms of i, right?
Aung Khant
CC BY-SA 4.0
2024-09-28T22:26:25.537Z
@AungKhant that is not enough, the formula we know describes the profit of the blacksmith, but ideally you want to make it dynamic. I assume you want the blacksmith in the game to behave as real business man and try to maximize the profits. If that’s the case in order to find quantity that maximizes the profit you first need to derive the first order conditions (using calculus) and then solve the FOCs algebraically to get optimum quantity the smith should produce
1muflon1
CC BY-SA 4.0
2024-09-29T01:03:28.327Z
@1amuflon1 ok so, this is how I understand: You have Proft = Revenue - Cost. To maximize profit, you differentiate with respect to q ( quantity of sword sold). Then you have Marginal Revenue = Marginal Cost (this is what you meant by "use calculus" to solve?).  Solve this and then you will have value of "q" that maximizes profit (and by extension you know "i" via "q" relation). That is all right? I am not missing anything else?
Aung Khant
CC BY-SA 4.0
2024-09-29T07:55:03.823Z
@AungKhant yep that’s it
1muflon1
CC BY-SA 4.0
2023-01-07T08:33:18.533Z
After the conversation in the comments of my actual question I had come up with an idea for each item to be given a value as a range as opposed to a base price, and to provide a shopkeep of any type with a list of items they keep and the range they would like to keep stock of each item, and for any given item get the percent between their min and max stock count that the actual count is, and use that to interpolate between the range of prices for that item.
RWolfe
CC BY-SA 4.0
2023-01-07T08:23:38.700Z
2023-01-07T08:29:51.550Z
2023-01-07T08:29:51.550Z
1muflon1
<p>First, I'm not absolutely certain if this site is the correct one for this question as it covers multiple topics simultaneously.</p>
<p>Second, Some context to my question, I'm working on an in-game economy for a single-player video game, and want the players actions (specifically buying and selling of items) to affect and hopefully be affected by the 'world's economic state', for example <code>A blacksmith needs 100 units of iron, but only 25 units are in circulation therefore the cost to buy iron increases</code>, while adding and removing items from the games economy is simple, calculating the cost an Item should have is not quite so simple, for the time being I'm using a simple algorithm where if there is no supply the 'multiplier' for cost would be equal to the demand, which for a needed item with no supply could reach astronomical prices and if there is supply the calculation is <code>demand / supply</code> which with low numbers eg <code>demand: 2, supply: 1</code> seems an unreasonable increase in price.</p>
<p>The actual question is somewhat two-fold, a) Can an economic state be boiled down to a mathematical equation like this; and b) If so, how would I at least approximate an economy like this?</p>
<p>EDIT</p>
<p>To clarify the example I gave, the blacksmith is requesting 100 units, but the region/village only has 25 units available in storage.</p>

CC BY-SA 4.0
2023-06-06T14:33:00.170Z
This may help: https://www.econstor.eu/bitstream/10419/268397/1/fiatmoneyvalue.pdf - it discusses an agent based model in which prices are continuously adjusted. In particular look at section 2 where it describes a "Sellers’ pricing policy" and "Purchasers’ propensity to spend".
Mick
CC BY-SA 4.0
2023-10-04T16:03:18.003Z
You could use an inverse relationship. If the smith buys Q_0  when the price is P_0, then if the price changes to P_1 the smith buys Q_1 = Q_0 * (P_0 / P_1) . In economics this would be an "elasticity" of 1.
Daniel
CC BY-SA 4.0
2023-01-07T04:45:26.420Z
@user253751 via the player or other NPC (if I add any mining NPC's to the game) adding more iron into circulation, more specifically by mining and selling ores.
RWolfe
CC BY-SA 4.0
2023-01-07T04:51:27.610Z
That would depend on the priority assigned to the 'project' the blacksmith is trying to complete
RWolfe
CC BY-SA 4.0
2023-01-07T05:00:06.730Z
I was not planning on the idea of bargaining, more the price point for a given item being 'updated' on in game daily basis, effectively more like publicly known exchange rates which while it fluctuates several times per day, the so called table only updates once per day.
RWolfe
CC BY-SA 4.0
2023-01-07T05:00:21.310Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/141866/discussion-between-rwolfe-and-user253751).
RWolfe
<supply-and-demand><simulations>
How to simulate supply and demand in a virtual environment
RWolfe
# How to simulate supply and demand in a virtual environment

(Asked by: username_0 on 2023-01-07)

First, I'm not absolutely certain if this site is the correct one for this question as it covers multiple topics simultaneously.

Second, Some context to my question, I'm working on an in-game economy for a single-player video game, and want the players actions (specifically buying and selling of items) to affect and hopefully be affected by the 'world's economic state', for example `A blacksmith needs 100 units of iron, but only 25 units are in circulation therefore the cost to buy iron increases`, while adding and removing items from the games economy is simple, calculating the cost an Item should have is not quite so simple, for the time being I'm using a simple algorithm where if there is no supply the 'multiplier' for cost would be equal to the demand, which for a needed item with no supply could reach astronomical prices and if there is supply the calculation is `demand / supply` which with low numbers eg `demand: 2, supply: 1` seems an unreasonable increase in price.

The actual question is somewhat two-fold, a) Can an economic state be boiled down to a mathematical equation like this; and b) If so, how would I at least approximate an economy like this?

EDIT

To clarify the example I gave, the blacksmith is requesting 100 units, but the region/village only has 25 units available in storage.

**Tags:** supply-and-demand, simulations

> **Comments:**
> **username_0**: @user253751 via the player or other NPC (if I add any mining NPC's to the game) adding more iron into circulation, more specifically by mining and selling ores.  
> **username_0**: That would depend on the priority assigned to the 'project' the blacksmith is trying to complete  
> **username_0**: I was not planning on the idea of bargaining, more the price point for a given item being 'updated' on in game daily basis, effectively more like publicly known exchange rates which while it fluctuates several times per day, the so called table only updates once per day.  
> **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/141866/discussion-between-username_0-and-user253751).  
> **username_1**: This may help: https://www.econstor.eu/bitstream/10419/268397/1/fiatmoneyvalue.pdf - it discusses an agent based model in which prices are continuously adjusted. In particular look at section 2 where it describes a "Sellers’ pricing policy" and "Purchasers’ propensity to spend".  
> **username_2**: You could use an inverse relationship. If the smith buys Q_0  when the price is P_0, then if the price changes to P_1 the smith buys Q_1 = Q_0 * (P_0 / P_1) . In economics this would be an "elasticity" of 1.  

---

## 1 answers

### Answer by username_3 on 2023-01-07. Score: 1

> a) Can an economic state be boiled down to a mathematical equation like this

Economic states can be boiled down to equations, but not equations like $price=demand/supply$ that makes little sense. Of course, in a game development you can model your economy in whatever way you want but if you want it to have at least some economic rationale behind it that would not work.

At a very minimum you should at least model simple linear demand and supply for every market where you want to determine prices. You can also increase the complexity by interconnecting them but I am not game developer and I have no idea if that would be feasible to program it in your game (although when I was younger I used to play video games and modded version of Victoria II from paradox had quite decent realistic economic system, so it is possible to do it within some games at least. But I do not remember which mods was I using - some mods that claimed to improve realism of the economy, you might want to check that out, although its not necessary best simulation of medieval economy as it was set in Victorian era).

> b) If so, how would I at least approximate an economy like this?

At a minimum you should model some reasonable supply and demand. If villagers have only 25 units of iron and it is an endowment (villagers do not produce iron just happen to have one) and there are no alternative suppliers then supply will be:

$$S=25$$

Next when it comes to demand the smith might want to have 100 pieces of iron, but not at any price. It is not realistic to think that he would demand 100 pieces at some exorbitant prices.

If you want to take short cut you can simply model it as some downward sloping linear function. For example, the demand of smith could be given by:

$$D=200-2p$$

Then to find a price you just equate supply and demand:

$$25=200-2p \implies p=87.5$$

If you want to make it more realistic you can model smith as a producer where demand will depend on how much profitably he can sell products from iron. You would have some smith's profit function:

$$\Pi = p(q(i))q(i) - c(q(i))$$

where $q$ would be quantity of ploughs or swords or whatever produced. The production of $q$ would depend on iron for example $q= \sqrt(i)$, $p(q)$ would be the inverse demand function of knights/villagers that buy the $q$ swords/ploughs from the blacksmith. It could be for example, $p= 100-q$ you can make up some other numbers you consider reasonable. Then the cost function $c(q)$ would tell you how much it costed to produce the sword/plough which in this case would the cost of iron (assuming for simplicity no labor costs which could be added but it would make the problem more complex as we would have to then model separate labor market). You will want to leave the cost as some $c$ because you want to find not just quantity of iron demanded at some specific price but at any price. Then you can simply solve it for the $i^\*$ using calculus in terms of $c$ and it will give you the demand function of the smith $i(c)$. Then this demand function can be equated to supply to find out what the price of iron c would be.

You can add infinite amount of complexity on top of it depending on how realistic you want to get.

> **Comments:**
> **username_0**: After the conversation in the comments of my actual question I had come up with an idea for each item to be given a value as a range as opposed to a base price, and to provide a shopkeep of any type with a list of items they keep and the range they would like to keep stock of each item, and for any given item get the percent between their min and max stock count that the actual count is, and use that to interpolate between the range of prices for that item.  
> **username_4**: @username_3 Hi, could you clarify the part that follows "Then you can simply solve it for the i*........". What do you mean by "using calculus" to solve i(c). We already know c's formula - just have to describe it in terms of i, right?  
> **username_3**: @username_4 that is not enough, the formula we know describes the profit of the blacksmith, but ideally you want to make it dynamic. I assume you want the blacksmith in the game to behave as real business man and try to maximize the profits. If that’s the case in order to find quantity that maximizes the profit you first need to derive the first order conditions (using calculus) and then solve the FOCs algebraically to get optimum quantity the smith should produce  
> **username_4**: @1amuflon1 ok so, this is how I understand: You have Proft = Revenue - Cost. To maximize profit, you differentiate with respect to q ( quantity of sword sold). Then you have Marginal Revenue = Marginal Cost (this is what you meant by "use calculus" to solve?).  Solve this and then you will have value of "q" that maximizes profit (and by extension you know "i" via "q" relation). That is all right? I am not missing anything else?  
> **username_3**: @username_4 yep that’s it  

---

