The Monte Carlo method is used to sample numerical integration using random numbers and to study the mean value of a large number of samples. The Monte Carlo method is especially useful when there is no closed form solution available.
In this section, we'll look at the simplest case, where we have path-dependent European options. We are going to sample numerical integration using a random drifting parameter. This will lead to various average values for the stochastic process, which makes up the movement of the underlying asset. We'll do this using 1,000 and 1,000,000 samples respectively and compare the results. Let's dig into the following code:
/// Monte Carlo implementation /// Convert the nr of days to years let days_to_years d = (float d) / 365.25 /// Asset price at maturity for sample rnd // s: stock price // t: time to expiration in years // r: risk free interest rate // v: volatility // rnd: sample let price_for_sample s t r v rnd = s*exp((r-v*v/2.0)*t...