next up previous contents index
Next: Defining payoffs. Up: A general approach to Previous: A general approach to   Contents   Index

Simulating prices of underlying.

Let us first look at how prices are simulated. We look at two cases. One where one only need the terminal price of the underlying at a given time. This is used for options that only depend on this, such as basic call and put options.



// 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;
    };
};



next up previous contents index
Next: Defining payoffs. Up: A general approach to Previous: A general approach to   Contents   Index
Bernt Arne Odegaard
1999-09-09