I have a problem where I am plotting a random walk and I am looking to get the average line for all the simulations. My code is below:
import numpy as np
from math import sqrt
import matplotlib.pyplot as plt
# starting stock price
S = 100
# number of trading days
T = 252
# random data inputs
mu = 0.061
stdev = 0.165
if __name__ == '__main__':
average= []
# running the simulation multiple times (# specified in range) times
for i in range(100):
daily_returns = np.random.normal((mu/T), stdev/sqrt(T), T) + 1
# set starting price and create price series generated by above random daily returns
price_list = [S]
for x in daily_returns:
price_list.append(price_list[-1]*x)
# Generate Plots - price series and histogram of daily returns
plt.plot(price_list, color='gray')
plt.hist(daily_returns-1, 100) # Note that we run the line plot and histogram separately, not simultaneously.
average.append(np.mean(price_list))
plt.plot(average, color='red')
plt.show()
The issue I am having is the average line I've been able to come up (probably incorrectly) seems to stop halfway through the plot. I am sure this is an easy fix but it is going to drive me crazy!
Thanks!