A beautiful rendering of the Bugatti Veyron with 2 million polygons worth of information using ray-tracing! The science behind ray-tracing is to use the Monte-carlo methods to simulate the random paths of light through any given pixel and create a 3D-image.

Simulations are central to finance and risk management. They allow us to price complex financial instruments e.g. European style options for which no analytic pricing formula is available. They allow risk managers to simulate a portfolio’s profit and loss performance for a specified time horizon. Repeated trials within the simulation produce a frequency distribution for the changes in the portfolio value. The cutoff point beyond which there is very low probability of greater losses is an estimate of VAR.

Steps in the Monte Carlo Process

To understand the technique of Monte Carlo, let us present the process as a series of steps. To illustrate the steps, I will take the case of using Monte Carlo simulation to value a European call option on a stock.

1. Specify the quantities of interest

Specify the quantities of interest, for example, option value in terms of the underlying variables. The underlying variable, for example could be the stock price. Specify the starting values of an underlying variable.

I use \(C_{iT}\) to represent the value of the option at maturity \(T\). The subscript \(i\) in \(C_{iT}\) is a value resulting from the \(i\)th simulation trial.

2. Specify a time grid

Take the time horizon in terms of calendar time and split it into a number of subperiods, say \(K\). The calendar time divided by the number of subperiods \(K\), is the time increment, \(\Delta{t}\).

We proceed with the simplifying assumption of \(K=1\).

3. Specify the distribution of the underlying random variables

The stock price is underlying random variable, so we need a model for the stock price movement. The model of stock price evolution we will be using is Geometric Brownian Motion (GBM). It is given by the following stochastic differential equation:

\(\begin{equation}\displaystyle{\frac{dS}{S}=\mu{dt}+\sigma{dW}}\tag{1}\end{equation}\)

where \(S\) is the stock price, \(\mu\) is the drift – the average rate of growth of the stock, \(\sigma\) is the volatility of the stock and \(W\) is a brownian motion process.

You can think of \(dW\) as a normally distributed random variable with zero mean and variance \(dt\). In terms of the standard normal random variable, equation \((1)\) can be written as:

\(\begin{equation}\displaystyle{dS=\mu{S}{dt}+\sigma{S}{dz}\sqrt{dt}}\tag{2}\end{equation}\)

We can make use of Ito’s Lemma to solve this SDE. Suppose that the value of a variable \(x\) follows the process:

\(dx = a(x,t)dt + b(x,t)dW\)

where \(dW\) is the standard brownian motion process and \(a\) and \(b\) are functions of \(x\) and \(t\). The variable \(x\) has a drift rate of \(a\) and a variance of \(b^2\). Ito’s lemma shows that a function \(G\) of \(x\) and \(t\) follows the process,

\(\begin{equation}\displaystyle{dG=\left(\frac{\partial{G}}{\partial{x}}a+\frac{\partial{G}}{\partial{t}}+\frac{1}{2}\frac{\partial^2{G}}{\partial{x^2}}b^2\right)dt+\frac{\partial{G}}{\partial{x}}{b}{dW}\tag{Ito’s Lemma}}\end{equation}\)

We are interested to know how the log of the stock price process evolves. To do a log transformation, let the function \(G(S)=\ln{S}\). Applying Ito’s lemma we have,

\(\begin{align}
d(\ln S) &= \left( \frac{\partial(\ln S)}{\partial{S}}{\mu}{S} + \frac{\partial(\ln S)}{\partial{t}} +\frac{1}{2}\frac{\partial^2(\ln S)}{\partial{S^2}}{\sigma}^2{S^2}\right)dt + \frac{\partial (\ln S)}{\partial S}\sigma{S}{dW} \\
&= \left(\mu – \frac{\sigma^2}{2}\right)dt+\sigma{dW} \tag{3}
\end{align}\)

Integrating the above equation\((3)\) from time \(0\) to \(t\), we have,

\(\begin{align}
\ln{\left(\frac{S_{t}}{S_{0}}\right)} &=\left(\mu – \frac{\sigma^2}{2}\right)t+\sigma{W_{t}} \\
&=\left(\mu – \frac{\sigma^2}{2}\right)t+\sigma{z_{t}}\sqrt{t} \tag{4} \\
S_{t} &= S_{0}e^{\left(\mu – \frac{\sigma^2}{2}\right)t+\sigma{z_{t}}\sqrt{t}}
\end{align}\)

where \(z_{t}\) is the standard brownian motion process. We now have an expression for the underlying stock price.

4. Draw random samples from the probability distribution

Using a python program or an excel spreadsheet function, we draw \(K\) random values of the standard normal random variable \(z\). For example, we generate \(z_{1},z_{2},z_{3},\ldots,z_{K}\).

5. Calculate the underlying variables

Calculate the underlying variables using the random observations generated in step 4. Using the above model of stock price dynamics, the result is \(K\) stock prices.

6. Compute the quantities of interest

In our example, the first calculation is the value of a European Call at maturity \(C_{iT}\). The value of the call option contract with strike \(X\) at maturity is,

\(C_{T} = max(S_{T}-X,0)\)

7. Conduct several trials of the simulation

Iteratively go back to step 4 until a specified number of trials, \(I\) is completed. Finally, the principle of risk-neutral valuation states that the value of an option today is its expected(average) future payoff in a risk-neutral world discounted at the risk-free rate.

\(C_{0} = E[C_{T}]e^{-\mu{T}}\)

So, we compute the average value of the payoffs and discount it as the risk-free interest rate to get the Monte Carlo estimate of the European Call option.

Putting all of the above together, here’s the complete Monte Carlo implementation. I won’t be utilizing any object-oriented or generic programming techniques. At this stage, the goal is to generate a understanding of the basic python Monte Carlo implementation.