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.

I've looked at the answer to the question "How would I implement a realistic stock market?", but I want the stock price to be influenced by the users actions, and based on non random actions that they have done. For example, if they buy a massive quantity of an item in the game, the value will go up

  • 1
    \$\begingroup\$ Why is the other question not helping you? \$\endgroup\$ – Vaillancourt Jun 12 '19 at 11:26
  • 1
    \$\begingroup\$ I voted to close this as a duplicate of how would I implement a realistic stock market?. When that answer there doesn't help you, please explain how your requirements are different or what problems you have with applying that answer to your particular game. \$\endgroup\$ – Philipp Jun 12 '19 at 11:37
  • \$\begingroup\$ I have tried that, however im thinking of making the stock market more of the main game itself \$\endgroup\$ – scopessuckM8 Jun 12 '19 at 12:08
  • \$\begingroup\$ So, what specific traits would an algorithm need to be better for your purposes than what's been proposed so far? What makes an algorithm "good" for your purposes? What specific outcomes do you need to create or need to avoid? Only once you provide us with such a specification can we re-open the question for answers to suggest ways to fulfill that specification. \$\endgroup\$ – DMGregory Jun 12 '19 at 12:58
  • 1
    \$\begingroup\$ I want it to be influenced by the users actions, and based on non random actions that they have done. For example, if they buy a massive quantity of an item in the game, the value will go up \$\endgroup\$ – scopessuckM8 Jun 12 '19 at 13:48

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.

  • \$\begingroup\$ How would they simulate those values, how could they take into account the actions of the player? Could you provide an example? \$\endgroup\$ – Vaillancourt Jun 12 '19 at 20:23
  • \$\begingroup\$ Not without in depth research into the models - which I would leave up to the original person. It's a potentially very complex problem, and perhaps exactly how to do it goes beyond what can be answered in this venue. \$\endgroup\$ – Tim Holt Jun 12 '19 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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