Stock price simulator

Discussion in 'Programming' started by EvilTerabyte, Jul 30, 2020 at 3:21 AM.

  1. Hey! I searched a lot to find out how to simulate stock prices realistically. The function takes 2 arguments, price, and volatility.

    The price is the starting or opening price, this can be any number you want!

    The volatility is how much it changes, it can be any number between 0 - 1 (0% - 100%). I usually keep mine around 0.01 - 0.05.

    NormInv is an excel function that can be found here

    Code (Java):
    public static void generatePrice(double price, double volatility) {
            double exactOpenPrice = price * (1+ NormInv.compute(Math.random(),0,volatility)));
            double openPrice = Math.round(exactOpenPrice * 100.0) / 100.0;
            System.out.println("New Stock Price is " + openPrice);
  2. Well, that's gonna be harsh...
    Other than the volatility you also have the concept of "trend", basically meaning that the stock price does mostly go up or down (obviously there're both, but one is more preeminent)
    There are also the concepts of "resistance" and "support" those are price ranges which have a lower chance to be broke
    You can also take the "volume" into account, this is the amount of cash which have been traded during for instance 24 hours, 1 week, 1 month, etc... depending on your time frame

    I cannot really explain everything here since it would take hours, but at least I gave you some keywords
  3. Oh yeah there's a lot more involved, but I just needed a quick way to get a "stock price" and couldn't find it anywhere so I thought I'd make a tiny example... I'm still researching and trying to adapt the Monte Carlo simulation in java