Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making an overly simplified version of a stock simulator game, because I:

  1. am fascinated with how the stock market works
  2. learn better & faster from a project like this, rather than text-books

Before writing any actual code, I started making an Excel spreadsheet to simulate the fluctuations of 1 company's stock based on how many people buy/sell the stock on any given day, so that when I have the code, I have something to compare it against to know that it works.

Variables I have access to:

  • a) Total amount of stock issued - 10000
  • b) Starting stock price when the company goes public - $10.00
  • c) Stock available on any given day
  • d) Stock bought/sold on that day - for example, 150 on day 1
  • e) Stock bought/sold the previous day - when first starting the simulation, this number is 0
  • f) Company profits on any given day - For simulation purposes, profits are calculated daily, not quarterly or yearly
  • g) Stock price - This is what I need calculated

I tried using (d-e)/a which gives me a difference, like 0.015 which I use to get the stock price for the next day. But it just seems too simple, since buying 100% of the stock on day 1 and then selling 100% of it on day 2, brings down the price to $0.00. Perhaps this would work given enough random participants who all buy/sell the stock, but in this case, I need the simulation to work with just 1 person. And the simple function I wrote just gives too much power to that 1 person.

PS: For simulation purposes, I assume there is always a buyer and always a seller for the stocks.

PPS - Edited to provide the test numbers I'm starting with

share|improve this question
    
Maybe it would be better to give it here: economics.stackexchange.com –  zacharmarz Oct 30 '11 at 19:44
2  
@zacharmarz I've asked this question on 2 SA Q&A sites that deal with finance and got redirected here. And now I'm being directed to the Economics one... And I'm pretty sure, they are going to redirect me to another Q&A site. And since this is a simulation game I'm making, I don't really need real-world scenarios and functions, which is what the other boards might provide. –  leo.vingi Oct 30 '11 at 19:47
1  
"I need the simulation to work with just 1 person." Who is the other side of the trade then? –  Den Oct 30 '11 at 20:26
    
@Den As I mentioned, for simulation purposes, I assume that there is always a buyer and a seller, so there wouldn't be anyone else on the other side of the trade. The player would be able to buy or sell as much as he likes/can afford. –  leo.vingi Oct 30 '11 at 20:29
    
Logically there is always someone on the other side of the trade. In your case it is simplified to a virtual "person"/market that is always willing to buy/sell any amount of stock. Maybe you can add a randomiser to change the maximum amount of stock that virtual person is willing to trade on any given day (like based on company profit)? –  Den Oct 30 '11 at 20:37
show 3 more comments

1 Answer

up vote 4 down vote accepted

Maybe you can have an entity 'Market' that represents a collection of players 'Trader'. Each of those players can be either a real person or a "virtual" one - bot. Each player can be willing to buy or sell certain amount of stock at certain price. Some bots can be optimistic, some pessimistic.

To simplify things all trades will be carried out at certain time(s) within a day. You can open a position to trade specific amount at specific price.

The 'Market' than sums up all the requests at "trade time" and if your position qualifies (within available amount and price) your trade will be carried out.

share|improve this answer
1  
I would just like to clarify that even though I did not get a mathematical function that would solve my problem, by using the answer @Den provided, I could stick to the math I have in place and use virtual bots, to simulate supply/demand. –  leo.vingi Oct 30 '11 at 21:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.