supply/demand cost algorithm
Hi,
I am trying to work out a buy cost and selling price based on the supply and demand of a certain product. I have a starting value of the product, and the buying cost takes that and adjusts it according to what the supply/demand is (high demand means higher price, high supply means lower price). But then I need to calculate the selling price, which is the buying price, plus a random number, which is to be calculated in accordance with the supply/demand. So if the demand is high, the selling price will be higher.
I could really use some help. I have the following varaibles:
starting_value
supply
demand
buy_cost
sell_price
thank u
-eat me!-but i''m not a cannibal!
I am not sure how complex you need it, but this is how I would do something like this.
First, I would define a set of standard values:
standard_supply = 100 (the "normal" supply which causes "normal" demand)
standard_price = 1 (basically just a renamed version of your starting_value)
You can then calculate the demand this way:
demand = standard_supply / supply
This way, a high supply would mean decreased demand, and vice versa.
To find the price, I would set buy_price to:
buy_price = demand * standard_price * buy_fluctuation
The random_fluctuation should then be a random number between, say, 0.90 to 1.10 (90-110%).
I would then let the sell_price be a little higher than this value:
sell_price = 3 * ( buy_price / 2 ) * sell_fluctuation
You can use a different fluctuation value for the sell_price, or not. This way, the buy_price would generally be about two-thirds of the sell_price, which seems to make sense.
Ok, an example. Apples
standard_supply = 100 apples
standard_price = 1 coin per apple
If we then have only 13 apples, the demand would be (w/o fluctuation):
demand = 100 / 13 = 7.69
buy_price = 7.69 * 1 = 7.69 coins per apple
sell_price = 3 * ( 7.69 / 2 ) = 11.54 coins per apple
On the other hand, if you had 213 apples, the values would be
demand = 100 / 213 = 0.47
buy_price = 0.47 * 1 = 0.47 coins per apple
sell_price = 3 * ( 0.47 / 2 ) = 0.70 coins per apple
Seems to work as intended. Hope you did not get too trivial on you
PS: this went a little fast, so forgive me if I made any mistakes...
First, I would define a set of standard values:
standard_supply = 100 (the "normal" supply which causes "normal" demand)
standard_price = 1 (basically just a renamed version of your starting_value)
You can then calculate the demand this way:
demand = standard_supply / supply
This way, a high supply would mean decreased demand, and vice versa.
To find the price, I would set buy_price to:
buy_price = demand * standard_price * buy_fluctuation
The random_fluctuation should then be a random number between, say, 0.90 to 1.10 (90-110%).
I would then let the sell_price be a little higher than this value:
sell_price = 3 * ( buy_price / 2 ) * sell_fluctuation
You can use a different fluctuation value for the sell_price, or not. This way, the buy_price would generally be about two-thirds of the sell_price, which seems to make sense.
Ok, an example. Apples

standard_supply = 100 apples
standard_price = 1 coin per apple
If we then have only 13 apples, the demand would be (w/o fluctuation):
demand = 100 / 13 = 7.69
buy_price = 7.69 * 1 = 7.69 coins per apple
sell_price = 3 * ( 7.69 / 2 ) = 11.54 coins per apple
On the other hand, if you had 213 apples, the values would be
demand = 100 / 213 = 0.47
buy_price = 0.47 * 1 = 0.47 coins per apple
sell_price = 3 * ( 0.47 / 2 ) = 0.70 coins per apple
Seems to work as intended. Hope you did not get too trivial on you

PS: this went a little fast, so forgive me if I made any mistakes...
Thanks, I like the formulas. I''m still kind of uncertain exactly how I want to put it into the game, tough. The game is all about trading goods. On the first map, there are 3 cities. Currently, each city has a supply/demand, and buy/sell price. If the user can only buy at one city and sell to the others, then the formula would work well. But if the user can buy at all cities and sell at all cities, then I should probably have the buying price be the same as the selling price, so that the user really has to think about where he wants to sell the product. Otherwise, he is making a profit no matter where he goes because the sell price is always higher than the buying cost.
Any ideas?
Any ideas?
-eat me!-but i''m not a cannibal!
I do not see the problem. This is why:
You have three cities (or merchants, whatever): A, B, and C.
Let us use my previous examples:
City A have only 13 apples, so they would BUY apples for 7.69 and SELL for 11.54.
City B have 213 apples, so they would BUY apples for 0.47 and SELL for 0.70.
City C has a normal supply of 100 apples, and would therefore BUY for 1 and SELL for, say, 1.3.
Now, as a player, when you BUY from a city, you would have to pay the SELL_PRICE for the specific city. Reversely, if you want to SELL, the city would only pay their BUY_PRICE.
So, in this example, you would want to buy the apples from City B for 0.70 apiece....then sell the apples to City A for 7.69.
There is plenty of room for mistakes:
If you buy from A for 11.54, you would loose money nomatter what you do.
If you buy from B for 0.70, you would only loose money if you sold them back to the same city (0.47).
If you buy from C for 1.3, you would loose money if you sold to C or B (1 / 0.47)
I think the confusion is caused by the fact, that I think of the prices from the viewpoint of the merchant, whereas you regard them from the viewpoint of the player. Nothing wrong with that, you would just have to adjust the formulas a little.
You have three cities (or merchants, whatever): A, B, and C.
Let us use my previous examples:
City A have only 13 apples, so they would BUY apples for 7.69 and SELL for 11.54.
City B have 213 apples, so they would BUY apples for 0.47 and SELL for 0.70.
City C has a normal supply of 100 apples, and would therefore BUY for 1 and SELL for, say, 1.3.
Now, as a player, when you BUY from a city, you would have to pay the SELL_PRICE for the specific city. Reversely, if you want to SELL, the city would only pay their BUY_PRICE.
So, in this example, you would want to buy the apples from City B for 0.70 apiece....then sell the apples to City A for 7.69.
There is plenty of room for mistakes:
If you buy from A for 11.54, you would loose money nomatter what you do.
If you buy from B for 0.70, you would only loose money if you sold them back to the same city (0.47).
If you buy from C for 1.3, you would loose money if you sold to C or B (1 / 0.47)
I think the confusion is caused by the fact, that I think of the prices from the viewpoint of the merchant, whereas you regard them from the viewpoint of the player. Nothing wrong with that, you would just have to adjust the formulas a little.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement