# How would I implement a realistic stock market?

by Zoe   Last Updated June 12, 2019 16:13 PM

I'm making a corporation simulator, and it contains stocks. In the game you can buy and sell stocks, but I can't implement a realistic change in the price for them. How do I make them change up/down in a realistic way?

Tags :

Rather unspecific to the programming language or the platform mentioned, but I would probably go for a greater change as a primary depiction of important stock change, and then generate a small fast change upon that to depict the hooky part of the stock graphs.

So basically:

1. You start at time T1. You're going towards time T2. Price at time T1 is P1. P2 is end price.
2. You generate a random number (probably based on some events, maybe?) for P2. This is your larger number target price.
3. You iterate towards it with a timestep. If you update a couple of times (denoted as Tt) between those timesteps, you do

(T2 - T1)/Tt = Your time step

4. To get the price at this time, you do

P1 + (P2 - P1)/Tt * AmountOfTimeStepsPassed

5. This will get you a pretty straight line, so you could look into something like Bezier or something to make a curve. But to get those hooks, you need to add a very small totally random deviation upon it. This needs to go from a small negative number to a small positive number!

P1 + (P2 - P1)/Tt * AmountsOfTimeStepsPassed + SmallRandomNumber

Anonymous
December 25, 2015 12:09 PM

## Related Questions

Updated September 05, 2017 07:13 AM

Updated April 10, 2018 07:13 AM

Updated March 09, 2016 07:05 AM

Updated May 13, 2016 08:05 AM

Updated May 31, 2017 13:13 PM