Monte-carlo Simulation Notes-1

Posted on April 19, 2015

\(d\)-dimensional Normal random variables

\[\phi_{\mu, \Sigma} = \frac{1}{(2\pi)^{d/2}\vert \Sigma \vert^{1/2}} \exp{\left(-\frac{1}{2}(x-\mu)^{T}\Sigma^{-1}(x-\mu)\right)}.\]

Cholesky factorization

\[\begin{align*} X_1 &= \mu_1 + \sigma_1 Z_1, \\ X_2 &= \mu_2 + \rho \sigma_2 Z_1 + \sqrt{1-\rho^2}\sigma_2 Z_2 \\ \end{align*}\]

\[\begin{align*} A_{ij} & = \frac{1}{A_jj}\left(\Sigma_{ij} - \sum_{k=1}^{j-1} A_{ik}A_{jk}\right), j<i \\ A_{ii} &= \sqrt{\Sigma_{ii} - \sum_{k=1}^{j-1} A^2_{ik}} \end{align*}\]


Brownian motion

Algorithm for simulation of standard Wiener process

\[ X(t_{i+1}) = X(t_i) + \mu(t_{i+1}-t_{i}) + \sigma \sqrt{t_{i+1} - t_{i}} Z_{i+1}, \quad i = 0, 1, \cdots, n-1.\]

\[X(t_{i+1}) = X(t_i) + \int_{t_i}^{t_{i+1}} \mu(s) \, \text ds + \sqrt{\int_{t_i}^{t_{i+1}} \sigma^2(u) \text du}\cdot Z_{i+1}, \quad i = 0, \cdots, n-1.\]

\[ X(t_{i+1}) = X(t_i) + \mu(t_i)(t_{i+1}-t_i) + \sigma(t_i) \sqrt{t_{i+1} - t_{i}} Z_{i+1}, i = 0, \cdots, n-1\]


Geometric Brownian motion

\[ S(t) = S(u) \exp((\mu - \frac{1}{2} \sigma^2)\cdot (t-u) + \sigma(W(t) - W(u)).\]

\[ S(t_{i+1}) = S(t_i) \exp((\mu - \frac{1}{2} \sigma^2) \cdot (t_{i+1} - t_{i}) + \sigma (\sqrt{t_{i+1} - t_{i}}) \cdot Z_i)\]

Code in R

{% highlight R %}

sigma = 0.3 mu = 0.06 N = 1000 flag = 0 lambda = c(0.01, 0.05, 0.1, 0.5, 1) xs = c(5) Xs = matrix(5, nrow = 5, ncol = N) zs = rnorm(N) for (i in 2:N) { xs[i] = xs[i-1] + (mu - 0.5sigmasigma)/N + sigmasqrt(1/N)zs[i] } for (j in 1:5) { for (i in 2:N) { n = rpois(1, lambda[j]1/N) M = 0 if(n != 0) { flag <<- flag+1 ys = 0.1rnorm(n, mean = 0, sd = 1)+1 M = 0 for (k in 1:n) M = M + log(ys[k]) } Xs[j, i] = Xs[j,i-1] + (mu-0.5sigmasigma)/N + sigmasqrt(1/N)zs[i] + M } } yM = max(max(xs), max(Xs)) ym = min(min(xs), min(Xs)) plot(xs, cex = 0.05, type=“l”, ylim=c(ym, yM)) lines(1:N, Xs[1,1:N], col=“red”) lines(1:N, Xs[2,1:N], col=“blue”) lines(1:N, Xs[3,1:N], col=“green”) lines(1:N, Xs[4,1:N], col=“violet”) lines(1:N, Xs[5,1:N], col=“orange”)

{% endhighlight %}