Next: Improving the estimates, control Up: A general approach to Previous: Defining payoffs.   Contents   Index

# Pricing

We can now use the two previously defined routines to implement rather general simulation routines.

```// file simulate_general.cc
// author: Bernt A Oedegaard
// estimation of an option price by simulation.
// This is a general routine, the payoff is defined by the user as a function
//       payoff(vector<double>&) or
//       payoff(vector<double>&,X),
// depending on whether there are other arguments beside the prices of the underlying needed.

#include <math.h>
#include <vector.h>
#include <algo.h>
#include "fin_algoritms.h"

double derivative_price_european_simulated ( double S,  double X,  double r,  double sigma, double time,
double payoff(double& price, double& X),
int no_sims) {
double sum_payoffs=0;
for (int n=0; n<no_sims; n++) {
double S_T = simulate_terminal_price(S,r,sigma,time);
sum_payoffs += payoff(S_T,X);
};
return  exp(-r*time) * (sum_payoffs/no_sims);
};

double derivative_price_european_simulated ( double S, double r, double sigma, double time,
double payoff(vector<double>& prices),
int no_steps, int no_sims) {
double sum_payoffs=0;
vector <double> prices(no_steps);
for (int n=0; n<no_sims; n++) {
simulate_price_sequence(S,r,sigma,time,no_steps,prices);
sum_payoffs += payoff(prices);
};
prices.clear();
return  exp(-r*time) * (sum_payoffs/no_sims);
};

double derivative_price_european_simulated ( double S, double X, double r, double sigma, double time,
double payoff(vector<double>& prices, double& X),
int no_steps, int no_sims) {
double sum_payoffs=0;
vector <double> prices(no_steps);
for (int n=0; n<no_sims; n++) {
simulate_price_sequence(S,r,sigma,time,no_steps,prices);
sum_payoffs += payoff(prices,X);
};
prices.clear();
return  exp(-r*time) * (sum_payoffs/no_sims);
};
```

Next: Improving the estimates, control Up: A general approach to Previous: Defining payoffs.   Contents   Index
Bernt Arne Odegaard
1999-09-09