tags:

views:

104

answers:

3

I have no idea what formulas I should use to create stock-market for my players that they could play it. I use php+mysql. Maybe you can throw any good ideas? I'll be grateful.

+1  A: 

The simplest (but not necessarily the best) way of implementing fluctuation in stock prices is by using a random walk, since it has been hypothesised that stock prices can be modelled using such a process. See http://en.wikipedia.org/wiki/Random_walk_hypothesis

So, dp = rand(-1,1) * p * dt where p is the stock price and dt is the time elapsed (probably in days).

Chinmay Kanchi
+1  A: 

Assuming this is multiplayer, in addition to random walk, some consideration of supply and demand can be taken into account. If more shares are bought than sold of a particular stock over a period, its value should go up slightly, and vice-versa. This will increase volatility and perhaps make this portion of the game more exciting.

Eric Mickelsen
+1  A: 

If you're allowing buying and selling between players (and assuming you've already created the storage part), you just need to expose four methods and let the players define the economy:

Bid (stock, price) 
Offer (stock, price)   
Buy (stock, price)    
Sell (stock, price)

If the stocks already exist in your game, then you just need to let the players define what they want for theirs.

Austin Salonen