-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimpleMC.cpp
37 lines (31 loc) · 827 Bytes
/
SimpleMC.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
#include "StdAfx.h"
#include "SimpleMC.h"
#include "Random1.h"
#include <cmath>
#if !defined(_MSC_VER)
using namespace std;
#endif
double SimpleMonteCarlo2(const PayOff& thePayOff,
double Expiry,
double Spot,
double Vol,
double r,
unsigned long NumberOfPaths)
{
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 = thePayOff(thisSpot);
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *= exp(-r*Expiry);
return mean;
}