-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimpleMC6.cpp
35 lines (30 loc) · 913 Bytes
/
SimpleMC6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "SimpleMC6.h"
#include "Random1.h"
#include <cmath>
#if !defined(_MSC_VER)
using namespace std;
#endif
double SimpleMonteCarlo4(const VanillaOption& TheOption,
double Spot,
const Parameters& Vol,
const Parameters& r,
unsigned long NumberOfPaths)
{
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 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.Integral(0, Expiry));
return mean;
}