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 :

newplot

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

Capture d_écran 2017-11-18 à 21.20.23

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.


Alex Mouturat

 

One thought on “Monte Carlo Simulations of an asset with Black & Scholes dynamic

  1. Pingback: Barrier option pricing with Monte Carlo | My financial markets

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s