2023-03-15

Introduction

Monte Carlo simulations are named after the famed Monte Carlo Casino in Monaco. The name was coined by mathematician Stanislaw Ulam after He realized that the process he was using to solve random sampling math problems was similar to the random nature of gambling games at the Monte Carlo Casino.

Monte Carlo simulation is a statistical technique that can be used to model complex systems by generating random samples. In the context of the stock market, Monte Carlo simulations can be used to model the potential outcomes of different investments or portfolios based on a range of possible scenarios.

In R, Monte Carlo simulations can be easily implemented using the rnorm() function, which generates random samples from a normal distribution.

How it Works

At the heart of Monte Carlo simulations is the concept of random sampling. The basic steps for a Monte Carlo simulation are as follows:

  1. Define the problem and the variables of interest, including their probability distributions or other relevant statistical properties.
  2. Generate a large number of random samples for each variable according to its probability distribution.
  3. Simulate the system using the generated samples and any relevant mathematical models or algorithms.
  4. Repeat steps 2 and 3 many times to generate a large number of simulated scenarios.
  5. Analyze the results of the simulation to estimate the probability distributions or other relevant statistical properties of the variables of interest.

Example

The expected value and variance of a normal distribution with mean \(\mu = 10\) and standard deviation \(\sigma = 2\) can be estimated using a Monte Carlo simulation by generating \(N\) random samples from the normal distribution and computing the sample mean \(\bar{x}\) and sample variance \(s^2\) like so:

\[\bar{x} = \frac{1}{N}\sum_{i=1}^{N} x_i\]

\[s^2 = \frac{1}{N-1}\sum_{i=1}^{N}(x_i-\bar{x})^2\]

Resulting in:

\[\mathbb{E}(X) \approx \bar{x} , \text{Var}(X) \approx s^2\]

Application with PDFs

Suppose we have a probability density function (PDF) \(f(x)\), and we want to estimate the probability that a random variable \(X\) takes on a value in some interval \([a,b]\). We can do this using Monte Carlo simulations by generating a large number of random samples from the PDF \(f(x)\), and counting the number of samples that fall in the interval \([a,b]\). The estimated probability is then given by:

\[\hat{P}(a \leq X \leq b) \approx \frac{\text{number of samples in [a,b]}}{\text{total number of samples}}\] This can be used to model the pricing financial derivatives such as Call options. Simulated stock prices from the Monte Carlo simulation can be used to calculate the payoff of the call option at the expiration date.

R Functions

R has the following functions that can be used to implement Monte Carlo simulations:
- rnorm(): generates random samples from a normal distribution.
- runif(): generates random samples from a uniform distribution.
- rbeta(): generates random samples from a beta distributions.
- rgamma(): generates random samples from a gamma distribution.
- rexp(): generates random samples from an exponential distribution.
- rlognormal(): generates random samples from a lognormal distribution.

The following code is an example of how to implement a Monte Carlo simulation in R using rnorm():

n <- 1000, t <- 10, s0 <- 100, mu <- 0.05, sigma <- 0.2

set.seed(123)  
epsilons <- matrix(rnorm(n*t, mean = 0, sd = sigma), ncol = t)

Surface Plot of Monte Carlo Simulations

Line Plot of Monte Carlo Simulations

Histogram of Monte Carlo Simulations