## DEV Community # Supply, Demand, Price and Game Theory

How price can be determined with game theory.

How game theory and simple math can be used to calculate the price of something and how this model is super powerful to explain a lot of others interactions.

Before using game theory to explain the price, I'm gonna do something that I like to do when I'm trying to understand something, and that is trying to explain it by myself without reading anything else, so let's try to explain how the price of something can be decided first only using our intuition so we can start forming a picture of what we are talking about, then it will be easier to understand the math that tries to model the behavior.

You want to charge for a service or product, to simplify, let's say it's a service that virtually only takes time,
to charge for it you need a value that will cover your time spent doing it at least, so let's say your cost of living is 1000 USD/month, if you can perform this service 100 times per month then you can charge no less than 10 USD otherwise you can't pay for your cost of living, besides that you probably
want to have a positive balance, meaning that you earn more than you spend so you want to charge more than the price that would be enough for you to survive.

So one thing that we can say about charging for something is that the cost of doing it(time and resources) is important.
because it dictates the minimum price possible, time is important here, because eventually bills will have to be paid, and these bills must cover the time frame that you took to do the work otherwise your would spend more than you earn which is also viable if you have debt, hoping that in the future it can be paid, but let's simplify things and assume you can't spend more than you earn.

With just these observations we can say that the amount of times that you do the same service or sell the same product is also important, and these two things are related, the longer it takes to do something the more you have to charge for it and you're going to be doing that less over a fix amount of time.

On the contrary the cheaper something is, the more times you have to do it, those two things balance out, here we're talking about a service but it could also be a product, so the next question is how can we describe this relation?

In our case the price is 10, because we think we can do it 100 times over a month and our cost of living is 1000, if we can increase the times that we do it we can reduce the price,

``````price   quantity
10      100
20      50
40      25
``````

The product is the same for all these rows, p x q = 1000
because 1000 is our minimum. We can also think about the advantages and disadvantages of each relation, of course this is a much more complicated subject to think about, but we can at least intuit that in general something cheaper will be easier to sell that something more expensive(demand curve, also called the law of demand) so increasing the quantity and lowering the price is generally speaking a good idea, this also means increasing efficiency, that's specially true in a very competitive market.

So now that we have a pretty good idea of the pieces that
make the price of something(quantity, time, cost) we can expand our view and start to think about other things that influence the price.

Until now we only took the point of view of the seller, but to sell something you also need a buyer, someone willing to pay the price that you're asking, assuming this buyer is a rational actor, he wants to pay the least amount possible for the product or service, everything else being equal.

We already know how to calculate the minimum price, but just selling something for the minimum possible price is not a good idea since you could earn a lot more if your buyer is willing to pay more, so now let's try to intuit what influences the upper limit, the maximum price that you can sell something, assuming two companies `c1` and `c2` both located at the same city and selling the same product, what will determined the price of the product in this situation?

We can say that our buyer being a rational actor and knowing that both product are mostly the same will choose the lowest price, but neither company wants to sell for the lowest price possible, not only that but since we certainly have multiple potential buyers in the same city, the buyers also will compete between themselves to buy the product or service it's a thug of war. Now that we have a good intuition about what's happening and the pieces that matter, let's define a demand function and think about the interaction between the parties using some game theory.

## Iterated Elimination Of Strictly Dominated Strategies Convergence

This long and complicated name is actually not that hard to understand, let's break each part and think about it.

### Iterated Elimination

We called iterated elimination because we gonna remove the strategies that the companies will not play, since we assume they are rational actors and those strategies will be sub-optimal, it's iterated because we do it in rounds and each round influences the next.

### Strictly Dominated Strategy

An strictly dominated strategy is an strategy that isn't the best strategy in any situation, it can be better than other strategies on a particular situation if you have more than 2 choices but it's never "the best strategy", We gonna eliminate these strategies in each iteration since there's a better strategy to be played.

### Convergence

Each strategy elimination, which in this case means the quantity that the company should produce will lead to a smaller price window, this price window will get smaller as we eliminate more and more strategies until we end up with just one optimal quantity to be produced by the companies.

## Applying the convergence

Now That we have a idea of what we're going to do, let's do it.

Given a demand function

``````d(q) = 100 - (q1 + q2)
``````

Where 100 is all meaningful data that influences this function besides the quantity and the price, q1 is the quantity that company 1(c1) will produce and q2 is the quantity that company 2(c2) will produce, the objective of each company is to have the highest profit possible, We can calculate the profit based on the demand function, the quantity being produced and the cost of producing the product.

The profit payoff function of firm 1

``````              [demand function]   [production cost]
v1(q1, q2) = (100 -  q1 - q2)  q1 -     10q1
``````

In a very competitive market two companies being rational actors can only influence the quantity that they produce, the demand multiplied by the quantity produced by company 1(c1) will give us the maximum possible revenue of c1, removing the cost of production will give us the profit of c1
we can rearrange the equation.

``````90q1 - q1**2 - q1q2
``````

Now we can use the derivative at 0 to calculate the max profit possible.

The derivative being

``````90 - 2q1 - q2 = 0
//after rearranging
q1 = (90 - q2)/2
``````

We end up with a function that will tell us the quantity that we need to produce based on the quantity that our competitor produced, if our competitor produce 0 units we have.

``````q1 = (90 - 0)/2
q1 = 45
``````

So 45 is the ideal number of units to maximize our profits if our competitor don't produce anything.
Now something interesting happens, if our competitor knows that we know that 45 is the ideal number if he doesn't produce anything, he knows that we'll never produce more than 45, since producing more than 45 will be a dominated strategy, S1 = (0, 46) is worst than S2 = (0, 45),

Knowing that, he can calculate the minimum amount ideal for him, he just needs to plug 45 in his equation.

``````q2 = (90 - 45)/2
q2 = 22.5
``````

What that means is that the quantity floor is 22.5, in other words a strategy that produces less than 22.5 is also a dominated strategy, because S1 = (22.5, 45) is better than
S2 = (22, 45) and we know that the upper quantity for company 1 is 45 so that company will never produce more than 45.
So now we also have a lower floor, we have a quantity window between 22.5 and 45 anything outside this window is a bad idea.
But it's not over yet we can now apply the same idea
for the floor 22.5, now company 1 knows that company 2 will never produce less than 22.5 we can plug this value in our function and figure out another quantity ceiling.

``````q1 = (90 -22.5)/2
q1 = 33.75
``````

since we know that company 2 will never produce less than 22.5 we should never produce more than 33.75.

Do you see where this is going? now we can "iterate" again, with a new upper ceiling of 33.75

``````q2 = (90 - 33.75)/2
q1 = 28.125
``````

and again...

``````q2 = (90 - 28.125)/2
q1 = 30.93
``````

If we keep doing this we can see that the value goes to 30, which is the best possible strategy for both companies, so the quantity that they should produce to maximize profit assuming both companies are rational actors is exactly 30, let's plug this value in to the profit function and see what happens.

``````v1(30, 30) = (100 -  30 - 30)30 - 10 * 30
v1(30,30) = 2100
``````

So both companies profit should be 2100 and the price of each unit 80, if another company would join the market the profit and price would drop for all of them, if we kept
adding more competitors eventually the price would drop to the cost of production and nobody would make a profit, considering that the demand didn't change

Game Theory is a interesting exercise to think about things that happens in the real world and also serves as a guide line on how things "should look" but the reality is that the real world is far more complicated, for starters there're no "rational actors" in the real world, people and companies act irrationally all the time, we usually don't have all the data and when we do it might not be correct so that magic "100" that we considered in the demand functional for "all the things that influence demand" can be wrong when
you apply to a real situation, nevertheless none of this should discourage you to try to understand things, model them and apply what you know to real life situations, you might not have the perfect answer but you can at least understand how things should look in a ideal situation which is usually not very far from the truth.