src/django/shared/Monte.py
def simulate(self):
        """
        Function that does the necessary calculations for the simulation data.
        """

        # np.random.seed(8) this can be used to seed the simulation so you can repeat results

        # Initial data values needed to set up the simulations.
        log_returns = np.log(1 + self.data.pct_change()) # percentage change between current and prior element
        mu = log_returns.mean() # average/mean
        var = log_returns.var() # variance
        drift = mu - (0.5 * var) # stochastic drift
        sigma = log_returns.std() # standard deviation
        daily_returns = np.exp(drift.to_numpy() + sigma.to_numpy() * norm.ppf(np.random.rand(self.time_steps, self.sim_amount)))

        # Takes last data point in stock data as as the starting point for the simulations
        initial = self.data.iloc[-1]
        self.monte_sims = np.zeros_like(daily_returns)
        self.monte_sims[0] = initial

        # Fills monte_sims with simulated prices which are pseudorandomized with daily_returns
        for t in range(1, self.time_steps):
            self.monte_sims[t] = self.monte_sims[t - 1] * daily_returns[t]

        Function that does the necessary calculations for the simulation data.
        
Function that does the necessary calculations for the simulation data.
Function that does the necessary calculations for the simulation data .
def simulate(self):
        log_returns = np.log(1 + self.data.pct_change()) 
        mu = log_returns.mean() 
        var = log_returns.var() 
        drift = mu - (0.5 * var) 
        sigma = log_returns.std() 
        daily_returns = np.exp(drift.to_numpy() + sigma.to_numpy() * norm.ppf(np.random.rand(self.time_steps, self.sim_amount)))
        initial = self.data.iloc[-1]
        self.monte_sims = np.zeros_like(daily_returns)
        self.monte_sims[0] = initial
        for t in range(1, self.time_steps):
            self.monte_sims[t] = self.monte_sims[t - 1] * daily_returns[t]
def simulate ( self ) : log_returns = np . log ( 1 + self . data . pct_change ( ) ) mu = log_returns . mean ( ) var = log_returns . var ( ) drift = mu - ( 0.5 * var ) sigma = log_returns . std ( ) daily_returns = np . exp ( drift . to_numpy ( ) + sigma . to_numpy ( ) * norm . ppf ( np . random . rand ( self . time_steps , self . sim_amount ) ) ) initial = self . data . iloc [ - 1 ] self . monte_sims = np . zeros_like ( daily_returns ) self . monte_sims [ 0 ] = initial for t in range ( 1 , self . time_steps ) : self . monte_sims [ t ] = self . monte_sims [ t - 1 ] * daily_returns [ t ]
Function that does the necessary calculations for the simulation data.
Function that does the necessary calculations for the simulation data .
"""
        Function that does the necessary calculations for the simulation data.
        """ # np.random.seed(8) this can be used to seed the simulation so you can repeat results # Initial data values needed to set up the simulations. # percentage change between current and prior element # average/mean # variance # stochastic drift # standard deviation # Takes last data point in stock data as as the starting point for the simulations # Fills monte_sims with simulated prices which are pseudorandomized with daily_returns
self