void SimpleMonteCarlo(
	const VanillaOption& theOption,
	double Spot,
	Parameters Vol,
	Parameters r,
	unsigned long NumberOfPaths,
	StatisticsMC& gatherer,
	RandomBase& generator)
{
	double Expiry = theOption.GetExpiry();
	double variance = Vol.IntegralSquare(0, Expiry);
	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5 * variance;

	double movedSpot = Spot * exp(r.Integral(0, Expiry) + itoCorrection);
	double thisSpot;

	double discounting = exp(-r.Integral(0, Expiry));

	std::vector<double> VariateVector(1);

	for (unsigned long i = 0; i < NumberOfPaths; i++)
	{
		generator.GetGaussian(VariateVector);
		thisSpot = movedSpot * exp(rootVariance * VariateVector[0]);
		gatherer.DumpOneResult(discounting * theOption.OptionPayOff(thisSpot));
	}
}
Example #2
0
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;
}
Example #3
0
void SimpleMonteCarloForLRDelta(const VanillaOption& TheOption, 
						 double Spot, 
						 const Parameters& Vol, 
						 const Parameters& r, 
                         unsigned long NumberOfPaths,
						 StatisticsMC& gatherer,
                         RandomBase& generator)
{
    generator.ResetDimensionality(1);

    double Expiry = TheOption.GetExpiry();
	double variance = Vol.IntegralSquare(0,Expiry); // sigma^2T
	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5*variance;
	double movedSpot = Spot*exp(r.Integral(0,Expiry) +itoCorrection);
	double averageR = r.Integral(0,Expiry);
	double subtractNumerator = averageR + itoCorrection; 


	double thisSpot;
    double discounting = exp(-r.Integral(0,Expiry));

    MJArray VariateArray(1);

	for (unsigned long i=0; i < NumberOfPaths; i++)
	{
        generator.GetGaussians(VariateArray);
		thisSpot = movedSpot*exp( rootVariance*VariateArray[0]);
		double thisPayOff = (TheOption.OptionPayOff(thisSpot))*(log(thisSpot/Spot) - subtractNumerator)/(Spot*variance);
        gatherer.DumpOneResult(thisPayOff*discounting); // payoff*Psi/Phi see (p. 195 of JoshiConcepts)
	}

    return;
}
Example #4
0
void SimpleMonteCarlo6(const VanillaOption& TheOption, 
						 double Spot, 
						 const Parameters& Vol, 
						 const Parameters& r, 
                         unsigned long NumberOfPaths,
						 StatisticsMC& gatherer,
                         RandomBase& generator)
{
    generator.ResetDimensionality(1);

    double Expiry = TheOption.GetExpiry();
	double variance = Vol.IntegralSquare(0,Expiry);
	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5*variance;
	double movedSpot = Spot*exp(r.Integral(0,Expiry) +itoCorrection);

	double thisSpot;
    double discounting = exp(-r.Integral(0,Expiry));

    MJArray VariateArray(1);

	for (unsigned long i=0; i < NumberOfPaths; i++)
	{
        generator.GetGaussians(VariateArray);
		thisSpot = movedSpot*exp( rootVariance*VariateArray[0]);
		double thisPayOff = TheOption.OptionPayOff(thisSpot);
        gatherer.DumpOneResult(thisPayOff*discounting);
	}

    return;
}
Example #5
0
void SimpleMonteCarlo_tol(const VanillaOption& TheOption,
						 double Spot,
						 const Parameters& Vol,
						 const Parameters& r,
                         double tol,
                         double maxLoops,
						 StatisticsMC& gatherer,
                         RandomBase& generator,
                         double target)
{
    generator.ResetDimensionality(1);

    double Expiry = TheOption.GetExpiry();
	double variance = Vol.IntegralSquare(0,Expiry);
	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5*variance;
	double movedSpot = Spot*exp(r.Integral(0,Expiry) +itoCorrection);

	double thisSpot;
    double discounting = exp(-r.Integral(0,Expiry));

    MJArray VariateArray(1);

    double error = 100.0;
    double loops = 0.0;
	double running_sum = 0.0;
    double prev_res = 0.0;

	while( (abs(error) > tol) && (loops < maxLoops))
	{
        generator.GetGaussians(VariateArray);
		thisSpot = movedSpot*exp( rootVariance*VariateArray[0]);
		double thisPayOff = TheOption.OptionPayOff(thisSpot);
        gatherer.DumpOneResult(thisPayOff*discounting);
        if(loops > 0){
        	prev_res = running_sum/loops;
        	running_sum += thisPayOff*discounting;
        	loops++;
        	error = abs(target - running_sum/loops);
        }
        else{
        	running_sum += thisPayOff*discounting;
        	loops++;
        }



	}

    return;
}
Example #6
0
// Project 1 - Euler Stepping
void SimpleMonteCarlo7(const VanillaOption& TheOption, 
						 double Spot, 
						 const Parameters& Vol, 
						 const Parameters& r, 
                         unsigned long NumberOfPaths,
						 unsigned long NumberOfSteps,
						 StatisticsMC& gatherer,
                         RandomBase& generator)
{
    //generator.ResetDimensionality(1);
	generator.ResetDimensionality(NumberOfSteps);
    double Expiry = TheOption.GetExpiry();
	double deltaT = Expiry/NumberOfSteps;
	double variance = Vol.IntegralSquare(0,Expiry); // \sigma^2T
	double rootVariance = sqrt(variance/ NumberOfSteps); // \sigma \sqrt{Delta T}
	double rDeltaT= (r.Integral(0,Expiry)/Expiry)*deltaT; // this assumes r is constant. 
	//double itoCorrection = -0.5*variance; // -\sigma^2 T/2
	//double movedSpot = Spot*exp(r.Integral(0,Expiry) +itoCorrection);

	double thisSpot= Spot;
    double discounting = exp(-r.Integral(0,Expiry));

    MJArray VariateArray(NumberOfSteps);
	double nextSpot=0.0;

	for (unsigned long i=0; i < NumberOfPaths; i++)
	{	// I guess this method fills the MJArray with Gaussians
        generator.GetGaussians(VariateArray);
		thisSpot=Spot; //reset starting point for each path.
		for (unsigned long j= 0; j < NumberOfSteps; j++) 
		{
			nextSpot = thisSpot*(1 + rDeltaT + rootVariance*(VariateArray[j]));
			thisSpot=nextSpot;
		}
		double thisPayOff = TheOption.OptionPayOff(nextSpot);
        gatherer.DumpOneResult(thisPayOff*discounting);
	}

    return;
}
Example #7
0
void SimpleStepping_tol(const VanillaOption& TheOption,
		double Spot,
		const Parameters& Vol,
		const Parameters& r,
		double tol,
		double maxLoops,
		int numSteps,
		StatisticsMC& gatherer,
		RandomBase& generator,
		double target)
{

	generator.ResetDimensionality(numSteps);

    double Expiry = TheOption.GetExpiry();
	double variance = Vol.IntegralSquare(0,Expiry)/Expiry;
	double rootVariance = sqrt(variance);
	double rr = r.Integral(0,Expiry)/Expiry;
	double discounting = exp(-r.Integral(0,Expiry));

    MJArray VariateArray(numSteps);

    double error = 100.0;
    double loops = 0.0;
	double running_sum = 0.0;
    double prev_res = 0.0;



	while( (abs(error) > tol) && (loops < maxLoops))
	{
        generator.GetGaussians(VariateArray);
        //Very similar to simple MC but generates thisSpot by stepping
        double thisSpot = GeneratePath(r,
        							Spot,
        							Vol,
        							Expiry,
        							numSteps,
        							generator);

        double thisPayOff = TheOption.OptionPayOff(thisSpot);
        gatherer.DumpOneResult(thisPayOff*discounting);
        if(loops > 0){
        	prev_res = running_sum/loops;
        	running_sum += thisPayOff*discounting;
        	loops++;
        	error = abs(target - running_sum/loops);
        }
        else{
        	running_sum += thisPayOff*discounting;
        	loops++;
        }



	}

    return;



}