Economics for trading

Started by
6 comments, last by ElCas 12 years, 6 months ago
Hello,

I am currently creating a browser game in my spare time. The premise is that you are a freelance cargo hauler. My problem is coming up with a way to control trade value of a resource based on location. I have several destinations and they have their export and import resources. So the players would want to take Resource A from a Location A to Location B because Location B is importing it and therefore has a higher demand for the resource (read: More $ per Ton). Obviously as more and more players deliver Resource A to Location B this would cause the buy price to go down (More supply Same Demand). I can't seem to come up with a mathematical formula to calculate the buy price for each Resource on a global level as well as a local level. The global buy price would be the base price at all locations and if any location has a higher demand for said resource then this would obviously drive the price up.

I the nearest thing I came up with was

GlobalResource[x].Price = ##.##

If local market is importing then
Resource[x].Price = GlobalResource[x].Price * (1 + Demand_factor)
else
Resource[x].Price = GlobalResource[x].Price

I don't know how to calculate the change for global price and how to calculate the demand factor.

Any help on the subject would be appreciated.
Advertisement

Hello,

I am currently creating a browser game in my spare time. The premise is that you are a freelance cargo hauler. My problem is coming up with a way to control trade value of a resource based on location. I have several destinations and they have their export and import resources. So the players would want to take Resource A from a Location A to Location B because Location B is importing it and therefore has a higher demand for the resource (read: More $ per Ton). Obviously as more and more players deliver Resource A to Location B this would cause the buy price to go down (More supply Same Demand). I can't seem to come up with a mathematical formula to calculate the buy price for each Resource on a global level as well as a local level. The global buy price would be the base price at all locations and if any location has a higher demand for said resource then this would obviously drive the price up.

I the nearest thing I came up with was

GlobalResource[x].Price = ##.##

If local market is importing then
Resource[x].Price = GlobalResource[x].Price * (1 + Demand_factor)
else
Resource[x].Price = GlobalResource[x].Price

I don't know how to calculate the change for global price and how to calculate the demand factor.

Any help on the subject would be appreciated.


What about something like:


Global Price = 100 // The standard price per unit

Location1 ImpactFactor = 75% // How much the local price is affected by local supply and demand (How much do the people want the goods, despite not having any available)
Location1 quantity = 50 // How much the location has in storage
Location1 maxQuantity = 100 // The maximum amount the location can keep
Location1 factor = 2 // maxQuantity divided by quantity = 2

Location1 newFactor = factor * impactfactor = 1.5
Location1 localFinalPrice = newFactor * price = 150

Location1 Consumption = 2 // How much is consumed per game time - as the game progresses more is consumed unless you supply
Location1 ConsumptionMin = 20 // The minimum amount to leave on the planet (to prevent everywhere having really good prices if you just wait). It also allows for fixed "routes"


Then you need something like:


Global PriceMax = 120 // The maximum price per unit for this item
Global PriceMin = 80 // The mimimum
Global PriceStability = 5 // The stability of the price (see below)
Global UpDownFactor = 50 // Whether the price will go up or down (change this to affect an items price - say there is an event in the game like a new oil well is built)
Global PriceFluctuationMax = 4 // The fluctuation of the price - maximum amount it can change by per check
Global PriceFluctuationMin = 1 // The fluctuation of the price - mimimum

// Each game time
for (each item price) {
Boolean priceChange = Get Random Chance of PriceStability (5/100) = 5%

if(priceChange) {
Boolean upOrDown = Get Random Chance of UpDownFactor (50/100) = 50%
RandomNumber = Get random between FluctuationMin and Max
if(up) {
Price = Price + RandomNumber
}
else {
Price = Price - RandomNumber
}
}
else {
// Do nothing this items price is stable
}
}
How about something like y=1/x where y would be the price and x is the amount of goods. If you graph the equation (google image) you get a line where the price is high for few goods being sold and low when a lot of goods are sold and a nice curve in between. You'd probably need to play with it a bit to get exactly what you want it to do but I think it's the effect you're hoping for.

What about something like:


Global Price = 100 // The standard price per unit

Location1 ImpactFactor = 75% // How much the local price is affected by local supply and demand (How much do the people want the goods, despite not having any available)
Location1 quantity = 50 // How much the location has in storage
Location1 maxQuantity = 100 // The maximum amount the location can keep
Location1 factor = 2 // maxQuantity divided by quantity = 2

Location1 newFactor = factor * impactfactor = 1.5
Location1 localFinalPrice = newFactor * price = 150

Location1 Consumption = 2 // How much is consumed per game time - as the game progresses more is consumed unless you supply
Location1 ConsumptionMin = 20 // The minimum amount to leave on the planet (to prevent everywhere having really good prices if you just wait). It also allows for fixed "routes"


Then you need something like:


Global PriceMax = 120 // The maximum price per unit for this item
Global PriceMin = 80 // The mimimum
Global PriceStability = 5 // The stability of the price (see below)
Global UpDownFactor = 50 // Whether the price will go up or down (change this to affect an items price - say there is an event in the game like a new oil well is built)
Global PriceFluctuationMax = 4 // The fluctuation of the price - maximum amount it can change by per check
Global PriceFluctuationMin = 1 // The fluctuation of the price - mimimum

// Each game time
for (each item price) {
Boolean priceChange = Get Random Chance of PriceStability (5/100) = 5%

if(priceChange) {
Boolean upOrDown = Get Random Chance of UpDownFactor (50/100) = 50%
RandomNumber = Get random between FluctuationMin and Max
if(up) {
Price = Price + RandomNumber
}
else {
Price = Price - RandomNumber
}
}
else {
// Do nothing this items price is stable
}
}



This looks simple to implement the only thing I would have to figure out is an equation to set the newFactor to a negative value when the quantity available exceeds the maxQuantity that way it drives the price below the gloablPrice when players attend to flood the local market.




How about something like y=1/x where y would be the price and x is the amount of goods. If you graph the equation (google image) you get a line where the price is high for few goods being sold and low when a lot of goods are sold and a nice curve in between. You'd probably need to play with it a bit to get exactly what you want it to do but I think it's the effect you're hoping for.


I like how the 1/x function looks but as you said it would take some trail and error to fine tune the equation to generate the right curve to fit my needs. And since I was just trying to make a quick and simple approach, Viscis method seems to be the quickest to implement and tweak as abuses by players is noticed.
Easy as:


// Run this first before you adjust prices and if it returns true escape out

if( maxQuantity / quantity < 0.5) // If the quantity is double the max quantity
// Force set the price to 25% of the global value
}

This seems like a totally random system without basis in supply and demand. My suggestion would be to simulate the planet's economic situation and needs in an organic way. This will allow you to add events and it will be taken care of automatically instead of fiddling with algorithms until it looks right.

What you need is for each planet :
- Population
- Available cash
- Rate of consumption for each product per quality of life level
- Rate of production for each product
- Stock for each product
- Quality of life index


The goal of the planet is to increase its quality of life index. It does this by consuming products over its current quality of life index. A shortage of product below it's current quality of life index will reduce it. The available cash will determine prices the planet is willing to pay for each product.

For example, you have the following products and their rate of consumption per quality of life index for that planet(per tick) :
- Food (2, 2, 3, 4, 5)
- Medicine (0, 1, 2, 2, 3)
- Clothes (1, 2, 4, 6, 10)
- Electronics (0, 1, 3, 7, 15)
- Art (0, 0, 0.5, 1, 5)

The planet will try to maintain a big reserve to ensure it doesn't starve. If the planet is at QoL level 1 and has 100 population at 2 food/tick and it feels comfortable at 100 tick of stock, then it will try to set its food stock requirement at 20K to create a buffer. If the current reserve is below 20K, the price will go up to attract traders. If the current reserve is over 20K, the price will go down to try and stockpile if the market is good. For clothes, it will try to maintain 10K stock.

Remember the planet's goal is to maximize its Quality of Life. Periodically, it will assess its sustainability. This is where the available cash comes into play. The planet will figure out how much stock it can replace with its current cash. If it feels like it can push up its quality of life, then it will increment it. So now instead of being at level 1, it's at 1.1. This has no effect on food. Clothes now need 11K stock, medicine 1K, electronics 1K and art 0K. This ends up creating a small market for medicine and electronics on this planet.

This is for consumption. For production, you calculate the price based on the raw material cost. Raw material contains the actual raw material and workforce. Workforce is the population and its quality of life. Since the higher the quality of life is, the higher the population and productivity, then maintaining it is part of the cost.

Planet B is a planet of starving artists. They produce art. It has a low quality of life. Similarly to consumption, it sets a target stock level for 0% markup. It should be equal or higher than consumption. Let's say its production is (5, 6, 7, 8, 9). Since they're starving at quality level 1, it produces 5/tick. At 0% markup, this gives a stock of 50K. The current cost is the current consumption rate for each product * market buy price. If food is at 5 credits and clothes at 20, we can calculate the cost to be 2*5 + 20*1 = 30 credit. Therefore, if the planet has 50K art, the price will move toward 30. If it has less, it will increase. If there's a big harvest and the food prices go down, its target art sell price will go down to sell more. The opposite is also true.

The important thing to make this work is to create changes incrementally. Small changes to prices done often instead of big prices changes done sporadically.

This may seem complex for nothing, but there are a lot of benefits which are not apparent at first. Anything you can add to the game will have an organic effect on prices. A farming planet suddenly gets a big harvest. You don't need to do anything. Increase the production rate of the planet, prices go down naturally. A new gadget is the rage in a sector of the galaxy. Increase consumption, prices go up. The government increases security funding. Traders are less inclined to carry contraband items. Planets starve, price shoot up dramatically. Security getting lax? Prices will plummet. Players build a huge research lab on a planet, this creates a massive cash inflow. The planet will increase its quality of life and prices will increase. Giant meteor crashes on a planet. Population is reduced, consumption is reduced and prices adjust automatically.

All of these will also ripple throughout the galaxy since everything is interconnected. An increase in food supply means planets now desire higher quality of life products which drive these prices up. No access to contraband items means they spend more money for them, which means they spend less for other items. Getting these side effects with an arbitrary system would be very hard.

Also, this gives you a lot of knobs to play with. Want to create a planet of cyborgs? Make electronics a required item for lower quality of life levels. Want to create a bi-polar planet with erratic prices? Calculate the required stock replacement on a shorter term. A government based planet could have cash injected, artificially keeping prices higher. A slave planet could have its cash reserves reduced periodically, keeping quality of life low and creating cheap labor.
Developer for Novus Dawn : a [s]Flash[/s] Unity Isometric Tactical RPG - Forums - Facebook - DevLog
You could use the formula (Demand / Supply) * UnitPrice.
That way, when ex. the demand is high and supply is low, the price will soar and vice versa.

The global price can also be calculated by getting the global demand and supply.
Your unit price then can be calculated from the costs of the resources that compose the product + a certain margin of profit

This seems like a totally random system without basis in supply and demand. My suggestion would be to simulate the planet's economic situation and needs in an organic way. This will allow you to add events and it will be taken care of automatically instead of fiddling with algorithms until it looks right.

What you need is for each planet :
- Population
- Available cash
- Rate of consumption for each product per quality of life level
- Rate of production for each product
- Stock for each product
- Quality of life index


The goal of the planet is to increase its quality of life index. It does this by consuming products over its current quality of life index. A shortage of product below it's current quality of life index will reduce it. The available cash will determine prices the planet is willing to pay for each product.

For example, you have the following products and their rate of consumption per quality of life index for that planet(per tick) :
- Food (2, 2, 3, 4, 5)
- Medicine (0, 1, 2, 2, 3)
- Clothes (1, 2, 4, 6, 10)
- Electronics (0, 1, 3, 7, 15)
- Art (0, 0, 0.5, 1, 5)

The planet will try to maintain a big reserve to ensure it doesn't starve. If the planet is at QoL level 1 and has 100 population at 2 food/tick and it feels comfortable at 100 tick of stock, then it will try to set its food stock requirement at 20K to create a buffer. If the current reserve is below 20K, the price will go up to attract traders. If the current reserve is over 20K, the price will go down to try and stockpile if the market is good. For clothes, it will try to maintain 10K stock.

Remember the planet's goal is to maximize its Quality of Life. Periodically, it will assess its sustainability. This is where the available cash comes into play. The planet will figure out how much stock it can replace with its current cash. If it feels like it can push up its quality of life, then it will increment it. So now instead of being at level 1, it's at 1.1. This has no effect on food. Clothes now need 11K stock, medicine 1K, electronics 1K and art 0K. This ends up creating a small market for medicine and electronics on this planet.

This is for consumption. For production, you calculate the price based on the raw material cost. Raw material contains the actual raw material and workforce. Workforce is the population and its quality of life. Since the higher the quality of life is, the higher the population and productivity, then maintaining it is part of the cost.

Planet B is a planet of starving artists. They produce art. It has a low quality of life. Similarly to consumption, it sets a target stock level for 0% markup. It should be equal or higher than consumption. Let's say its production is (5, 6, 7, 8, 9). Since they're starving at quality level 1, it produces 5/tick. At 0% markup, this gives a stock of 50K. The current cost is the current consumption rate for each product * market buy price. If food is at 5 credits and clothes at 20, we can calculate the cost to be 2*5 + 20*1 = 30 credit. Therefore, if the planet has 50K art, the price will move toward 30. If it has less, it will increase. If there's a big harvest and the food prices go down, its target art sell price will go down to sell more. The opposite is also true.

The important thing to make this work is to create changes incrementally. Small changes to prices done often instead of big prices changes done sporadically.

This may seem complex for nothing, but there are a lot of benefits which are not apparent at first. Anything you can add to the game will have an organic effect on prices. A farming planet suddenly gets a big harvest. You don't need to do anything. Increase the production rate of the planet, prices go down naturally. A new gadget is the rage in a sector of the galaxy. Increase consumption, prices go up. The government increases security funding. Traders are less inclined to carry contraband items. Planets starve, price shoot up dramatically. Security getting lax? Prices will plummet. Players build a huge research lab on a planet, this creates a massive cash inflow. The planet will increase its quality of life and prices will increase. Giant meteor crashes on a planet. Population is reduced, consumption is reduced and prices adjust automatically.

All of these will also ripple throughout the galaxy since everything is interconnected. An increase in food supply means planets now desire higher quality of life products which drive these prices up. No access to contraband items means they spend more money for them, which means they spend less for other items. Getting these side effects with an arbitrary system would be very hard.

Also, this gives you a lot of knobs to play with. Want to create a planet of cyborgs? Make electronics a required item for lower quality of life levels. Want to create a bi-polar planet with erratic prices? Calculate the required stock replacement on a shorter term. A government based planet could have cash injected, artificially keeping prices higher. A slave planet could have its cash reserves reduced periodically, keeping quality of life low and creating cheap labor.


I like this approach. The problem I see with is that this method is over kill for what I need for the game. The only factors that are in play are demand and available local supply. I could maybe add something like this down the line.

This topic is closed to new replies.

Advertisement