# Monte Carlo Simulations of an asset with Black & Scholes dynamic

## Introduction

This first and basic article will show how to simulate a security following the Black & Scholes dynamic :

$\frac{dS_t}{S_t} = \mu dt + \sigma dB_t$

When solving this stochastic differential equation with Ito, you finally obtain:

$S_T = S_0 e^{(\mu - \frac{\sigma ^2}{2})T + \sigma B_T}$

The browian motion $B_T$ can be written as $\sqrt{T}X$ where $X \sim \mathcal{N}(0,1)$. This will be usefull for our simulation!

Let’s simulate an asset over a year with $\mu = 0.05$, $\sigma = 0.25$ and $S_0 = 35$. We discretize time daily so that we have $dt = \frac{1}{365}$.

The little program will use numpy package for its efficient data structure, math package for mathematical functions and plotly package for plotting. Let’s go into the code:

import numpy as np
import math
import plotly as plt
import plotly.graph_objs as go

def asset_price(S,drift,volatility,dt,X):
return S*math.exp((drift-(volatility**2)/2)*dt + volatility*math.sqrt(dt)*X)

S_0 = 35
drift = 0.05
volatility = 0.25
dt = 1/365
N_days = 365

path_matrix = np.zeros((N_days+1,1))
path_matrix[0,0] = S_0 #Initial value

random_variable = np.random.randn(N_days) #365 independant values generated from standard normal random variables.

for i in range(N_days):
path_matrix[i+1,0] = asset_price(path_matrix[i,0],drift,volatility,dt,random_variable[i])

#Generate plot :
asset = go.Scatter(y=path_matrix[:,0],name="Simulated asset",opacity = 0.8)
layout = go.Layout( title='Simulated asset path')

#Plot :
plt.offline.plot({"data":[asset],"layout":layout})

Final result is a plot of a simulated path :

When generating 100 random walks for this asset by adding a few lines of code, we obtain something such as this :

## Conclusion

This article shows how to simulate one random path for an asset following a straightforward dynamic but the method can easily be extended to N assets. Here $\mu$ and $\sigma$ are constant but stochastic process can be inserted. Following articles will deal with a Monte Carlo simulation of N correlated assets used to price exotic options for example.