Aug 29, 2014 at 4:01pm UTC
When & is used in this way SimpleMonetCarlo(const PayOff& thePayOff) what does it mean.
Also like this Numeric CND(const Numeric& d)
Aug 29, 2014 at 4:14pm UTC
Last edited on Aug 29, 2014 at 7:40pm UTC
Aug 29, 2014 at 4:31pm UTC
Contrary to what AbstractionAnon just said, the apersand & is used in the context to make thePayOff a reference to objects of type PayOff const
and similarly for d being a reference to objects of type Numeric const
To avoid confusion with pointers, I generally don't tend to use & to take address of - I use std::addressof
Last edited on Aug 29, 2014 at 4:33pm UTC
Aug 29, 2014 at 5:32pm UTC
@ LB (9988), thank you very muck for your help. I appreciate
Aug 29, 2014 at 6:31pm UTC
@LB need your help once again. I came across this below in my C++ pattern and design with Joshi what does it mean:
double thisSpot;
double thisPayoff = thePayOff(thisSpot);
Aug 29, 2014 at 6:51pm UTC
There is not enough context for me to know what that means.
Aug 29, 2014 at 6:57pm UTC
Here is the complete program:
#include "JoshiOption.hpp" //JoshiOption.cpp
#include "Fns.hpp"
#include <minmax.h>
#include <cmath>
using namespace std;
PayOff::PayOff(double Strike_, OptionType TheOptionsType_)
:
Strike(Strike_), TheOptionsType(TheOptionsType_)
{
}
double PayOff::operator ()(double spot) const
{
switch (TheOptionsType)
{
case call :
return max(spot-Strike,0.0);
case put:
return max(Strike-spot,0.0);
default:
throw("unknown option type found.");
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 thisGaussian = GetOneGaussianByBoxMuller();
thisSpot = movedSpot*exp(rootVariance*thisGaussian);
double thisPayoff = thePayOff(thisSpot);
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *=exp(-r*Expiry);
return mean;
}
Aug 29, 2014 at 7:02pm UTC
thePayOff is a PayOff instance, and the PayOff class has a definition for double operator ()(double )
meaning that you can treat thePayOff as if it were a function that took a double and returned a double .
Last edited on Aug 29, 2014 at 7:02pm UTC