-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimpleMC4.cpp
38 lines (31 loc) · 874 Bytes
/
SimpleMC4.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
36
37
38
#include "stdafx.h"
#include "SimpleMC4.h"
#include "Random1.h"
#include <cmath>
#if !defined(_MSC_VER)
using namespace std;
#endif
double SimpleMonteCarlo3a(const VanillaOption2& 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 thisGuassian = GetOneGaussianByBoxMuller();
thisSpot = movedSpot*exp( rootVariance*thisGuassian );
double thisPayoff = TheOption.OptionPayOff(thisSpot);
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *= exp(-r*Expiry);
return mean;
}