Geometric Brownian Motion
As we all know, the SDE(Stochastic Differential Equation) is also an important tool in finance, like the famous BlackScholes Equation is also derived by the SDE, and its root is the equation we’ll talk about today.
The derivation process
The GBM could be like this form. $$ \mathrm{d} S_t = \mu S_t \mathrm{d}t + \sigma S_t \mathrm{d}W_t $$
In this equation, $S_t$ is the random viable in $t$ point, $\mu$ is the average increase rate in unit time, and the $\sigma$ is the volatility rate of random viable, and the $W_t$ is the basic Brownian Motion, which has $\mu$ with 1 and $\sigma$ with $t$.
We could solve this equation with the method of solving stochastic differential equations. so we could have the general answer of this SDE like this. $$ S_t = S_0 + \int_0^t \mu S_i \mathrm{d}i + \int_0^t \sigma S_i \mathrm{d}W_i $$
According to the Ito’s lemma, we could solve this equation with this form. $$ \frac{\mathrm{d}S_t}{S_t} = \mu \mathrm{d}t + \sigma \mathrm{d}W_t $$
Then we integrate the equation on both sides. $$ \ln S_t  \ln S_0 = (\mu  \frac{1}{2}\sigma^2)t = \sigma W_t $$
We could time the $e^x$ on both side then the formula would be like this. $$ S_t = S_0 \exp [(\mu  \frac{1}{2}\sigma^2)t + \sigma W_t] $$
Now we have solved this SDE and the GBM could be stimulated, and the Probability Density Function would be like this. $$ p(S) = \frac{1}{S \sigma \sqrt{2\pi t}}\exp [\frac{[\ln(\frac{S}{S_0})(\mu\frac{\sigma^2}{2})t]^2}{2\sigma^2t}] $$
So what we need to do is like this.
Program
If we know this process well, we would get the program easily, first of all we need to get $\mu$ and $\sigma$.
We could get these number by the code below.


After running this code we could get these two parameters and the next thing we should do is construct the GBM and use Monte Carlo to give the much path.
We could achieve this goal by this code.


Then we could get the histogram like this.
And the stimulated path would there and we could get all path on the figure.
I have stimulated this GBM for 10000 times and actually it is up to you.
Then we could use mean method to get the prediction or any other method.
At last, I think this method is a classic way which combines the physic and finance, if the physical theory would be used in financial market analysis, it could be so usefull.