// file simulate_underlying_terminal.cc #include <math.h> #include "random.h" double simulate_terminal_price(double S, // current value of underlying double r, // interest rate double sigma, // volatitily double time) // time to final date { double R = (r - 0.5 * pow(sigma,2) )*time; double SD = sigma * sqrt(time); return S * exp(R + SD * random_normal()); };

More generally we need to simulate price observations of the underlying at various times during the life of the derivative. This is what is implemented next.

// file: simulate_underlying_sequence.cc #include <math.h> #include <vector.h> #include "random.h" void simulate_price_sequence(double S, // current value of underlying double r, // interest rate double sigma, // volatitily double time, // time to final date int no_steps, // number of steps vector<double>& prices ) { if (prices.size() < no_steps) { prices.clear(); prices = vector<double>(no_steps); }; double delta_t = time/no_steps; double R = (r-0.5*sigma*sigma)*delta_t; double SD = sigma * sqrt(delta_t); double S_t = S; // initialize at current price for (int i=0; i<no_steps; ++i) { S_t = S_t * exp(R + SD * random_normal()); prices[i]=S_t; }; };