okay perfect in this lesson we'll continue to explore how Monte Carlo simulations can
be applied in practice in particular we will see how we can run a simulation when trying to
predict the future stock price of a company there is a group of libraries and modules that can be
imported when carrying out this task but the good news is you have already used all of them besides
the classical numpy and pandas we will need norm from Sify and some specific matplotlib features
once again the company we will use for our analysis will be P&G the timeframe under
consideration reflects the past 10 years starting from January the 1st 2007 we want to forecast P
and G's future stock price in this exercise so the first thing we'll do is estimate its historical
log returns there is a second way to obtain simple or logarithmic returns and we will discuss it in
more detail in the notebook document attached to this video the method will apply here is
called percent change and you must write percent underscore change open and close parentheses to
obtain the simple returns from a provided data set we can create the formula for log returns by
using num pies log and then type 1 plus the simple returns extracted from our data and
here's a table with P G's log returns awesome
in the first graph we can see P and G's price which has been gradually growing during the
past decade in the second one we plot the log returns not the price of P&G the picture tells
us the returns are normally distributed and have a stable mean great now let's explore
their mean and variance as we will need them for the calculation of the Brownian motion we talked
about in our previous lecture remember we already know how to calculate mean and variance don't we
after a few lines of code we obtained these numbers so what are we going to do with them
first I'll compute the drift component we studied in our previous lecture it
is the best approximation of future rates of return of the stock the formula to use here
will be U which equals the average log return minus half its variance
all right we obtained a tiny number and that need not scare you because we'll do this entire
exercise without annualizing our indicators why because we will try to predict pn G's
daily stock price good next we will create a variable called st dev and we will assign
to it the standard deviation of log returns we said the Brownian motion comprises the Sun of
the drift and standard deviation of adjusted by e to the power of r so we will use this
block in the second part of the expression okay we've set up the first Brownian motion
element in our simulation in the next lesson we will create the second component and we'll
show you how this would allow us to run a simulation about a firm's future stock price