OK, so in this lecture, you're going to look at a simple example of how to simulate stock prices,
assuming that the log returns come from a normal distribution.
Now, this might seem at first to be a strange exercise, but it should get you thinking.
We'll see how totally unpredictable randomness can lead to something that looks very much like a stock
race time series.
In fact, this exact method can be used for doing Montecarlo simulations and evaluating the Black-Scholes
formula.
Furthermore, it is also useful for when we want to analyze certain rules of thumb for Arima.
This may not make too much sense right now, but you'll see how this kind of approach can help to validate
some of the rules that we use for a rhema model selection.
OK, so let's start by importing nonpaying matplotlib.
The next step is to set a few constants will be using, such as the number of time steps, the initial
price and the drift term.
The next step is to run our simulation, so we'll start by taking the log of the price and setting it
to last P last P is a variable will continue to update throughout the loop, since the current price
will always depend on the last price.
The next step is to create two arrays, to store log returns and our prices, and of course, these
should both have length T.
The next step is to enter a loop that goes 40 iterations inside the loop.
We'll start by sampling a random log return from a zero mean normal distribution with standard deviation
zero point zero one.
The next step is to compute our new log price.
This is equal to the old log price, plus the drifter, plus the random noise.
The next step is to store the log return and the new price note that we don't actually make use of the
log returns, but you may find them to be useful in later code for the price.
Note that we have to take the exponential since we want to plot the price and not the log price.
The final step in this loop is to assign P to last P so that last P has the correct value in the next
iteration.
OK, and so in the next block, we are going to plot our simulated time series.
So as you can see, this certainly looks like a plausible stock price evolution in the coming lectures,
you learn about the why behind what we just did.
And hopefully this will give you some insight behind this exercise.