Skip to content

Instantly share code, notes, and snippets.

@IlievskiV
Created April 13, 2020 22:56
Show Gist options
  • Save IlievskiV/569460436df44d1d8b92fc47a016885c to your computer and use it in GitHub Desktop.
Save IlievskiV/569460436df44d1d8b92fc47a016885c to your computer and use it in GitHub Desktop.
num_simulations = 10000 # num of simulation
N = 100000 # number od steps in each simulation
dt = 1./N # the time step
X_norm = [0] * num_simulations # the normalized random variable
# run the simulations
for i in range(num_simulations):
X, _ = random_walk(N)
X_norm[i] = X[N - 1] * np.sqrt(dt)
print('The mean is: {0}'.format(np.mean(X_norm)))
print('The var is: {0}'.format(np.var(X_norm)))
plt.figure(figsize=(15, 7))
plt.grid(True, which='major', linestyle='--', color='black', alpha=0.4)
plt.title('Probability distribution of X_n', fontsize=18)
plt.xlabel('Value for one realization of X_n', fontsize=18)
plt.ylabel('Probability Density', fontsize=22)
plt.hist(X_norm, 100, density=True, color='#0492C2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment