# What is a good algorithm for a stock market simulation?

by scopessuckM8   Last Updated June 12, 2019 12:13 PM

I am making a text game about investing in the stock market, however I need a better algorithm, as the current simulation just goes up and down randomly. How can I make it so that its a more realistic simulation in python. However, other possible duplicates like: How would I implement a realistic stock market? dont help me.

Tags :

As you've pointed out, the other question you linked to is more about how to render a nice graph and numerical change, and not how to decide exactly how or why the number should change. It just states...

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.

Obviously you don't want a random number, you want a stock market model to tell you what P2 should be. And what that value is can be influenced by a market simulator and also player actions that impact the simulator's outcome.

To that end (how to model and simulate a stock market) I think you're going to have to go deep and learn more about actual stock market simulators outside of the game space.

Below are a few links to reading on this topic, that I think should help get you further down the path of how a market simulator works, what the inputs to it are, etc.

Modeling and Simulation of the Artificial Stock MarketTrading System

Multi-agent modeling and simulation of a stock market

Wikipedia Stock market simulator page

You might also check out the MarketWatch virtual stock exchange at https://www.marketwatch.com/game. No source code but it should be a good learning experience to see how this is done in other games/simulators.

Lastly, you might find this previous question in a different stack somewhat useful: https://softwareengineering.stackexchange.com/questions/84490/what-algorithms-would-be-useful-for-designing-a-stock-market-simulator

In the end, this is potentially a pretty complex problem if you truly want an accurate simulation.

Tim Holt
June 12, 2019 19:04 PM

## Related Questions

Updated February 21, 2019 20:13 PM

Updated March 02, 2016 01:05 AM

Updated August 18, 2019 00:13 AM

Updated August 18, 2019 06:13 AM