Simulating a Market

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Simulating a Market

Post by Lap »

I'm trying to make a market for a multiplayer game where players can buy and sell resources to a global market. Ideally the market would react to player trades and respond accordingly (i.e. everyone buying large amounts of a certain resource will drive up the price). Some element of randomness would be ideal though.

This seems like something that should be pretty easy, but getting a result that feels right has proven more difficult than I thought. Read over a lot of stuff so far including:

http://en.wikipedia.org/wiki/Normal_distribution
http://en.wikipedia.org/wiki/Gaussian_function
http://en.wikipedia.org/wiki/Random_walk
as well as various logarithmic type functions.

Currently I have it so that a resource has a hidden base price and random numbers that are weighted towards returning to this price are added to this number as well as a modifier for the net sell/buy volume that players have traded.

I'm currently determining the price change each turn with something like below, where x is related to the distance from the hidden base price. This seems OK, but still feels a little off. http://stackoverflow.com/questions/4420 ... low-values

Code: Select all

math.ceil(minNum+(maxNum-minNum)*math.random()^x)
I have a feeling there is a somewhat simple equation I am missing that would help greatly. Or maybe there is just a totally better way to go about doing this. Any thoughts?
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Simulating a Market

Post by Davidobot »

Code: Select all

currentPrice = defaultPrice + (defaultAmount - currentAmount)
Maybe something like that?
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Simulating a Market

Post by Plu »

Consider using a simple supply/demand model. For each resource, store how much of it available because people are selling to the market, and store how much of it is wanted because of people buying from the market. Set a base price for each item, and then modify this price based on demand vs supply. For example; if demand is twice as high as supply, the base price is doubled, while if supply is twice as high as demand, the base price is halved.

In order to introduce randomness, add a random amount to both supply and demand each turn. To make the market self-balancing, base the random amount on previous values; ie if in the previous round(s) the demand for something was much higher than its supply, then a larger amount is added to the supply to simulate new companies starting up to sell the currently expensive product, while if the supply is higher than the demand you can add more the demand as new companies start up to make use the currently cheap product.

It'll still be fairly simplistic but should at least look a little bit like a real market.

(I'm not sure how important the market is to your game; if it's a major part then this might be still too simplistic, but if it's sort of a tack-on (like for example it is in Age of Empires games) then this should work just fine.)

(Although this might also be fairly close to what you're planning already)
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Simulating a Market

Post by Ranguna259 »

+1 Plu, I'm taking economics and what Plu said is the basic of a Perfect Competition market and that's the best course of action for a market simulation, this graphs will help you out.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 215 guests