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.
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...
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.
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.