Member-only story
In a recent post I discussed performing a Monte Carlo random walk in Excel, and that post can be found here:- https://medium.com/@tracyrenee61/create-a-random-walk-in-excel-af64d6f7d6d6
In this post I intend to carry out a Monte Carlo random walk in Python, which, in my opinion, might be easier to undertake because there are functions already created and in place for this purpose.
I have created the script using Google Colab because it is a free resource within the Google family of applications.
Once I created the program, I imported the libraries that I would need to use, being:-
- Numpy to perform numerical calculations
- Matplotlib to visualise the data
I initialised the parameters of:-
- 20 steps
- 1 simulation
I defined the function, random_walk, that will be used to perform the random walk:-
- I used numpy to initialise the steps as being 20 random steps.
- I defined the position as being the cumulative sum of the array elements of steps.
I then defined the variable, one_walk, which was the function, random_walk, being executed:-