There's more...

There are some statistical methods that make working with Monte Carlo simulations easier (higher accuracy, faster computations). One of them is a variance reduction method called antithetic variates. In this approach, we try to reduce the variance of the estimator by introducing negative dependence between pairs of random draws. This translates into the following: when creating sample paths, for each , we also take the antithetic values .

The advantages of this approach are:

  • Reduction (by half) of the number of Standard Normal samples to be drawn in order to generate N paths
  • Reduction of the sample path variance, while at the same time, improving the accuracy

We implemented this approach in the simulate_gbm function. Additionally, we made the function shorter by putting the majority of the calculations into one line.

Before we implemented these changes, we timed the old version of the function:

%timeit gbm_simulations = simulate_gbm(S_0, mu, sigma, N_SIM, T, N)
# 188 µs ± 3.75 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

The new function is defined as follows:

def simulate_gbm(s_0, mu, sigma, n_sims, T, N, antithetic_var=False):

dt = T/N

if antithetic_var:
dW_ant = np.random.normal(scale = np.sqrt(dt),
size=(int(n_sims/2), N + 1))
dW = np.concatenate((dW_ant, -dW_ant), axis=0)
else:
dW = np.random.normal(scale = np.sqrt(dt),
size=(n_sims, N + 1))

S_t = s_0 * np.exp(np.cumsum((mu - 0.5 * sigma ** 2) * dt + sigma * dW,
axis=1))
S_t[:, 0] = s_0

return S_t

First, we run the simulations without antithetic variables:

%timeit gbm_simulations = simulate_gbm(S_0, mu, sigma, N_SIM, T, N)
# 106 µs ± 9.68 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

Then, we run the simulations with them:

%timeit gbm_simulations = simulate_gbm(S_0, mu, sigma, N_SIM, T, N, antithetic_var=True)
# 71.5 µs ± 1.89 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

We succeeded in making the function faster. If you are interested in pure performance, these simulations can be further expedited using Numba, Cython, or multiprocessing.

Other possible variance reduction techniques include:

  • Control variates
  • Common random numbers
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.102.79