I have written a simple script for modelling stock prices using Geometric Brownian Motion. The time series I am downloading are daily adjusted closing prices. My aim is to be able to change the prediction period and all other variables.
However, I am trying to understand the price prediction differences between calculating the mu (average returns) and sigma (variance) using a linear or standard methods versus using a log approach. The log approach consistently generates a higher predicted stock price. My code is below.
My question is, which approach is the most appropriate?
(I am using Python 3.)
from math import log, e import matplotlib.pyplot as plt from pandas_datareader import data from datetime import date, timedelta import datetime stock = 'AAPL' # Enter the name of the stock start = '2015/1/1' apple = data.DataReader(stock, 'yahoo', start) # This is the 'normal' way of calculating mu and sigma close = apple[:]['Adj Close'] mu = (close[-1]/close)** (252.0/len(close)) - 1 sigma = (close/close.shift(1)-1)[1:].std()*np.sqrt(252) # This is the 'log' way of calculating mu and sigma apple['log_price'] = np.log(apple['Adj Close']) apple['log_return'] = apple['log_price'].diff() mu = apple.log_return.sum() -1 sigma = np.std(apple.log_price) s0 = close[-1] T = 18/12 delta_t = 0.001 num_reps = 1000 steps = T/delta_t plt.figure(figsize=(15,10)) closing_prices =  for j in range(num_reps): price_path = [s0] st = s0 for i in range(int(steps)): drift = (mu - 0.5 * sigma**2) * delta_t diffusion = sigma * np.sqrt(delta_t) * np.random.normal(0, 1) st = st*e**(drift + diffusion) price_path.append(st) closing_prices.append(price_path[-1]) plt.plot(price_path) plt.ylabel('stock price',fontsize=15) plt.xlabel('steps',fontsize=15) plt.axhline(y = s0, color = 'r', linestyle = '-') # print latest price TW plt.show() mean_end_price = round(np.mean(closing_prices),2) print("Expected price in 12 months: $", str(mean_end_price))