Created
April 13, 2020 22:50
-
-
Save IlievskiV/39686652cacf72eebbd486e86e40c811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
np.random.seed(1234) | |
def random_walk(N): | |
""" | |
Simulates a discrete random walk | |
:param int N : the number of steps to take | |
""" | |
# event space: set of possible increments | |
increments = np.array([1, -1]) | |
# the probability to generate 1 | |
p=0.5 | |
# the epsilon values | |
random_increments = np.random.choice(increments, N, p) | |
# calculate the random walk | |
random_walk = np.cumsum(random_increments) | |
# return the entire walk and the increments | |
return random_walk, random_increments | |
# generate a random walk | |
N = 500 | |
X, epsilon = random_walk(N) | |
# normalize the random walk using the Central Limit Theorem | |
X = X * np.sqrt(1./N) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment