double SimpleMonteCarlo3(const VanillaOption& TheOption, double Spot, double Vol, double r, unsigned long NumberOfPaths) { double Expiry = TheOption.GetExpiry(); double variance = Vol*Vol*Expiry; double rootVariance = sqrt(variance); double itoCorrection = -0.5*variance; double movedSpot = Spot*exp(r*Expiry +itoCorrection); double thisSpot; double runningSum=0; for (unsigned long i=0; i < NumberOfPaths; ++i) { double thisGaussian = GetOneGaussianByBoxMuller(); thisSpot = movedSpot * exp( rootVariance * thisGaussian); double thisPayoff = TheOption.OptionPayoff(thisSpot); runningSum += thisPayoff; } double mean = runningSum / NumberOfPaths; mean *= exp(-r * Expiry); return mean; }
double MilsteinScheme1(double start,double strike, double t,int NofIntervals,double r, double d,double sigma,double (*pt2func1)(double,double,double), double (*pt2func2)(double,double),double (*pt2func3)(double) ){ double dt=t/NofIntervals; double x=start; for (int i=0;i<NofIntervals;i++){ double a=pt2func1(x,r,d); double b=pt2func2(x,sigma); double c=pt2func3(sigma); double dw=GetOneGaussianByBoxMuller()*sqrt(dt); x+=a*dt+b*dw+0.5*b*c*(dw*dw-dt); } double thisPayoff = x - strike; thisPayoff = thisPayoff >0 ? thisPayoff : 0; return thisPayoff*exp(-r*t); }